You are on page 1of 3

Experiment 4: cyclic codes

Name: Shreya Ambeti


Roll no: UEC2022005
ITCT

Code:

% Encoding
clc;
clear all;
close all;
k = input("Enter the number of bits k:");
d = input("Enter the data bits");
n = input("Enter the code length n:");
m = (n-k);
disp("m=");
disp(m);
g=input("enter coefficients of generator polynomial:");
x = [zeros(1,m) 1];
disp("x^m polynomial=");
disp(x);
A = conv(x,d);
disp("multiplication=");
disp(A);
A1 = fliplr(A);
g1 = fliplr(g);
[q,r] = deconv(A1,g1);
disp("remainder=");
disp(r);
r1 = abs(r);
disp("absolute value of remainder=");
disp(r1);
r2 = rem(r1,2);
disp("remainder=");
disp(r2);
r3= fliplr(r2);
disp("flipped remainder=");
disp(r3);
B= xor(A,r3);
disp("encoded sequence");
disp(B);
%Decoding
R = input("Enter receieved codeword=");
I = eye(n);
disp('identity matrix');
disp(I);
R1 = fliplr(R);
[u,v] = deconv(R1,g1);
R2 = abs(v);
R3 = rem(R2,2);
disp("syndrome for received codeword=");
disp(R3);
disp("syndrome table=");
for(i = 1:n)
e1 = I(i,:);
e2 = fliplr(e1);
[y,z] = deconv(e2,g1);
z1 = abs(z);
z2 = rem(z1,2);
disp(z2);
if(R3 == z2)
e3 = fliplr(e2);
j=i;
end
end
disp("error in bit=");
disp(j);
w = xor(e3,R);
disp("corrected codeword=");
disp(w);

Output:

Enter the number of bits k:4


Enter the data bits[1 0 0 1]
Enter the code length n:7
m=
3

enter coefficients of generator polynomial:[1 0 1 1]


x^m polynomial=
0 0 0 1

multiplication=
0 0 0 1 0 0 1

remainder=
0 0 0 0 2 -1 1

absolute value of remainder=


0 0 0 0 2 1 1
remainder=
0 0 0 0 0 1 1

flipped remainder=
1 1 0 0 0 0 0

encoded sequence
1 1 0 1 0 0 1

Enter receieved codeword=[1 0 0 1 1 0 0]


identity matrix
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1

syndrome for received codeword=


0 0 0 0 0 1 1

syndrome table=
0 0 0 0 0 0 1

0 0 0 0 0 1 0

0 0 0 0 1 0 0

0 0 0 0 1 0 1

0 0 0 0 1 1 1

0 0 0 0 0 1 1

0 0 0 0 1 1 0

error in bit=
6

corrected codeword=
1 0 0 1 1 1 0

You might also like