Matlab CRC generator calculate CRC code different from online calculator

조회 수: 6 (최근 30일)
BIN LI
BIN LI 2018년 6월 22일
댓글: Jakub Streit 2023년 8월 31일
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
Alexandros Kessanopoulos 2019년 10월 10일
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