forked from robmaunder/turbo-3gpp-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstituent_encoder.m
76 lines (63 loc) · 2.29 KB
/
constituent_encoder.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function [z, x] = constituent_encoder(c)
% CONSTITUENT_ENCODER encodes a code block using a terminated unity-rate
% recursive convolutional code having 3 memory elements, a generator
% polynomial of [1,1,0,1] and a feedback polynomial of [1,0,1,1], as
% specified in Section 5.1.3.2.1 and 5.1.3.2.2 of TS36.212.
% [z, x] = CONSTITUENT_ENCODER(c) encodes a code block, in order to
% obtain a sequence of systematic and termination bits, as well as a
% sequence of encoded bits.
%
% c should be a row vector, comprising the K bits of a code block.
%
% z will be a row vector, comprising K+3 encoded bits.
%
% x will be a row vector, comprising K systematic bits, appended with 3
% termination 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.
K = length(c);
% Initialise our output bit vectors
z = zeros(1,K+3);
x = zeros(1,K+3);
% We start in the all-zeros state
s1 = 0;
s2 = 0;
s3 = 0;
% Encode the uncoded bit sequence
for k = 0:K-1
% Determine the next state
s1_plus = mod(c(k+1)+s2+s3, 2); % This uses the feedback polynomial
s2_plus = s1;
s3_plus = s2;
% Determine the systematic bit
x(k+1) = c(k+1);
% Determine the encoded bit
z(k+1) = mod(s1_plus+s1+s3, 2); % This uses the generator polynomial
% Enter the next state
s1 = s1_plus;
s2 = s2_plus;
s3 = s3_plus;
end
% Terminate the convolutional code
for k = K:K+2
% Determine the next state
s1_plus = 0; % During termination, zeros are clocked into the shift register
s2_plus = s1;
s3_plus = s2;
% Determine the termination bit
x(k+1) = mod(s2+s3, 2); % This uses the feedback polynomial
% Determine the encoded bit
z(k+1) = mod(s1_plus+s1+s3, 2); % This uses the generator polynomial
% Enter the next state
s1 = s1_plus;
s2 = s2_plus;
s3 = s3_plus;
end
end