📄 trellis_encoder.m
字号:
function [trel_output, currentState]=trellis_encoder(info_bits, trellis, currentState, type);
%trellis_encoder implements the trellis codes specified in
%trellis.
%General enough for convolutional codes and trellis codes.
%Ready for used in turbo codes.
%Structure of trellis:
% trellis.numTotalInput
% trellis.numTotalOutput
% trellis.numInputSymbols (only from trellis)
% trellis.numStates (only from trellis)
% trellis.nextStates (only from trellis)
% trellis.numOutputSymbols (only from trellis)
% trellis.outputs (only from trellis)
%info_bits is the binary input.
%trel_output is the output binary sequence
%
%By Aijun Song, July, 2005
if nargin<2 | nargin>4,
disp('[trellis_encoder]Only two-four inputs are supported');
return;
end
if nargin==2 | nargin==3
type='tailing';
end
if nargin==2
currentState=0;
end
if isempty(currentState)
currentState=0;
end
if isempty(type)
type='tailing';
end
if size(info_bits, 1)>1 & size(info_bits, 2)>1,
disp('[trellis_encoder]info_bits is not a vector');
return;
end
if ~strcmp(lower(type), 'no_tailing') & ~strcmp(lower(type), 'notailing') & ~strcmp(lower(type), 'tailing')
disp('[trellis_encoder]Wrong type.')
return;
end
numTrelInput=log2(trellis.numInputSymbols);
numRegisters=log2(trellis.numStates);
numTrelOutput=log2(trellis.numOutputSymbols);
%encoding intialization
%radix assumes the first bit is MSB.
input_radix=2.^[numTrelInput-1:-1:0];
%generate a table for fast converting decimals to binary vectors.
%mTable is a 2^Ndigits times Ndigits matrix;
mTable=dec2base_tab(numTrelOutput, 2);
if mod(length(info_bits), trellis.numTotalInput)~=0,
tval=trellis.numTotalInput-mod(length(info_bits), trellis.numTotalInput);
info_bits=[info_bits; zeros(tval, 1)];
end
%trellis coding
blk_num=floor(length(info_bits)/trellis.numTotalInput);
total_output=(blk_num)* trellis.numTotalOutput;
trel_output=zeros(total_output, 1);
for ic=1: blk_num;
currentInputVec=info_bits((ic-1)*trellis.numTotalInput+1: ic*trellis.numTotalInput);
currentInput=input_radix*currentInputVec(1: numTrelInput);
currentOutput=trellis.outputs(currentState+1, currentInput+1);
currentState=trellis.nextStates(currentState+1, currentInput+1);
currentOutputVec=[mTable(currentOutput+1, :).'; currentInputVec(numTrelInput+1: trellis.numTotalInput)];
trel_output((ic-1)*trellis.numTotalOutput+1: ic*trellis.numTotalOutput)=currentOutputVec;
end
if strcmp(lower(type), 'no_tailing') | strcmp(lower(type), 'notailing')
return;
end
%Expand the trel_output emplicitly.
trel_output=[trel_output; zeros(trellis.numTotalOutput*numRegisters, 1)];
%trellis coding--pading with zeros
for ic=blk_num+1: blk_num+numRegisters;
currentInputVec=zeros(trellis.numTotalInput, 1);
currentInput=input_radix*currentInputVec(1: numTrelInput);
currentOutput=trellis.outputs(currentState+1, currentInput+1);
currentState=trellis.nextStates(currentState+1, currentInput+1);
currentOutputVec=[mTable(currentOutput+1, :).'; currentInputVec(numTrelInput+1: trellis.numTotalInput)];
trel_output((ic-1)*trellis.numTotalOutput+1: ic*trellis.numTotalOutput)=currentOutputVec;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -