Skip to content

Commit ae3e275

Browse files
committed
Implemented CRC initialised to with all ones for PDCCH.
1 parent 481cf1d commit ae3e275

11 files changed

Lines changed: 167 additions & 17 deletions

PDCCH_decoder.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@
8484
info_bit_pattern = get_3GPP_info_bit_pattern(K, Q_N, rate_matching_pattern, mode);
8585

8686
% Perform Distributed-CRC-Aided polar decoding.
87-
a_hat = DSCA_polar_decoder(f_tilde,crc_polynomial_pattern,RNTI,crc_interleaver_pattern,info_bit_pattern,rate_matching_pattern,mode,L,min_sum,P2);
87+
a_hat = DS1CA_polar_decoder(f_tilde,crc_polynomial_pattern,RNTI,crc_interleaver_pattern,info_bit_pattern,rate_matching_pattern,mode,L,min_sum,P2);

PDCCH_encoder.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
info_bit_pattern = get_3GPP_info_bit_pattern(K, Q_N, rate_matching_pattern, mode);
6767

6868
% Perform Distributed-CRC-Aided polar encoding.
69-
f = DSCA_polar_encoder(a,crc_polynomial_pattern, RNTI, crc_interleaver_pattern,info_bit_pattern,rate_matching_pattern);
69+
f = DS1CA_polar_encoder(a,crc_polynomial_pattern, RNTI, crc_interleaver_pattern,info_bit_pattern,rate_matching_pattern);
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function a_hat = DSCA_polar_decoder(e_tilde, crc_polynomial_pattern, crc_scrambling_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern, mode, L, min_sum, P2)
2-
% DSCA_POLAR_DECODER Distributed-and-Scrambled-CRC-Aided (DSCA) polar decoder.
3-
% a_hat = DSCA_POLAR_DECODER(e_tilde, crc_polynomial_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern, mode, L, min_sum, P2)
1+
function a_hat = DS1CA_polar_decoder(e_tilde, crc_polynomial_pattern, crc_scrambling_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern, mode, L, min_sum, P2)
2+
% DS1CA_POLAR_DECODER Distributed-Scrambled-and-1-initialised-CRC-Aided (DS1CA) polar decoder.
3+
% a_hat = DS1CA_POLAR_DECODER(e_tilde, crc_polynomial_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern, mode, L, min_sum, P2)
44
% decodes the encoded LLR sequence e_tilde, in order to obtain the
55
% recovered information bit sequence a_hat.
66
%
@@ -66,7 +66,7 @@
6666
% each having the value 0 or 1. However, in cases where the CRC check
6767
% fails, a_hat will be an empty vector.
6868
%
69-
% See also DSCA_POLAR_ENCODER
69+
% See also DS1CA_POLAR_ENCODER
7070
%
7171
% Copyright © 2017 Robert G. Maunder. This program is free software: you
7272
% can redistribute it and/or modify it under the terms of the GNU General
@@ -211,8 +211,13 @@
211211

