Main Content

Convolutional Encoder

Encode binary data using convolutional encoding scheme

  • Convolutional Encoder block

Libraries:
Communications Toolbox / Error Detection and Correction / Convolutional
Communications Toolbox HDL Support / Error Detection and Correction / Convolutional

Description

The Convolutional Encoder block encodes the input binary message by using the convolutional encoding scheme specified by a trellis structure. For more information, see Convolutional Coding.

This block can accept inputs that vary in length during simulation. For more information about variable-size signals, see the Variable-Size Signal Basics (Simulink) topic.

These icons show the optional block ports enabled.

Convolutional Encoder block with optional initial state and final state ports enabled

Convolutional Encoder block with optional reset and final state ports enabled

Examples

expand all

Apply convolutional encoding and BPSK modulation to a binary signal, pass the modulated signal through an AWGN channel. Compute the symbol error rate (SER) of the signal after applying BPSK demodulation and Viterbi decoding.

Explore model

The doc_conv model generates a binary signal by using a Bernoulli Binary Generator block. The Convolutional Encoder block encodes the signal. The BPSK Modulator Baseband block modulates the signal. The AWGN Channel block adds noise to the signal. To demodulate the BPSK modulated signal with zero phase shift, simply extract the value of the real component of the complex symbol demodulation by using the Complex to Real-Imag (Simulink) block. The Viterbi Decoder block decodes the signal. The Error Rate Calculation block computes the SER.

Run simulation

ans =

    'Filtering the signal through an AWGN channel with the EsN0 set to -1 dB, the computed SER is 0.005608.'


ans =

    'For 53499 transmitted symbols, there were 300 symbols errors.'

This example simulates a punctured coding system that uses rate 1/2 convolutional encoding and Viterbi decoding. The complexity of a Viterbi decoder increases rapidly with the code rate. The puncturing technique enables encoding and decoding of higher rate codes by using standard lower rate coders.

The cm_punct_conv_code model transmits a convolutionally encoded BPSK signal through an AWGN channel, demodulates the received signal, and then performs Viterbi decoding to recover the uncoded signal. To compute the error rate, the model compares the original % signal and the decoded signal.

The model uses the PreloadFcn callback function to set these workspace variables for initialization of block parameters:

puncvec = [1;1;0;1;1;0];
EsN0dB = 2;
traceback = 96; % Viterbi traceback depth

For more information, see Model Callbacks (Simulink).

The blocks in this model perform these operations:

  • Bernoulli Binary Generator — Sets Sample per frames to 3. The block creates a sequence of random bits outputting three samples per frame at each sample time.

  • Convolutional Encoder — Uses the default setting for Trellis structure, selects Puncture code, and sets Puncture vector to the workspace variable puncvec. The block encodes frames of data by puncturing a rate 1/2, constraint length 7 convolutional code to a rate 3/4 code. The puncture vector specified by puncvec is the optimal puncture vector for the rate 1/2, constraint length 7 convolutional code. A 1 in the puncture vector indicates that the bit in the corresponding position of the coded vector is sent to the output vector, while a 0 indicates that the bit is removed. For the configured encoder, coded bits in positions 1, 2, 4, and 5 are transmitted, while bits in positions 3 and 6 are removed. The rate 3/4 code means that for every 3 bits of input, the punctured code generates 4 bits of output.

  • BPSK Modulator Baseband — Modulates the encoded message using default parameter values.

  • AWGN Channel — Sets Mode to Signal to noise ratio (Es/No) and sets Es/No (dB) to the workspace variable EsN0dB. Since the modulator block generates unit power signals, Input signal power, referenced to 1 ohm (watts) keeps its default value of 1.

  • Viterbi Decoder — Uses settings for Trellis structure, Punctured code, and Puncture vector that align with the Convolutional Encoder block. The block sets Decision type to Unquantized and Traceback depth to the traceback workspace variable. To decode the specified convolutional code without puncturing the code, a traceback depth of 40 is sufficient. However, to give the decoder enough data to resolve the ambiguities introduced by the punctures, the block uses a traceback depth of 96 to decode the punctured code. Similar to the convolutional encoder, the puncture vector for the decoder indicates the locations of the punctures. For the decoder, the locations are bits to ignore in the decoding process because the punctured bits are not transmitted and there is no information to indicate their values. Each 1 in the puncture vector indicates a transmitted bit, and each 0 indicates a punctured bit to ignore in the input to the decoder.

  • Complex to Real-Imag (Simulink) — Demodulates the BPSK signal by extracting the real part of the complex samples.

  • Error Rate Calculation — Uses the Receive delay value to account for total number of samples of system delay and compares the decoded bits to the original source bits. The block outputs a three-element vector containing the calculated BER, the number of errors observed, and the number of bits processed. The Receive delay is set to the traceback workspace variable because the Viterbi traceback depth causes the only delay in the system. Typically, BER simulations run until a minimum number of errors have occurred, or until the simulation processes a maximum number of bits. The Error Rate Calculation block selects the Stop simulation parameter and sets the target number of errors to 100 and the maximum number of symbols to 1e6 to control the duration of the simulation.

Evaluate Bit Error Rate

Generate a bit error rate curve by running this code to simulate the model over a range of EbN0 settings.

Compare the simulation results with an approximation of the bit error probability bound for a punctured code as per [ 1 ]. The bit error rate performance of a rate $r = (n-1)/n$ punctured code is bounded above by the expression:

$${P_b} \le {1 \over {2\left( {n - 1} \right)}}\sum\limits_{d = {d_{{\rm
{free}}}}}^\infty {{\omega _d}\,{\mathop{\rm erfc}\nolimits} \left( {
\sqrt {{\mathop{\rm rd}\nolimits} \left( {{{{E_b}}
\mathord{\left/{\vphantom {{{E_b}} {{N_0}}}}
\right.\kern-\nulldelimiterspace} {{N_0}}}}\right)} } \right)} $$

In this expression, erfc denotes the complementary error function, $r$ is the code rate, and both $d_{free}$ and ${\omega _d}$ are dependent on the particular code. For the rate 3/4 code of this example, $d_{free}$ = 5, ${\omega _5}$ = 42, ${\omega _6}$ = 201, ${\omega _7}$ = 1492, and so on. For more information, see reference [ 1 ].

Compute an approximation of the theoretical bound using the first seven terms of the summation for Eb/N0 values in 2:0.02:5. The values used for nerr come from reference [ 2 ], Table II.

Plot the simulation results, a fitted curve, and theoretical bounds.

In some cases, at the lower bit error rates, you might notice simulation results that appear to indicate error rates slightly above the bound. This result can come from the finite traceback depth in the decoder or, if you observe fewer than 500 bit errors, from simulation variance.

For an example that shows convolutional coding without puncturing, see the Soft-Decision Decoding section in Error Detection and Correction.

References

  1. Yasuda, Y., K. Kashiki, and Y. Hirata, "High Rate Punctured Convolutional Codes for Soft Decision Viterbi Decoding," IEEE Transactions on Communications, Vol. COM-32, March, 1984, pp. 315–319.

  2. Begin, G., Haccoun, D., and Paquin, C., "Further results on High-Rate Punctured Convolutional Codes for Viterbi and Sequential Decoding," IEEE Transactions on Communications, Vol. 38, No. 11, November, 1990, p. 1923.

Use the Viterbi Decoder block for fixed-point hard- and soft-decision convolutional decoding. Compare results to theoretical upper bounds as computed with the Bit Error Rate Analysis app.

Simulation Configuration

The cm_viterbi_harddec_fixpt and cm_viterbi_softdec_fixpt models highlight the fixed-point modeling attributes of the Viterbi decoder, using similiar layouts. The default configuration of the models use the PreLoadFcn Callback to specify an ${E_b}/{N_0}$ setting of 4 dB for the AWGN Channel block. The convolutional encoder is configured as a rate 1/2 encoder. Specifically, for every 2 bits the encoder adds another 2 redundant bits. To accommodate the code rate, the Eb/No (dB) parameter of the AWGN block is halved by subtracting 10*log10(2) from the assigned ${E_b}/{N_0}$ setting. To limit the run duration to 100 errors or 1e6 bits for the Error Rate Calculation block.

Fixed-Point Modeling

Fixed-point modeling enables bit-true simulations which take into account hardware implementation considerations and the dynamic range of the data and parameters. For example, if the target hardware is a DSP microprocessor, some of the possible word lengths are 8, 16, or 32 bits, whereas if the target hardware is an ASIC or FPGA, there may be more flexibility in the word length selection.

To enable fixed-point Viterbi decoding,

  • For hard decisions, the block input must be of type ufix1 (unsigned integer of word length 1). Based on this input (either a 0 or a 1), the internal branch metrics are calculated using an unsigned integer of word length = (number of output bits), as specified by the trellis structure (which equals 2 for the hard-decision example).

  • For soft decisions, the block input must be of type ufixN (unsigned integer of word length N), where N is the number of soft-decision bits, to enable fixed-point decoding. The block inputs must be integers in the range 0 to $2^{N-1}$. The internal branch metrics are calculated using an unsigned integer of word length = (N + number of output bits - 1), as specified by the trellis structure (which equals 4 for the soft-decision example).

