source: ResearchApps/PHY/MIMO_OFDM/calcCRC32.m

Last change on this file was 1715, checked in by murphpo, 12 years ago

cleaning up PHY directory; coded PHY is now primary OFDM_MIMO model

File size: 1.2 KB
Line 
1function crcOut = calcCRC32(thePacketBytes)
2%Based on the C code example at:
3%http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
4%Uses slightly modified version of CRC-32:
5% No output XOR
6% No bit-order swapping on message or digest bytes
7
8CRCPolynomial = hex2dec('04c11db7');
9CRC_Table = CRC_table_gen(CRCPolynomial, 32);
10
11init_crc = hex2dec('ffffffff');
12myData = thePacketBytes;
13%de2bi(49,'left-msb',8))
14crc_accum = init_crc;
15for n=1:length(myData)
16    x = bitshift(crc_accum,-24,32);
17%CRC32 would swap bit order here:
18%   x = bitxor(x, bi2de( de2bi(myData(n),'left-msb',8)));
19    x = bitxor(x, myData(n));
20    x = bitand(x,hex2dec('ff'));
21    crc_accum = bitxor(bitshift(crc_accum,8,32),CRC_Table(x+1));
22    crc_tracking(n) = crc_accum;
23end
24
25CRC32 = crc_accum;
26%CRC32 would XOR with all ones, then reorder bits here:
27%CRC32 = bitxor(CRC32, hex2dec('ffffffff'));
28%CRC32 = bi2de(de2bi(CRC32,'left-msb',32));
29
30CRC32_b3 = bitand(bitshift(CRC32,-24,32),hex2dec('ff'));
31CRC32_b2 = bitand(bitshift(CRC32,-16,32),hex2dec('ff'));
32CRC32_b1 = bitand(bitshift(CRC32,-8,32),hex2dec('ff'));
33CRC32_b0 = bitand(CRC32,hex2dec('ff'));
34
35crcOut = [CRC32_b3 CRC32_b2 CRC32_b1 CRC32_b0];
Note: See TracBrowser for help on using the repository browser.