0% found this document useful (0 votes)
10 views2 pages

Exp) 10

The document is a MATLAB script for simulating cyclic code encoding and decoding. It includes steps for inputting message parameters, performing polynomial division for encoding, calculating error detection and correction capacities, and decoding received code with error correction. The script also provides a look-up table for syndrome to identify and correct errors in the received codeword.

Uploaded by

RAHUL PILLI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Exp) 10

The document is a MATLAB script for simulating cyclic code encoding and decoding. It includes steps for inputting message parameters, performing polynomial division for encoding, calculating error detection and correction capacities, and decoding received code with error correction. The script also provides a look-up table for syndrome to identify and correct errors in the received codeword.

Uploaded by

RAHUL PILLI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

10/14/24 5:08 PM C:\Users\Student\Documents\...\experi10.

m 1 of 2

%Exp Name- Simulation : Study of Cyclic Code


%Name:Muskan Shaikh
%Batch:B2
%Roll no:345
clc;
clear all;
close all;

disp('--- Cyclic Code Encoding and Decoding ---')

% Step 1: Input Parameters


k = input('Number of message bits k = ');
n = input('Number of codeword length n = ');
q = n - k;
disp(['Number of check bits q = ', num2str(q)]);

% Step 2: Input Message Vector


m = input('Enter message vector to be encoded (only coefficients) m = ');
c = zeros(1, n);
for i = 1:k % Appends q number of zeros
c(1, i) = m(1, i);
end
disp('X^q.M(x) = '), disp(c);

% Step 3: Input Message Polynomial and Generator Polynomial


Mp = input('Enter message poly corresponding to X^q.M(x) Mp (e.g. [1 0 1 0 0 0]): ');
Gp = input('Enter generator polynomial Gp (e.g. [1 0 1 1]): ');

% Step 4: Perform Polynomial Division for Encoding


[r1, q1] = deconv(Mp, Gp); % Polynomial division
r1 = mod(r1, 2); % Convert remainder to binary (mod 2)
disp('Remainder of division = '), disp(r1);

% Step 5: Ensure sizes match by padding r1 with zeros if needed


r1 = [zeros(1, length(Mp) - length(r1)), r1]; % Pad remainder to match message length

% Step 6: Compute the Codeword


code = mod(Mp + r1, 2); % Adding remainder to original polynomial
disp('The codeword is: '), disp(code);

% Step 7: Calculate Error Detection/Correction Capacity


dmin = input('Enter minimum Hamming distance dmin = ');
td = dmin - 1; % Error detection capacity
tc = floor((dmin - 1) / 2); % Error correction capacity
disp(['Minimum Hamming distance: dmin = ', num2str(dmin)]);
disp(['Error detection capacity: td = ', num2str(td)]);
disp(['Error correction capacity: tc = ', num2str(tc)]);

% Step 8: Decoding Process


Rp = input('Enter received code polynomial (with one bit error) Rp (e.g. [1 0 1 1 1 0
1]): ');
10/14/24 5:08 PM C:\Users\Student\Documents\...\experi10.m 2 of 2

[r2, q2] = deconv(Rp, Gp); % Polynomial division for decoding


r2 = mod(r2, 2); % Convert remainder to binary (syndrome)
syndrome = r2;
disp('Calculated syndrome is: s = '), disp(syndrome);

% Step 9: Look Up Table (Syndrome Table) for Error Correction


disp('Look Up Table (Syndrome Table)::');
disp('Error Vector(e) | Syndrome(s)');

a = zeros(n, n); % Error vector


for i = 1:n
a(i, n - i + 1) = 1; % Generate one-bit error pattern
end

num = -1; % Initialize error location variable

for i = 1:n
ep = a(i, :); % Error pattern
[s, q1] = deconv(ep, Gp); % Compute syndrome for error pattern
s = mod(s, 2);
disp(['Error vector: ', num2str(a(i, :)), ' | Syndrome: ', num2str(s)]);
if isequal(s, syndrome) % If the syndrome matches, locate the error
num = i;
break; % Exit loop when error is found
end
end

% If no error was found, handle accordingly


if num == -1
disp('No error detected');
else
disp(['The error is present at bit number: ', num2str(n - num + 1)]);

% Step 10: Correct the Error


Rpp = Rp; % Received polynomial as a vector
c = mod(Rpp + a(num, :), 2); % XOR to correct the error
disp('Corrected Codeword is: '), disp(c);
end

You might also like