Last active
April 17, 2019 16:24
-
-
Save satlavida/b5a2bf2d8587faf37c3125ee1c1c2046 to your computer and use it in GitHub Desktop.
Cyclic Encoding using Shift Registers
This file contains hidden or 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-k'); | |
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:k | |
%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)*S(1), SP(j-1)); | |
end | |
%disp(S); | |
SP = S; | |
end | |
encoded = [msg, fliplr(S)]; | |
sprintf('Encoded message using hardware is') | |
disp(encoded); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment