vitdec

Convolutionally decode binary data using Viterbi algorithm

Syntax

decoded = vitdec(code,trellis,tblen,opmode,dectype)
decoded = vitdec(code,trellis,tblen,opmode,'soft',nsdec)
decoded = ...
vitdec(...,'cont',...,initmetric,initstates,initinputs)
[decoded,finalmetric,finalstates,finalinputs] = ...
vitdec(...,'cont',...)

Description

decoded = vitdec(code,trellis,tblen,opmode,dectype) decodes the vector code using the Viterbi algorithm. The MATLAB structure trellis specifies the convolutional encoder that produced code; the format of trellis is described in Trellis Description of a Convolutional Encoder and the reference page for the istrellis function. code contains one or more symbols, each of which consists of log2(trellis.numOutputSymbols) bits. Each symbol in the vector decoded consists of log2(trellis.numInputSymbols) bits. tblen is a positive integer scalar that specifies the traceback depth. If the code rate is 1/2, then a typical value for tblen is about five times the constraint length of the code.

The string opmode indicates the decoder's operation mode and its assumptions about the corresponding encoder's operation. Choices are in the table below.

Values of opmode Input

ValueMeaning
'cont'The encoder is assumed to have started at the all-zeros state. The decoder traces back from the state with the best metric. A delay equal to tblen symbols elapses before the first decoded symbol appears in the output. This mode is appropriate when you invoke this function repeatedly and want to preserve continuity between successive invocations. See the continuous operation mode syntaxes below.
'term'The encoder is assumed to have both started and ended at the all-zeros state, which is true for the default syntax of the convenc function. The decoder traces back from the all-zeros state. This mode incurs no delay. This mode is appropriate when the uncoded message (that is, the input to convenc) has enough zeros at the end to fill all memory registers of the encoder. If the encoder has k input streams and constraint length vector constr (using the polynomial description of the encoder), then "enough" means k*max(constr-1).
'trunc'The encoder is assumed to have started at the all-zeros state. The decoder traces back from the state with the best metric. This mode incurs no delay. This mode is appropriate when you cannot assume the encoder ended at the all-zeros state and when you do not want to preserve continuity between successive invocations of this function.

The string dectype indicates the type of decision that the decoder makes, and influences the type of data the decoder expects in code. Choices are in the table below.

Values of dectype Input

ValueMeaning
'unquant'code contains real input values, where 1 represents a logical zero and -1 represents a logical one.
'hard'code contains binary input values.
'soft'For soft-decision decoding, use the syntax below. Note that nsdec is required for soft-decision decoding.

Syntax for Soft Decision Decoding

decoded = vitdec(code,trellis,tblen,opmode,'soft',nsdec) decodes the vector code using soft-decision decoding. code consists of integers between 0 and 2^nsdec-1, where 0 represents the most confident 0 and 2^nsdec-1 represents the most confident 1.

Additional Syntaxes for Continuous Operation Mode

Continuous operation mode enables you to save the decoder's internal state information for use in a subsequent invocation of this function. Repeated calls to this function are useful if your data is partitioned into a series of smaller vectors that you process within a loop, for example.

decoded = ...
vitdec(...,'cont',...,initmetric,initstates,initinputs)
is the same as the earlier syntaxes, except that the decoder starts with its state metrics, traceback states, and traceback inputs specified by initmetric, initstates, and initinputs, respectively. Each real number in initmetric represents the starting state metric of the corresponding state. initstates and initinputs jointly specify the initial traceback memory of the decoder; both are trellis.numStates-by-tblen matrices. initstates consists of integers between 0 and trellis.numStates-1. If the encoder schematic has more than one input stream, then the shift register that receives the first input stream provides the least significant bits in initstates, while the shift register that receives the last input stream provides the most significant bits in initstates. The vector initinputs consists of integers between 0 and trellis.numInputSymbols-1. To use default values for all of the last three arguments, specify them as [],[],[].

[decoded,finalmetric,finalstates,finalinputs] = ...
vitdec(...,'cont',...)
is the same as the earlier syntaxes, except that the final three output arguments return the state metrics, traceback states, and traceback inputs, respectively, at the end of the decoding process. finalmetric is a vector with trellis.numStates elements that correspond to the final state metrics. finalstates and finalinputs are both matrices of size trellis.numStates-by-tblen. The elements of finalstates have the same format as those of initstates.

Examples

The example below encodes random data and adds noise. Then it decodes the noisy code three times to illustrate the three decision types that vitdec supports. Notice that for unquantized and soft decisions, the output of convenc does not have the same data type that vitdec expects for the input code, so it is necessary to manipulate ncode before invoking vitdec. Notice also that the bit error rate computations must account for the delay that the continuous operation mode incurs.

trel = poly2trellis(3,[6 7]); % Define trellis.
msg = randint(100,1,2,123); % Random data
code = convenc(msg,trel); % Encode.
ncode = rem(code + randerr(200,1,[0 1;.95 .05]),2); % Add noise.
tblen = 3; % Traceback length
decoded1 = vitdec(ncode,trel,tblen,'cont','hard'); %Hard decision
% Use unquantized decisions.
ucode = 1-2*ncode; % +1 & -1 represent zero & one, respectively.
decoded2 = vitdec(ucode,trel,tblen,'cont','unquant');
% To prepare for soft-decision decoding, map to decision values.
[x,qcode] = quantiz(1-2*ncode,[-.75 -.5 -.25 0 .25 .5 .75],...
[7 6 5 4 3 2 1 0]); % Values in qcode are between 0 and 2^3-1.
decoded3 = vitdec(qcode',trel,tblen,'cont','soft',3);
% Compute bit error rates, using the fact that the decoder
% output is delayed by tblen symbols.
[n1,r1] = biterr(decoded1(tblen+1:end),msg(1:end-tblen));
[n2,r2] = biterr(decoded2(tblen+1:end),msg(1:end-tblen));
[n3,r3] = biterr(decoded3(tblen+1:end),msg(1:end-tblen));
disp(['The bit error rates are:   ',num2str([r1 r2 r3])])

The output is

The bit error rates are:   0.020619    0.020619    0.020619

The example below illustrates how to use the final state and initial state arguments when invoking vitdec repeatedly. Notice that [decoded4;decoded5] is the same as decoded6.

trel = poly2trellis(3,[6 7]);
code = convenc(randint(100,1,2,123),trel);
% Decode part of code, recording final state for later use.
[decoded4,f1,f2,f3] = vitdec(code(1:100),trel,3,'cont','hard');
% Decode the rest of code, using state input arguments.
decoded5 = vitdec(code(101:200),trel,3,'cont','hard',f1,f2,f3);
% Decode the entire code in one step.
decoded6 = vitdec(code,trel,3,'cont','hard');
isequal(decoded6,[decoded4; decoded5])

The output is

ans =

     1

For additional examples, see Examples of Convolutional Coding.

See Also

convenc, poly2trellis, istrellis, vitsimdemo, vitsimexample, Convolutional Coding

References

[1] Gitlin, Richard D., Jeremiah F. Hayes, and Stephen B. Weinstein, Data Communications Principles, New York, Plenum, 1992.


© 1994-2005 The MathWorks, Inc.