source: ResearchApps/PHY/MIMO_OFDM/calcCRC16.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: 800 bytes
Line 
1function crcOut = calcCRC16(thePacketBytes)
2%Based on the C code example at:
3%http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
4%Uses CRC-CCIT standard checksum polynomial/formatting
5
6CRCPolynomial = hex2dec('1021');
7CRC_Table = CRC_table_gen(CRCPolynomial, 16);
8
9%init_crc = hex2dec('FFFF');
10init_crc = 0;
11myData = thePacketBytes;
12
13crc_accum = init_crc;
14for n=1:length(myData)
15    x = bitshift(crc_accum,-8,16);
16    x = bitxor(x, myData(n));
17    x = bitand(x,hex2dec('ff'));
18    crc_accum = bitxor(bitshift(crc_accum,8,16),CRC_Table(x+1));
19    crc_tracking(n) = crc_accum;
20end
21
22TxCRC16 = bitand(crc_accum, hex2dec('ffff'));
23
24TxCRC16_b1 = bitand(bitshift(TxCRC16,-8,32),hex2dec('ff'));
25TxCRC16_b0 = bitand(TxCRC16,hex2dec('ff'));
26
27crcOut = [TxCRC16_b1 TxCRC16_b0];
Note: See TracBrowser for help on using the repository browser.