-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgenerate_and_append_crc_bits.m
42 lines (38 loc) · 1.52 KB
/
generate_and_append_crc_bits.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
42
function b = generate_and_append_crc_bits(a, G_max)
% GENERATE_AND_APPEND_CRC_BITS generates and appends Cyclic Redudancy Check
% (CRC) bits to an information bit sequence.
% b = GENERATE_AND_APPEND_CRC_BITS(a, G_max) uses a specified generator
% matrix to generate CRC bits for an information bit sequence and appends
% them.
%
% a should be a row vector comprising A information bits.
%
% G_max should be a binary generator matrix for the CRC. The number of
% rows in G_max should be at least A, while the number of columns in
% G_max should equal the number of CRC bits to be generated.
%
% b will be a row vector comprising B=A+L bits, formed by appending the
% sequence of L CRC bits onto the end of the sequence of A information
% bits.
%
% 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.
A = length(a);
L = size(G_max,2);
B = A+L;
% Calculate the CRC bits
p = calculate_crc_bits(a,G_max);
% Implemented according to Section 5.1.1 of TS36.212
b = zeros(1,B);
for k = 0:A-1
b(k+1) = a(k+1);
end
for k=A:A+L-1
b(k+1) = p(k-A+1);
end