Matlab CRC generator calculate CRC code different from online calculator

13 ビュー (過去 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 Center および File ExchangeAudio 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