Created
April 17, 2019 16:23
-
-
Save satlavida/119bb466ee7bc515591330625eaeb9ce to your computer and use it in GitHub Desktop.
Syndrome Generator for cyclic codes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc; | |
close all; | |
clear; | |
n = input('Enter n for cyclic code'); | |
k = input('Enter k for cyclic code'); | |
msg = input('Enter message bits of the length n'); | |
N = n-k; %No of shift register% | |
poly = cyclpoly(n,k,'max'); | |
S = zeros(1,N); | |
SP = S; %Previous state of shift register% | |
g = zeros(1,N-1); | |
for i = 2:N | |
g(i-1) = poly(i); | |
end | |
disp(S); | |
for i=1:n | |
%disp(S); | |
% sprintf('%d + %d %d', S(N), msg(i), i) | |
S(1) = xor(S(N),msg(i)); | |
for j = 2:N | |
%sprintf('%d + %d %d', g(N-j+1)*S(1), SP(j-1), j) | |
S(j) = xor(g(N-j+1)*SP(N), SP(j-1)); | |
end | |
%disp(S); | |
SP = S; | |
end | |
sprintf('Syndrome = ') | |
disp(fliplr(S)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment