Matlab CRC generator calculate CRC code different from online calculator

14 次查看(过去 30 天)
Hi,
I basically copied an example code to generate CRC-16 bits. But comparing to an online CRC calculator, the results are always different. I trust the online calculator, because my SW colleagues were using their C-language library and generate the same bits as from the online calculator (<http://www.sunshine2k.de/coding/javascript/crc/crc_js.html)>. Could someone help me on this issue?
For string msg = '123456789', the matlab code generates '0xA0C4' , but the online calculator '0xB4C8', while both methods use all the same parameter settings.
The matlab code I used:
% 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', 'InitialState', '0xFFFF', ...
'ReflectInput', true, 'ReflectRemainder', true, 'FinalXOR', '0xFFFF' );
% The message below is an ASCII representation of ...
% the digits 1-9
msg = reshape(de2bi(49:57, 8, 'left-msb')',72, 1);
encoded = generate(gen, msg);
crc16code = encoded(end-15:end,1)';
bin2hex(num2str(crc16code))
  2 个评论
Alexandros Kessanopoulos
I have also noticed that. Do you have any answer?
The following code gives 0x19cf where the online calculator gives 0xe5cc
h = crc.generator('Polynomial', '0x1021', 'InitialState', '0x1d0f');
msg = reshape(de2bi(49:57, 8, 'left-msb')', 72, 1);
encoded = generate(h,msg); dec2hex(bi2de(fliplr(encoded(end-15:end).')))
while the following gives 0xE5CC
h = crc.generator('Polynomial', '0x1021', 'InitialState', '0xffff')
encoded = generate(h,msg); dec2hex(bi2de(fliplr(encoded(end-15:end).')))
encoded = generate(h,msg); dec2hex(bi2de(fliplr(encoded(end-15:end).')))
Jakub Streit
Jakub Streit 2023-8-31
I have the same problem using comm.CRCGenerator (crc.generator is now deprecated - see https://uk.mathworks.com/help/comm/ref/crc.generator.html ).
Tested against online calculator https://crccalc.com/ with data unicode2native("123456789", "UTF-8").

请先登录,再进行评论。

回答(1 个)

Alex L
Alex L 2023-8-22
I have the same problem, the online calculator actually gave polynomial, initial state, finalxor and reflections the same as yours. Even with the same setting the results are different from the online calculator...
Wondering if anyone has solved the problem.

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by