Communications Toolbox | ![]() ![]() |
Examples of Convolutional Coding
This section contains more examples of convolutional coding:
Example: A Rate-2/3 Feedforward Encoder
The example below uses the rate 2/3 feedforward encoder depicted in the schematic below. The accompanying description explains how to determine the trellis structure parameter from a schematic of the encoder and then how to perform coding using this encoder.
Determining Coding Parameters. The convenc
and vitdec
functions can implement this code if their parameters have the appropriate values.
The encoder's constraint length is a vector of length 2 because the encoder has two inputs. The elements of this vector indicate the number of bits stored in each shift register, including the current input bits. Counting memory spaces in each shift register in the diagram and adding one for the current inputs leads to a constraint length of [5 4].
To determine the code generator parameter as a 2-by-3 matrix of octal numbers, use the element in the ith row and jth column to indicate how the ith input contributes to the jth output. For example, to compute the element in the second row and third column, notice that the leftmost and two rightmost elements in the second shift register of the diagram feed into the sum that forms the third output. Capture this information as the binary number 1011, which is equivalent to the octal number 13. The full value of the code generator matrix is [23 35 0; 0 5 13].
To use the constraint length and code generator parameters in the convenc
and vitdec
functions, use the poly2trellis
function to convert those parameters into a trellis structure. The command to do this is below.
Using the Encoder. Below is a script that uses this encoder.
len = 1000; msg = randint(2*len,1); % Random binary message of 2-bit symbols trel = poly2trellis([5 4],[23 35 0;0 5 13]); % Trellis code = convenc(msg,trel); % Encode the message. ncode = rem(code + randerr(3*len,1,[0 1;.96 .04]),2); % Add noise. decoded = vitdec(ncode,trel,34,'cont','hard'); % Decode. [number,ratio] = biterr(decoded(68+1:end),msg(1:end-68));
Notice that convenc
accepts a vector containing 2-bit symbols and produces a vector containing 3-bit symbols, while vitdec
does the opposite. Also notice that biterr
ignores the first 68 elements of decoded
. That is, the decoding delay is 68, which is the number of bits per symbol (2) of the recovered message times the traceback depth value (34) in the vitdec
function. The first 68 elements of decoded
are 0s, while subsequent elements represent the decoded messages.
Example: A Punctured Convolutional Code
This example processes a punctured convolutional code. It begins by generating 3000 random bits and encoding them using a rate-1/2 convolutional encoder. The resulting vector contains 6000 bits, which are mapped to values of -1 and 1 for transmission. The puncturing process removes every third value and results in a vector of length 4000. The punctured code, punctcode
, passes through an additive white Gaussian noise channel. Afterwards, the example inserts values to reverse the puncturing process. While the puncturing process removed both -1s and 1s from code, the insertion process inserts zeros. Then vitdec
decodes the vector of -1s, 1s, and 0s using the 'unquant'
decision type. This unquantized decision type is appropriate here for these reasons:
tcode
uses -1 to represent the 1s in code
.
tcode
uses 1 to represent the 0s in code
.
'unquant'
decision type, which allows any real values as input.
Finally, the example computes the bit error rate and the number of bit errors.
len = 3000; msg = randint(len,1,2,94384); % Random data t = poly2trellis(7,[171 133]); % Define trellis. code = convenc(msg,t); % Length is 2*len. tcode = -2*code+1; % Transmit -1s and 1s. % Puncture by removing every third value. punctcode = tcode; punctcode(3:3:end)=[]; % Length is (2*len)*2/3. ncode = awgn(punctcode,8,'measured',1234); % Add noise. % Insert zeros. nicode = zeros(2*len,1); % Zeros represent inserted data. nicode(1:3:end) = ncode(1:2:end); % Write actual data. nicode(2:3:end) = ncode(2:2:end); % Write actual data. decoded = vitdec(nicode,t,96,'trunc','unquant'); % Decode. [number,ratio]=biterr(decoded,msg); % Bit error rate
![]() | Creating and Decoding Convolutional Codes | Selected Bibliography for Convolutional Coding | ![]() |