You are on page 1of 3

Convolutional decoder using Viterbi Algorithm

clc;
clear all;
close all;
syms s1 s2 s3 s4
r=input('Enter the received message bits....\n');
n=length(r);
input=[0 0 0;0 0 1;0 1 0;0 1 1;1 0 0;1 0 1;1 1 0;1 1 1];
code=zeros(8,6);
for j=1:8
p_st=s1;
for i=0:2
[q,n_st]=state( p_st,input(j,i+1));
code(j,1+i*2)=q(1);
code(j,2+i*2)=q(2);
p_st=n_st;
end
end
message=zeros(1,n-5);
for i=1:(n-5)
dmin=6;
for j=1:8
hamming_dist = sum(r(i:6+i-1)~=code(j));
if(dmin>hamming_dist)
dmin=hamming_dist;
a=j;
end
end
if(a<=4)
message(i)=0;
else
message(i)=1;

end
end
message

state function:

function [output,n_st] = state(p_st,i)


syms s1 s2 s3 s4
if(p_st==s1 && i==0)
n_st=s1;
output=[0 0];
elseif(p_st==s1 && i==1)
n_st=s3;
output=[1 1];
elseif(p_st==s2 && i==0)
n_st=s1;
output=[1 0];
elseif(p_st==s2 && i==1)
n_st=s3;
output=[0 1];
elseif(p_st==s3 && i==0)
n_st=s2;
output=[1 1];
elseif(p_st==s3 && i==1)
n_st=s4;
output=[0 0];
elseif(p_st==s4 && i==0)
n_st=s2;
output=[0 1];
elseif(p_st==s4 && i==1)

n_st=s4;
output=[1 0];
end
end

Output:
Enter the received message bits....
[1 1 0 1 0 1 1 0 0]
message =
1

You might also like