Skip to content

Instantly share code, notes, and snippets.

@korniltsev
Created December 4, 2012 10:17
Show Gist options
  • Save korniltsev/4202436 to your computer and use it in GitHub Desktop.
Save korniltsev/4202436 to your computer and use it in GitHub Desktop.
inf. sec. 04
function [ out ] = berlekamp_massey( )
z=[ 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 0 1 1 1 1 1];
n = length(z);
c = zeros(1,n);
b= zeros(1,n);
c(1) = 1;
b(1) = 1;
for r=1:n
d = 0;
for j = 0:r - 1
d= xor(d, z(r-j)*c(j+1));
end
if (d ~= 0)
t = xor(c , [0 b(1:length(b)-1)]);
b = c;
c = t;
else
% b(x) = xb(x)
b = [0 b(1:length(b)-1)];%circshift(b, [0 1]);
end
end
log_polynom(c);
out = find(c, 1, 'last' ) - 1;
end
function []= log_polynom( poly )
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
str = '';
first = true;
for i=1:length(poly)
if (poly(i) == 1)
if (first)
first = false;
else
str = [str ' + '];
end
if (i)==1
str = [str '1'];
else
str = [str , 'x'];
if (i-1 ~= 1)
str = [str,'^', char(int2str(i-1))];
end
end
end
end
str
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment