MATLAB: getting the reminder of polynomial division

Thread Starter

walid el masry

Joined Mar 31, 2009
133
"Header Check Sequence
An 8-bit field used to detect errors in the header.The transmitter shall calculate the HCS value for the first five bytes of the cell header, and insert the result into the HCS field (the last byte of the MAC header). It shall be the reminder of the division (Modulo 2) by the generator polynomial D^8 + D^2 + D + 1 of the polynomial D^8 multiplied by the content of the header excluding the HCS field."

how to do that in matlab ?
 
Last edited:

Thread Starter

walid el masry

Joined Mar 31, 2009
133
thnx for all who tried to help me, the solution is

Rich (BB code):
% get the remoner of division of the input by genpol polynomials
function rem = binary_rem(input, genpol)
%input = [0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 ];
%genpol= [1 0 0 0 0 0 1 1 1];
input = [input zeros(1,length(genpol)-1) 0];
temp=input(1:length(genpol));
for i=1:length(input)-length(genpol);
    if temp(1) == 1;
        q(i) = 1;
        output = xor(temp,genpol);
    else
        q(i) = 0;
        %output = xor(temp,not(genpol));
        output = temp;
    end
    temp = [output(2:end) input(length(genpol)+i)];
end

rem = temp(1:end-1);
end
 
Top