The State metric word length is specified by the user and usually must be greater than the branch metric word length already calculated. You can tune this to be the most suitable value (based on hardware and data considerations) by reviewing the logged data for the system.

Enable the logging by selecting Apps > Fixed-Point Tool. In the Fixed-Point Setting menu, set the Fixed-point instruments mode to Minimums, maximums and overflows, and rerun the simulation. If you see overflows, it implies the data did not fit in the selected container. You could either try scaling the data prior to processing it or, if your hardware allows, increase the size of the word length. Based on the minimum and maximum values of the data, you are also able to determine whether the selected container is of the appropriate size.

Try running simulations with different values of State metric word length to get an idea of its effect on the algorithm. You should be able to narrow down the parameter to a suitable value that has no adverse effect on the BER results.

The hard decision configuration for the cm_viterbi_harddec_fixpt model:

  • The Viterbi Decoder block has the Decision type parameter set to Hard decision, and on the Data Types tab, the State metric word length is set to 4 and the Output data type is set to boolean. The bit error rate is displayed and captured to the BER workspace variable.

The soft decision configuration for the cm_viterbi_softdec_fixpt model:

  • The Viterbi Decoder block has the Decision type parameter set to Soft decision and Number of soft decision bits set to 3, and on the Data Types tab, the State metric word length is set to 6 and the Output data type is set to boolean. The bit error rate is displayed and captured to the BER workspace variable.

Comparisons Between Hard and Soft-Decision Decoding

The two models are configured to run from within the Bit Error Rate Analysis app to generate simulation curves to compare the BER performance for hard-decision versus soft-decision decoding.

You can produce the results in this plot by following the steps outlined below.

These steps generate simulation results for theoretical and fixed-point hard and soft decision Viterbi decoding:

  1. Open the Bit Error Rate Analysis app by selecting it in the Apps tab or by entering bertool at the MATLAB command prompt.

  2. On the Theoretical pane, with Eb/N0 range set to 2:5, Channel type set to AWGN, Modulation type set to PSK, Channel coding set to Convolutional, run with Decision method set to Hard and then Soft. Rename the BER Data Set to identify the hard and soft data sets of theoretical results.

  3. On the Monte Carlo pane, set Eb/N0 range to 2:1:5, for Simulation environment select Simulink, BER variable name set to BER, for Simulation limits set Number of errors to 100 and Number of bits to 1e6. Run with Model name set to cm_viterbi_harddec_fixpt and then cm_viterbi_softdec_fixpt. Rename the BER Data Set to identify the hard and soft data sets of Simulink results.

After the four runs the app will resemble this image.

Comparisons with Double-Precision Data

For further explorations, you can run the same model with double precision data by selecting Apps > Fixed-Point Tool. In the Fixed-Point Tool app, select the Data type override to be Double. This selection overrides all data type settings in all the blocks to use double precision. For the Viterbi Decoder block, as Output type was set to boolean, this parameter should also be set to double.

Upon simulating the model, note that the double-precision and fixed-point BER results are the same. They are the same because the fixed-point parameters for the model have been selected to avoid any loss of precision and optimize memory efficiency.

Ports

Input

expand all

Input message, specified as a binary column vector. This port is unnamed until a second input port is enabled. If the encoder takes K input bit streams (that is, it can receive 2K possible input symbols), the block input vector length is L×K for some positive integer L.

Example: [1 1 0 1 0 0 1 1] specifies the message as a binary row vector with eight elements.

Data Types: double | single | Boolean | int8 | int16 | int32 | uint8 | uint16 | uint32 | ufix1

Initial state of encoder registers for every frame input to the block, specified as a nonnegative integer.

Dependencies

To enable this port set the Operation mode parameter to Truncated (reset every frame) and select Specify initial state via input port.

Data Types: double | uint32

Reset state of encoder registers, specified as scalar value. Any nonzero value forces a reset of the encoder registers.

Dependencies

To enable this port set the Operation mode parameter to Reset on nonzero input via port.

Data Types: double | Boolean

Output

expand all

Convolutionally encoded codeword, returned as a binary column vector. This port is unnamed on the block icon. If the encoder produces N output bit streams (that is, it can produce 2N possible output symbols), the block output vector length is L×N for some positive integer L. This output inherits its data type from the In input.

Data Types: double | single | Boolean | int8 | int16 | int32 | uint8 | uint16 | uint32 | ufix1

Final state of encoder registers for every frame output from the block, returned as a nonnegative integer.

