Communications Toolbox | ![]() ![]() |
Creating and Decoding Convolutional Codes
The functions for encoding and decoding convolutional codes are convenc
and vitdec
. This section discusses using these functions to create and decode convolutional codes.
Encoding
A simple way to use convenc
to create a convolutional code is shown in the commands below.
t = poly2trellis([4 3],[4 5 17;7 4 2]); % Define trellis. code = convenc(ones(100,1),t); % Encode a string of ones.
The first command converts a polynomial description of a feedforward convolutional encoder to the corresponding trellis description. The second command encodes 100 bits, or 50 two-bit symbols. Because the code rate in this example is 2/3, the output vector code
contains 150 bits (that is, 100 input bits times 3/2).
Hard-Decision Decoding
To decode using hard decisions, use the vitdec
function with the flag 'hard'
and with binary input data. Because the output of convenc
is binary, hard-decision decoding can use the output of convenc
directly, without additional processing. This example extends the previous example and implements hard decision decoding.
t = poly2trellis([4 3],[4 5 17;7 4 2]); % Define trellis. code = convenc(ones(100,1),t); % Encode a string of ones. tb = 2; % Traceback length for decoding decoded = vitdec(code,t,tb,'trunc','hard'); % Decode.
Soft-Decision Decoding
To decode using soft decisions, use the vitdec
function with the flag 'soft'
. You must also specify the number, nsdec
, of soft-decision bits and use input data consisting of integers between 0 and 2^nsdec-1
.
An input of 0 represents the most confident 0, while an input of 2^nsdec-1
represents the most confident 1. Other values represent less confident decisions. For example, the table below lists interpretations of values for 3-bit soft decisions.
Example: Soft-Decision Decoding. The script below illustrates decoding with 3-bit soft decisions. First it creates a convolutional code with convenc
and adds white Gaussian noise to the code with awgn
. Then, to prepare for soft-decision decoding, the example uses quantiz
to map the noisy data values to appropriate decision-value integers between 0 and 7. The second argument in quantiz
is a partition vector that determines which data values map to 0, 1, 2, etc. The partition is chosen so that values near 0 map to 0, and values near 1 map to 7. (You can refine the partition to obtain better decoding performance if your application requires it.) Finally, the example decodes the code and computes the bit error rate. Notice that when comparing the decoded data with the original message, the example must take the decoding delay into account. The continuous operation mode of vitdec
causes a delay equal to the traceback length, so msg(1)
corresponds to decoded(tblen+1)
rather than to decoded(1)
.
msg = randint(4000,1,2,139); % Random data t = poly2trellis(7,[171 133]); % Define trellis. code = convenc(msg,t); % Encode the data. ncode = awgn(code,6,'measured',244); % Add noise. % Quantize to prepare for soft-decision decoding. qcode = quantiz(ncode,[0.001,.1,.3,.5,.7,.9,.999]); tblen = 48; delay = tblen; % Traceback length decoded = vitdec(qcode,t,tblen,'cont','soft',3); % Decode. % Compute bit error rate. [number,ratio] = biterr(decoded(delay+1:end),msg(1:end-delay))
![]() | Trellis Description of a Convolutional Encoder | Examples of Convolutional Coding | ![]() |