Monday, October 19, 2009
Matlab: Calculating Syndrome of Cyclic Code (15,7)
It is a matlab script to calculate syndrome of a (15,7) cyclic code.
%for cyclic code (15,7)
%Given g(X)=1+X^4+X^6+X^7+X^8
%Design a syndrome computation circuit and calculate the syndrome if input, Z=1+X^12+X^14
clc
clear all;
close all;
z=[1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 ]; %input vector=1+X^12+X^14
z_flp= fliplr(z); %reverse the sequence because MSB is first shifted in
x=zeros(1,8); %initialized shift register to zero
x_prev = zeros(1,8); %initialized virtual previous shift register to zero
for i=1: length(z)
%store all previous value
x_prev(1)=x(1);
x_prev(2)=x(2);
x_prev(3)=x(3);
x_prev(4)=x(4);
x_prev(5)=x(5);
x_prev(6)=x(6);
x_prev(7)=x(7);
x_prev(8)=x(8);
%decoder connection
x(1) = xor(x_prev(8),z_flp(i));
x(2) = x_prev(1);
x(3) = x_prev(2);
x(4) = x_prev(3);
x(5) = xor(x_prev(4),x_prev(8));
x(6) = x_prev(5);
x(7) = xor(x_prev(6),x_prev(8));
x(8) = xor(x_prev(7),x_prev(8));
%storing values
x_store(i+1,:)=[x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8)];
shift_number(i+1,:)=i;
z_input(i+1)=z_flp(i);
end
%display nicely
for i=1: (length(z)+1) %plus 1 to include initial state
disp(sprintf('Shift number = %d\tRegister-->%d%d%d%d%d%d%d%d,\tinput=%d',shift_number(i),x_store(i,:),z_input(i)))
end
--------------------------------------------------------------------------------------
Calculating Syndrome Value:
Shift number = 0 Register-->00000000, input=0
Shift number = 1 Register-->10000000, input=1
Shift number = 2 Register-->01000000, input=0
Shift number = 3 Register-->10100000, input=1
Shift number = 4 Register-->01010000, input=0
Shift number = 5 Register-->00101000, input=0
Shift number = 6 Register-->00010100, input=0
Shift number = 7 Register-->00001010, input=0
Shift number = 8 Register-->00000101, input=0
Shift number = 9 Register-->10001001, input=0
Shift number = 10 Register-->11001111, input=0
Shift number = 11 Register-->11101100, input=0
Shift number = 12 Register-->01110110, input=0
Shift number = 13 Register-->00111011, input=0
Shift number = 14 Register-->10010110, input=0
Shift number = 15 Register-->11001011, input=1
Other cyclic code: generator-syndromer-for-15-7-cyclic-code
Subscribe to:
Post Comments (Atom)
1 comment:
Post a Comment