Matlab CRC generator calculate CRC code different from online calculator
6 views (last 30 days)
Show older comments
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 Comments
Alexandros Kessanopoulos
on 10 Oct 2019
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
on 31 Aug 2023
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").
Answers (1)
Alex L
on 22 Aug 2023
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.
0 Comments
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!