You are on page 1of 2

6.

Convolutional Encoding and Viterbi Decoding


clear all;
close all;
clc;
k=input('enter the constraint length: ')
m=input('enter the message bits: ')
v=zeros(length(m),k)
a=zeros(1,k-1);
for i=1:length(m)
for j=k:-1:2
a(j)=a(j-1);
end
a(1)=m(i);
v(i,1)=a(1);
v(i,2)=xor(a(1),a(3));
v(i,3)=abs(mod(sum(a,2),2));
end
o=v'
encoded_output=reshape(o,1,k*length(m))

trellis=poly2trellis(k,[4 5 7])
trellis_encoded =convenc(m,trellis)

%%DECODING
decode=vitdec(code,trellis,k,'trunc','hard')

%%% OUTPUT%%%
enter the constraint length: 3
k =
3
enter the message bits: [1 1 0 1 1]
m =
1 1 0 1 1
v =
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
o =
1 1 0 1 1
1 1 1 0 1
1 0 0 0 0
encoded_output =
Columns 1 through 12

1 1 1 1 1 0 0 1 0 1 0 0
Columns 13 through 15

1 1 0

trellis =
numInputSymbols: 2
numOutputSymbols: 8
numStates: 4
nextStates: [4x2 double]
outputs: [4x2 double]

trellis_encoded =
Columns 1 through 12
1 1 1 1 1 0 0 1 0 1 0 0

Columns 13 through 15

1 1 0
decode =

1 1 0 1 1

You might also like