Communications Toolbox | ![]() ![]() |
Convolutionally encode binary data
Syntax
code = convenc(msg,trellis); code = convenc(msg,trellis,init_state); [code,final_state] = convenc(...);
Description
code = convenc(msg,trellis)
encodes the binary vector msg
using the convolutional encoder whose MATLAB trellis structure is trellis
. For details about MATLAB trellis structures, see Trellis Description of a Convolutional Encoder. Each symbol in msg
consists of log2(trellis.numInputSymbols)
bits. The vector msg
contains one or more symbols. The output vector code
contains one or more symbols, each of which consists of log2(trellis.numOutputSymbols)
bits.
code = convenc(msg,trellis,init_state)
is the same as the syntax above, except that init_state
specifies the starting state of the encoder registers. The scalar init_state
is an integer 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 init_state
, while the shift register that receives the last input stream provides the most significant bits in init_state
. To use the default value for init_state
, specify init_state
as 0
or []
.
[code,final_state] = convenc(...)
encodes the input message and also returns in final_state
the encoder's state. final_state
has the same format as init_state
.
Examples
The command below encodes five two-bit symbols using a rate 2/3 convolutional code. A schematic of this encoder is on the reference page for the poly2trellis
function.
The commands below define the encoder's trellis structure explicitly and then use convenc
to encode ten one-bit symbols. A schematic of this encoder is in Trellis Description of a Convolutional Encoder.
trel = struct('numInputSymbols',2,'numOutputSymbols',4,... 'numStates',4,'nextStates',[0 2;0 2;1 3;1 3],... 'outputs',[0 3;1 2;3 0;2 1]); code2 = convenc(randint(10,1),trel);
The commands below illustrate how to use the final state and initial state arguments when invoking convenc
repeatedly. Notice that [code3; code4]
is the same as the earlier example's output, code1
.
trel = poly2trellis([5 4],[23 35 0; 0 5 13]); msg = randint(10,1,2,123); % Encode part of msg, recording final state for later use. [code3,fstate] = convenc(msg(1:6),trel); % Encode the rest of msg, using state as an input argument. code4 = convenc(msg(7:10),trel,fstate);
See Also
vitdec
, poly2trellis
, istrellis
, vitsimdemo
References
Gitlin, Richard D., Jeremiah F. Hayes, and Stephen B. Weinstein, Data Communications Principles, New York, Plenum, 1992.
![]() | compand | convmtx | ![]() |