212212
% We use the interleaved CRC generator matrix to update the CRC
213213
% check sums whenever an information or CRC bit adopts a value of
214-
% 1.
215-
crc_checksums = cat(3,crc_checksums,mod(crc_checksums+repmat(G_P3(i2,:)',[1 1 L_prime]),2));
214+
% 1. We need to toggle the first P information bits to model a CRC
215+
% that is initialised with all ones.
216+
if crc_interleaver_pattern(i2) <= P
217+
crc_checksums = cat(3,mod(crc_checksums+repmat(G_P3(i2,:)',[1 1 L_prime]),2),crc_checksums);
218+
else
219+
crc_checksums = cat(3,crc_checksums,mod(crc_checksums+repmat(G_P3(i2,:)',[1 1 L_prime]),2));
220+
end
216221
% We need to keep track of whether any of the checks associated
217222
% with the previous CRC bits have failed.
218223
crc_okay = cat(3,crc_okay,crc_okay);
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function e = DSCA_polar_encoder(a, crc_polynomial_pattern, crc_scrambling_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern)
2-
% DSCA_POLAR_ENCODER Distributed-and-Scrambled-CRC-Aided (DSCA) polar encoder.
3-
% e = CA_POLAR_ENCODER(a, crc_polynomial_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern)
1+
function e = DS1CA_polar_encoder(a, crc_polynomial_pattern, crc_scrambling_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern)
2+
% DS1CA_POLAR_ENCODER Distributed-Scrambled-and-1-initialised-CRC-Aided (DS1CA) polar encoder.
3+
% e = DS1CA_POLAR_ENCODER(a, crc_polynomial_pattern, crc_interleaver_pattern, info_bit_pattern, rate_matching_pattern)
44
% encodes the information bit sequence a, in order to obtain the encoded
55
% bit sequence e.
66
%
@@ -38,7 +38,7 @@
3838
% e will be a binary row vector comprising E number of bits, each having
3939
% the value 0 or 1.
4040
%
41-
% See also DSCA_POLAR_DECODER
41+
% See also DS1CA_POLAR_DECODER
4242
%
4343
% Copyright © 2017 Robert G. Maunder. This program is free software: you
4444
% can redistribute it and/or modify it under the terms of the GNU General
@@ -72,7 +72,16 @@
7272

7373
% Generate the CRC bits.
7474
G_P = get_crc_generator_matrix(A,crc_polynomial_pattern);
75-
crc_bits = mod(a*G_P,2);
75+
a2 = a;
76+
a2((1:A)<=P) = ~a2((1:A)<=P); % Toggle the first P bits to model a CRC that is initialised with all ones
77+
crc_bits = mod(a2*G_P,2);
78+
crc_bits((A+1:A+P) <= P) = ~crc_bits((A+1:A+P) <= P);
79+
80+
crc_bits2 = calculate_crc_ones(a,crc_polynomial_pattern);
81+
82+
if ~isequal(crc_bits,crc_bits2)
83+
error('Rob');
84+
end
7685

7786
% Scramble the CRC bits.
7887
scrambled_crc_bits = xor(crc_bits,[zeros(1,P-length(crc_scrambling_pattern)),crc_scrambling_pattern]);

components/calculate_crc.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
for bit_index = 1:length(bits)
66
crc = xor(xor(crc(1),bits(bit_index))*crc_polynomial_pattern(2:end),[crc(2:end),0]);
7-
87
end

components/calculate_crc_ones.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function crc = calculate_crc_ones(bits, crc_polynomial_pattern)
2+
3+
crc = ones(1,length(crc_polynomial_pattern)-1);
4+
5+
for bit_index = 1:length(bits)
6+
crc = xor(xor(crc(1),bits(bit_index))*crc_polynomial_pattern(2:end),[crc(2:end),0]);
7+
8+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function G_P = get_crc_generator_matrix_ones(A, crc_polynomial_pattern)
2+
% GET_CRC_GENERATOR_MATRIX Obtain a Cyclic Redudancy Check (CRC) generator
3+
% matrix.
4+
% G_P = GET_CRC_GENERATOR_MATRIX(A, crc_polynomial_pattern) obtains the CRC
5+
% generator matrix G.
6+
%
7+
% A should be an integer scalar. It specifies the number of bits in the
8+
% information bit sequence.
9+
%
10+
% crc_polynomial_pattern should be a binary row vector comprising P+1
11+
% number of bits, each having the value 0 or 1. These bits parameterise a
12+
% Cyclic Redundancy Check (CRC) comprising P bits. Each bit provides the
13+
% coefficient of the corresponding element in the CRC generator
14+
% polynomial. From left to right, the bits provide the coefficients for
15+
% the elements D^P, D^P-1, D^P-2, ..., D^2, D, 1.
16+
%
17+
% G_P will be a K by P binary matrix. The CRC bits can be generated
18+
% according to mod(a*G_P,2).
19+
%
20+
% Copyright © 2017 Robert G. Maunder. This program is free software: you
21+
% can redistribute it and/or modify it under the terms of the GNU General
22+
% Public License as published by the Free Software Foundation, either
23+
% version 3 of the License, or (at your option) any later version. This
24+
% program is distributed in the hope that it will be useful, but WITHOUT
25+
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26+
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
27+
% more details.
28+
29+
30+
P = length(crc_polynomial_pattern)-1;
31+
32+
if P<1
33+
error('crc_polynomial_pattern is invalid');
34+
end
35+
36+
G_P = zeros(A,P);
37+
38+
for k = 1:A
39+
G_P(k,:) = calculate_crc_ones(zeros(1,k), crc_polynomial_pattern);
40+
end
41+
42+

components/test_crc.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77
crc_generator_pattern(end) = 1;
88

99

10-
A = randi([0,2000]);
10+
A = randi([0,100]);
1111

1212
[P,A]
1313

1414
G_P = get_crc_generator_matrix(A, crc_generator_pattern);
1515

1616
a = round(rand([1,A]));
1717

18-
crc1 = mod(a*G_P,2);
19-
crc2 = calculate_crc(a,crc_generator_pattern);
18+
a2 = a;
19+
a2(1:A < P) = ~a2(1:A<P);
20+
21+
crc1 = mod(a2*G_P,2);
22+
crc1((A+1:A+P) < P) = ~crc1((A+1:A+P) < P);
23+
24+
crc2 = calculate_crc_ones(a,crc_generator_pattern);
2025

2126
if ~isequal(crc1,crc2)
2227
[crc1;crc2]

components/test_crc2.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
4+
while 1
5+
6+
P = randi([2,20]);
7+
8+
crc_generator_pattern = round(rand([1,P]));
9+
crc_generator_pattern(1) = 1;
10+
crc_generator_pattern(end) = 1;
11+
12+
13+
A = randi([20,100]);
14+
15+
[P,A]
16+
17+
18+
crc_ones = calculate_crc_ones(zeros(1,A),crc_generator_pattern);
19+
20+
diff = crc_ones;
21+
22+
23+
for rep = 1:100
24+
25+
a = round(rand([1,A]));
26+
27+
crc_zeros = calculate_crc(a,crc_generator_pattern);
28+
crc_ones = calculate_crc_ones(a,crc_generator_pattern);
29+
30+
31+
if ~isequal(diff, xor(crc_zeros,crc_ones))
32+
[crc1;crc2]
33+
error('Rob');
34+
end
35+
end
36+
end

components/test_crc3.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
A_max = 100;
2+
3+
4+
while 1
5+
6+
P = randi([2,20]);
7+
8+
crc_generator_pattern = round(rand([1,P]));
9+
crc_generator_pattern(1) = 1;
10+
crc_generator_pattern(end) = 1;
11+
12+
G_P2 = get_crc_generator_matrix_ones(A_max, crc_generator_pattern);
13+
14+
15+
A = randi([20,A_max]);
16+
17+
[P,A]
18+
19+
G_P = get_crc_generator_matrix(A, crc_generator_pattern);
20+
21+
a = round(rand([1,A]));
22+
23+
% crc1 = xor(mod(a*G_P,2),calculate_crc_ones(zeros(1,A),crc_generator_pattern));
24+
25+
crc1 = xor(mod(a*G_P,2),G_P2(A,:));
26+
crc2 = calculate_crc_ones(a,crc_generator_pattern);
27+
28+
if ~isequal(crc1,crc2)
29+
[crc1;crc2]
30+
error('Rob');
31+
end
32+
end

0 commit comments

Comments
 (0)