RF Wireless World

Home of RF and Wireless Vendors and Resources

One Stop For Your RF and Wireless Need

CRC MATLAB source code

This section of CRC MATLAB source codes which covers CRC8 and CRC32 matlab codes.

Various polynomial based CRC techniques are used for error detection. It means it detects whether any errors have been occurred or not in the received packet from distant end. It can be used in wired as well as wireless transmission systems. In such circumstances when error is detected, retransmission is initiated. For detail refer our page on CRC in the terminology section.

CRC8 MATLAB Code

Following code is CRC matlab code for CRC8 polynomials used widely in ethernet and wireless standards(wimax,wlan etc).

Input = [0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0, ...
0,1,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0, ...
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; % Input values.
M1=Input; G1 = [1,0,0,0,0,0,1,1,1];
mL = length(M1);
gL = length(G1);
count = 0;
while((mL-count) >= gL)
msg9 = M1(1:gL);
rem = mod((msg9 + G1),2)
M1(1:gL) = rem;
j=1;
shft = 0;
while(j<=gL)
if(rem(j)~=0)
break;
else shft = j;
j = j + 1;
end
end
count = count + shft;
M1(1:shft) = [];
end
j = 0;
value = 0;
chksuml = length(M1);
for j = 1:chksuml % convert binary to decimal
if(M1(j) == 1)
value = value + (2^(chksuml-j));
end
end
dec2hex(value)
% decimal to hex CRC8 output

CRC MATLAB Code for CRC32

Following code is CRC matlab code for CRC32 polynomials.

function Output = CRC_gen(Input) GenPoly = [1 1 1 0 1 1 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0];
%G(x)=x32+x26+x23+x22+x16+x12+ x11+ x10+ x8+ x7+ x5+ x4+ x2+x+1
BufferInit = ones(1,32);
Input = [ Input zeros(1,32)];
for i = 1:length(Input)
temp1 = BufferInit(end);
temp2 = temp1*GenPoly;
for j = length(BufferInit):-1:2
BufferInit(j) = xor(temp2(j), BufferInit(j-1));
end
BufferInit(1) = xor(Input(i), temp2(1));
end
Output = fliplr(BufferInit)