Communications Toolbox | ![]() ![]() |
Convolutionally decode binary data using the 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,
decodes the vector opmode
,dectype
)
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.
The string opmode
indicates the decoder's operation mode and its assumptions about the corresponding encoder's operation. Choices are in the table below.
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.
Syntax for Soft Decision Decoding
decoded = vitdec(code,trellis,tblen,
decodes the vector opmode
,'soft
',nsdec)
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
decoded = vitdec(...,'
is the same as the earlier syntaxes, except that the decoder starts with its state metrics, traceback states, and traceback inputs specified by cont
',...,initmetric,initstates,initinputs)
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] = ...
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.
vitdec(...,'cont
',...)
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
.
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 % Use hard decisions. decoded1 = vitdec(ncode,trel,tblen,'cont','hard'); % Use unquantized decisions. ucode = 1-2*ncode; % +1 & -1 represent zero & one, respectively. decoded2 = vitdec(ucode,trel,tblen,'cont','unquant'); % Use soft decisions. % 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 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]) ans = 1
See Also
convenc
, poly2trellis
, istrellis
, vitsimdemo
References
Gitlin, Richard D., Jeremiah F. Hayes, and Stephen B. Weinstein, Data Communications Principles, New York, Plenum, 1992.
![]() | vec2mat | wgn | ![]() |