以MATLAB的CRC函数为标准,进行校验的脚本如下:
clc;
clear;
crc_Poly = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1]; %%%% x^16+x^15+x^2+1
crc_g = crc.generator('Polynomial',crc_Poly); %%%
crc_g.InitialState = zeros(1,16); %%% InitialState
crc_g.FinalXOR = zeros(1,16); %%%'FinalXOR
crc_g.ReflectInput = false; %%%% 高位在前
crc_g.ReflectRemainder =false; %%%% 高位在前
M = 32;
crc_din_hex = "ABCD0001";
crc_din_bin = bin2dec(dec2bin(hex2dec(crc_din_hex),M).');
crc_dout_mat = generate(crc_g,crc_din_bin);
crc_dout_direct = CRC_direct(crc_Poly,crc_din_bin,crc_g.InitialState,crc_g.FinalXOR);
figure(1);
plot(crc_dout_direct - crc_dout_mat);
crc_dout_direct_LFSR = CRC_direct_LFSR(crc_Poly,crc_din_bin,crc_g.InitialState,crc_g.FinalXOR);
figure(2);
plot(crc_dout_direct_LFSR - crc_dout_mat);
crc_dout_direct_LFSR_Hex = dec2hex(sum(crc_dout_direct_LFSR.'.*2.^(M+15:-1:0