Viterbi Decoding

7 views (last 30 days)
Abi Aarthy
Abi Aarthy on 23 Jan 2012
clc;
clear all;
close all;
N=10;%number of databits send over channel
for i=1:N
a(i)=randint;%generate random binary inputs
i=i+1;
end
inter=randintrlv(a,N);
deinter = randdeintrlv(inter,N);
%encoding
trel=poly2trellis(4,[13 15], 13);
parity1=convenc(a,trel);
parity2=convenc(inter,trel);
enco1=horzcat(a,parity1,parity2);
%modultion
y = pskmod(enco1,8);
%channel
chan = ricianchan;%(.01,10,2);
z=filter(chan,y);
%demodulation
demod = pskdemod(z,8);
p=demod(1:10);
q=demod(11:30);
r=demod(31:50);
deinter1=zeros(1,10);
%decoding
for i=1:2
decode1=horzcat(p,q,deinter1);
decoder1=vitdec(decode1,trel,20,'cont','hard');
inter1=randintrlv(decoder1,length(decoder1));
inter2=randintrlv(p,length(p));
decode2=horzcat(r,inter1,inter2);
decoder2=vitdec(decode2,trel,20,'cont','hard');
deinter1=randdeintrlv(decoder2,length(decoder2));
i=i+1;
end
%Error:Length of the input code vector must be a multiple of the number of bits in an
input symbol.
Error in ==> pnsg at 32
decoder1=vitdec(decode1,trel,20,'cont','hard');
Please help us to correct this error.

Answers (1)

Walter Roberson
Walter Roberson on 23 Jan 2012
You have already been told what the problem is: http://www.mathworks.com/matlabcentral/answers/26596-viterbi-decoder
You create
trel=poly2trellis(4,[13 15], 13);
In terms of the documented syntax for poly2trellis:
trellis = poly2trellis(ConstraintLength,CodeGenerator) performs the conversion for a rate k/n feedforward encoder. ConstraintLength is a 1-by-k vector that specifies the delay for the encoder's k input bit streams. CodeGenerator is a k-by-n matrix of octal numbers that specifies the n output connections for each of the encoder's k input bit streams.
Now your first argument is 1-by-1 and that must match 1-by-k so we deduce that your k is 1. And then your second argument is 1-by-2 and that must match k-by-n and we figured k is 1 so we are matching 1-by-n and thus we deduce that n is 2.
Then we read down further and see that the output structure includes
numOutputSymbols Scalar Number of output symbols from the encoder: 2^n
and as we have figured that n is 2, we deduce that numOutputSymbols will be 2^2 = 4.
Your problem is occurring in the vitdec step and as we discussed before, log2(trel.numInputSymbols) must evenly divide length(decode1). So log2(4) must evenly divide length(decode1), so 2 must evenly divide length(decode1)
At this point you must debug your program and check what length(decode1) actually is. Especially on the second round (i=2)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!