-
Notifications
You must be signed in to change notification settings - Fork 26
/
get_3gpp_crc_polynomial.m
41 lines (39 loc) · 1.77 KB
/
get_3gpp_crc_polynomial.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function crc_polynomial = get_3gpp_crc_polynomial(CRC)
% GET_3GPP_CRC_POLYNOMIAL Obtain a Cyclic Redudancy Check (CRC) generator
% polynomial as a binary vector.
% crc_polynomial = GET_3GPP_CRC_POLYNOMIAL(CRC) obtains a CRC
% generator polynomial, as specified in Section 5.1.1 of TS36.212.
%
% CRC should be a string selected from the set 'CRC24A', 'CRC24B',
% 'CRC16' and 'CRC8'.
%
% crc_polynomial will be a binary row vector comprising P+1
% number of bits, each having the value 0 or 1. These bits parameterise a
% Cyclic Redundancy Check (CRC) comprising P bits. Each bit provides the
% coefficient of the corresponding element in the CRC generator
% polynomial. From left to right, the bits provide the coefficients for
% the elements D^P, D^P-1, D^P-2, ..., D^2, D, 1.
%
% Copyright © 2018 Robert G. Maunder. This program is free software: you
% can redistribute it and/or modify it under the terms of the GNU General
% Public License as published by the Free Software Foundation, either
% version 3 of the License, or (at your option) any later version. This
% program is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
% more details.
% CRC exponents, as specified in Section 5.1.1 of TS36.212
if strcmp(CRC, 'CRC24A')
exponents = [24,23,18,17,14,11,10,7,6,5,4,3,1,0];
elseif strcmp(CRC, 'CRC24B')
exponents = [24,23,6,5,1,0];
elseif strcmp(CRC, 'CRC16')
exponents = [16,12,5,0];
elseif strcmp(CRC, 'CRC8')
exponents = [8,7,4,3,1,0];
else
error('CRC is unsupported');
end
crc_polynomial = zeros(1,max(exponents)+1);
crc_polynomial(exponents+1) = 1;
crc_polynomial = fliplr(crc_polynomial);