LinearBlockCode - Maltab Program:
clc;
clear all;
close all;
k=input('Number of message bits');
n=input('Number of coded bits');
P=[1 1 1;0 1 1;1 0 1;1 1 0]
G=[eye(k) P]
for i=1:2^k
str=dec2base(i-1,2,4);
for j=1:k
m(i,j)=str(j);
end
end
for i=1:(2^k)
for r=1:n
o=0;
for j=1:k
o=o+(m(i,j)*G(j,r));
end
c(i,r)=mod(o,2);
end
end
e=zeros(n,n)
for i=1:n
e(i,i)=1;
end
% Syndrome Table
H=[P' eye(n-k)];
H1=H';
for i=1:n
for r=1:n-k
o=0;
for j=1:n
o=o+(e(i,j)*H1(j,r));
end
er(i,r)=mod(o,2);
end
end
for i=1:n
rec1=c(2^k,i)+e(1,i);
rec(1,i)=mod(rec1,2);
end
for i=1:1
for r=1:n-k
o=0;
for j=1:n
o=o+(rec(i,j)*H1(j,r));
end
sy(i,r)=mod(o,2);
end
end
i=1;
j=1;
while sy(1,j)==er(i,j)&&sy(1,j+1)==er(i,j+1)&&sy(1,j+2)==er(i,j+2)
rec_er=e(i,:);
i=i+1;
end
rec_er
%Error Corrected Message
for i=1:n
Det=rec(1,i)+rec_er(1,i);
det_rec(1,i)=mod(Det,2);
end
det_rec
clc;
clear all;
close all;
k=input('Number of message bits');
n=input('Number of coded bits');
P=[1 1 1;0 1 1;1 0 1;1 1 0]
G=[eye(k) P]
for i=1:2^k
str=dec2base(i-1,2,4);
for j=1:k
m(i,j)=str(j);
end
end
for i=1:(2^k)
for r=1:n
o=0;
for j=1:k
o=o+(m(i,j)*G(j,r));
end
c(i,r)=mod(o,2);
end
end
e=zeros(n,n)
for i=1:n
e(i,i)=1;
end
% Syndrome Table
H=[P' eye(n-k)];
H1=H';
for i=1:n
for r=1:n-k
o=0;
for j=1:n
o=o+(e(i,j)*H1(j,r));
end
er(i,r)=mod(o,2);
end
end
for i=1:n
rec1=c(2^k,i)+e(1,i);
rec(1,i)=mod(rec1,2);
end
for i=1:1
for r=1:n-k
o=0;
for j=1:n
o=o+(rec(i,j)*H1(j,r));
end
sy(i,r)=mod(o,2);
end
end
i=1;
j=1;
while sy(1,j)==er(i,j)&&sy(1,j+1)==er(i,j+1)&&sy(1,j+2)==er(i,j+2)
rec_er=e(i,:);
i=i+1;
end
rec_er
%Error Corrected Message
for i=1:n
Det=rec(1,i)+rec_er(1,i);
det_rec(1,i)=mod(Det,2);
end
det_rec
0 comments:
Post a Comment