Dependencies

This parameter appears only when you set the Operation mode parameter to Continuous, Truncated (reset every frame), or Reset on nonzero input via port and you select the Output final state parameter.

Data Types: double

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Trellis description of the convolutional code, specified as a structure that contains the trellis description for a rate KN code. K is the number of input bit streams, and N is the number of output bit streams.

You can either use the poly2trellis function to create the trellis structure or create it manually. For more about this structure, see Trellis Description of a Convolutional Code and the istrellis function.

The trellis structure contains these fields.

Number of symbols input to the encoder, specified as an integer equal to 2K, where K is the number of input bit streams.

Number of symbols output from the encoder, specified as an integer equal to 2N, where N is the number of output bit streams.

Number of states in the encoder, specified as a power of 2.

Next states for all combinations of current states and current inputs, specified as a matrix of integers. The matrix size must be numStates by 2K.

Outputs for all combinations of current states and current inputs, specified as a matrix of octal numbers. The matrix size must be numStates by 2K.

Termination method of the encoded frame, specified as one of these mode values.

  • Continuous — The block retains the encoder states at the end of each input for use with the next frame.

  • Truncated (reset every frame) — The block treats each input independently. At the start of each input frame, the encoder states are reset to all-zeros state, or if you select Specify initial state via input port, to the state specified by the ISt port.

  • Terminate trellis by appending bits — The block treats each input independently. For each input frame, extra bits are used to set the encoder states to all-zeros state at the end of the frame. The output length is given by y = N × (x + s) / K, where x is the number of input bits, and s = constraint length – 1 (or, in the case of multiple constraint lengths, s =sum(constraint length(i) – 1)).

    Note

    This block works for cases K ≥ 1, where it has the same values for constraint lengths in each input stream. For example, constraint lengths of [2 2] or [7 7] will work, but [5 4] will not.

  • Reset on nonzero input via port — The block has an additional input port, labeled Rst. When the Rst input is nonzero, the encoder resets to the all-zeros state.

Note

When this block outputs sequences that vary in length during simulation and you set the Operation mode to Truncated (reset every frame) or Terminate trellis by appending bits, the block's state resets at every input time step.

Select this parameter to reset the block after computing the encoded data. The delay in the reset action allows the block to support HDL code generation. Generating HDL code, requires HDL Coder™ software.

Dependencies

This parameter appears only when you set the Operation mode parameter to Reset on nonzero input via port.

Select this parameter to add the ISt input port to the block.

Dependencies

This parameter appears only when you set the Operation mode parameter to Truncated (reset every frame).

Select this parameter to add the FSt output port to the block.

Dependencies

This parameter appears only when you set the Operation mode parameter to Continuous, Truncated (reset every frame), or Reset on nonzero input via port.

Select this parameter to view and enable the Puncture vector parameter.

Puncture pattern, specified as vector. The puncture vector is a pattern of 1s and 0s where the 0s indicate the bits punctured in the output encoded data. The length of the vector must be an integer divisor of length(In), the input message vector length.

For some commonly used puncture patterns for specific rates and polynomials, see the Yasuda [3], Haccoun [4], and Begin [5] references.

Dependencies

This parameter appears only when you select the Puncture code parameter.

Block Characteristics

Data Types

Boolean | double | fixed pointa | integer | single

Multidimensional Signals

no

Variable-Size Signals

yes

a ufix(1) only.

More About

expand all

References

[1] Clark, George C., and J. Bibb Cain. Error-Correction Coding for Digital Communications. Applications of Communications Theory. New York: Plenum Press, 1981.

[2] Gitlin, Richard D., Jeremiah F. Hayes, and Stephen B. Weinstein. Data Communications Principles. Applications of Communications Theory. New York: Plenum Press, 1992.

[3] Yasuda, Y., K. Kashiki, and Y. Hirata. “High-Rate Punctured Convolutional Codes for Soft Decision Viterbi Decoding.” IEEE Transactions on Communications 32, no. 3 (March 1984): 315–19. https://doi.org/10.1109/TCOM.1984.1096047.

[4] Haccoun, D., and G. Begin. “High-Rate Punctured Convolutional Codes for Viterbi and Sequential Decoding.” IEEE Transactions on Communications 37, no. 11 (November 1989): 1113–25. https://doi.org/10.1109/26.46505.

[5] Begin, G., D. Haccoun, and C. Paquin. “Further Results on High-Rate Punctured Convolutional Codes for Viterbi and Sequential Decoding.” IEEE Transactions on Communications 38, no. 11 (November 1990): 1922–28. https://doi.org/10.1109/26.61470.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a