CRC matlab

Polynomial : 多项式

InitialState:初始化状态。移位寄存器的初始内容。 可以将此属性指定为二进制标量,二进制向量或以’0x’开头的字符串,该字符串是二进制向量的十六进制表示形式。 作为二进制矢量,其长度必须比多项式的二进制矢量表示的长度小一。

ReflectInput:输入。一个布尔量,指定在进入移位寄存器之前是否应按字节对输入数据进行翻转。

ReflectRemainder: 一个布尔量,指定在输入数据完全通过移位寄存器后,是否应将二进制输出CRC校验和绕其中心翻转。

c r c . generator的理解:
Usage Example:

% Construct a CRC generator with a polynomial defined
% by x^4+x^3+x^2+x+1:
h = crc.generator([1 1 1 1 1]) 

% Construct a CRC generator with a polynomial defined
% by x^4+x^3+x^2+x+1, all-ones initial states, reflected
% input, and all-zeros final XOR value:
h = crc.generator('Polynomial', '0xF', 'InitialState', ...
'0xF', 'ReflectInput', true, 'FinalXOR', '0x0')

% Create a CRC-16 CRC generator, then use it to generate
% a checksum for the
% binary vector represented by the ASCII sequence '123456789'.
gen = crc.generator('Polynomial', '0x8005', ...
'ReflectInput', true, 'ReflectRemainder', true);
% The message below is an ASCII representation of ...
% the digits 1-9
msg = reshape(de2bi(49:57, 8, 'left-msb')', 72, 1);   % 将49:57这些数字转换为8行的2禁止数据,左位为最高位。然后再把数组变为9*8的 72行 1列数据

encoded = generate(gen, msg);

% Construct a CRC generator with a polynomial defined
% by x^3+x+1, with zero initial states,
% and with an all-ones final XOR value:
h = crc.generator('Polynomial', [1 0 1 1], ...
                   'InitialState', [0 0 0], ...
                   'FinalXOR', [1 1 1])

函数:de2bi( 把一个十进制数转换成一个字符串形式的二进制数)
具体参看 CRC在matlab中运用 篇博客

猜你喜欢

转载自blog.csdn.net/qq_42580533/article/details/106842363
CRC