%% Implementation of Generation and Decoding of Cyclic Codes
%% Implementation of Generation and Decoding of Cyclic Codes
k=input('enter the order of the message= '); x=sym('x'); ik=eye(k) ink=eye(n-k); g=input('Enter the Generator Polynomial in terms of bits having the order of n-k ='); disp('Generator polynomial'); gp=poly2sym(g) % gp=1+x^2+x^3 jk=x^(n-k); for i=1:k xk=poly2sym(ik(i,:)); y=xk*jk;A [qp,remp]=quorem(y,gp); % z(i,:)=y+remp a(i,:)=mod(remp,2); end a p=input('enter the parity matrix='); disp('Generator Matrix:'); G=cat(2,ik,p) m=2^k; a=[0:m-1]; %Left MSB Return MSB to L.H.S d=de2bi(a); b=d*G; codewords=rem(b,2) dmin=gfweight(G) td=dmin-1 tc=td/2 H=[p' ink] Ht=H' z=zeros(1,n); e=eye(n); E=[z;e] a1=E*Ht; %% Decoding Table Dec=[E a1] %% checking Validity of the Received Codewor r=input('Enter the Received Code r='); rp=poly2sym(r) [qp,remp]=quorem(rp,gp); disp('Syndrome polynomial:'); % disp(remp); remp=mod(remp,2); s=sym2poly(remp); % s=mod(rem,2); disp('Syndrome :');disp(remp); s=input('enter the syndrome having size 1x3=') if (s == 0)
disp('The received code is correct'); else for j=1:1:length(E) m=xor(s,a1(j,:)); if (m==0) row = j; break; end end disp('The Corrected codeword is=') rc=xor(r,E(j,:)) end
enter the order of the code= 7 enter the order of the message= 4
ik =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Enter the Generator Polynomial in terms of bits having the order of n-k =[1 0 1 1] Generator polynomial
gp =
x^3 + x + 1
a=
G=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
1 1 1 0
0 1 1 1
1 1 0 1
codewords =
0 1 0 1 0 1
0 0 1 1 0 0
0 0 0 0 1 1
0 0 0 0 0 0
0 1 1 0 1 0
0 0 1 1 1 1
0 1 1 0 0 1
0 1 0 1 0 1 0 1 0 1
1 1 0 0 1 1 0 0 1 1
1 1 0 0 0 0 1 1 1 1
0 0 1 1 1 1 1 1 1 1
0 1 0 1 1 0 1 0 0 1
0 0 1 1 0 0 0 0 1 1
1 0 1 0 0 1 1 0 0 1
dmin =
td =
tc =
H=
1 0 1
1 1 1
1 1 0
0 1 1
1 0 0
0 1 0
0 0 1
Ht =
1 1 1 0 1 0 0
0 1 1 1 0 1 0
1 1 0 1 0 0 1
E=
0 1 0
0 0 1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Dec =
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
0 1 1 1 0 1 0 0
0 0 1 1 1 0 1 0
0 1 1 0 1 0 0 1
rp =
Syndrome polynomial:
Syndrome : x^2
s=
rc =
>>