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

OUTPUT in MATLAB Command Window

crc matlab

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)

Useful Links to MATLAB codes

Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation  Time off estimation corr  Freq off estimation corr  channel estimation  11a WLAN channel  PN sequence generation  OFDMA Tx Rx  AES DES  carrier aggregation  CCDF  FIR Filter  IIR Filter  Low Pass FIR  Viterbi decoder  CRC8 CRC32 

RF and Wireless tutorials

WLAN  802.11ac  802.11ad  wimax  Zigbee  z-wave  GSM  LTE  UMTS  Bluetooth  UWB  IoT  satellite  Antenna  RADAR