-
Notifications
You must be signed in to change notification settings - Fork 14
/
srsPDCCHdmrsUnittest.m
253 lines (217 loc) · 10.7 KB
/
srsPDCCHdmrsUnittest.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
%srsPDCCHdmrsUnittest Unit tests for PDCCH DMRS processor functions.
% This class implements unit tests for the PDCCH DMRS processor functions using the
% matlab.unittest framework. The simplest use consists in creating an object with
% testCase = srsPDCCHdmrsUnittest
% and then running all the tests with
% testResults = testCase.run
%
% srsPDCCHdmrsUnittest Properties (Constant):
%
% srsBlock - The tested block (i.e., 'dmrs_pdcch_processor').
% srsBlockType - The type of the tested block, including layer
% (i.e., 'phy/upper/signal_processors').
%
% srsPDCCHdmrsUnittest Properties (ClassSetupParameter):
%
% outputPath - Path to the folder where the test results are stored.
%
% srsPDCCHdmrsUnittest Properties (TestParameter):
%
% NCellID - PHY-layer cell ID (0...1007).
% NSlot - Slot index (0...19).
% numerology - Defines the subcarrier spacing (0, 1).
% Duration - CORESET duration (1, 2, 3).
% CCEREGMapping - CCE-to-REG mapping ('interleaved', 'noninteleaved').
% AggregationLevel - PDCCH aggregation level (1, 2, 4, 8, 16).
%
% srsPDCCHdmrsUnittest Methods (TestTags = {'testvector'}):
%
% testvectorGenerationCases - Generates a test vector according to the provided
% parameters.
%
% srsPBCHdmrsUnittest Methods (Access = protected):
%
% addTestIncludesToHeaderFile - Adds include directives to the test header file.
% addTestDefinitionToHeaderFile - Adds details (e.g., type/variable declarations)
% to the test header file.
% See also matlab.unittest.
% Copyright 2021-2024 Software Radio Systems Limited
%
% This file is part of srsRAN-matlab.
%
% srsRAN-matlab is free software: you can redistribute it and/or
% modify it under the terms of the BSD 2-Clause License.
%
% srsRAN-matlab 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
% BSD 2-Clause License for more details.
%
% A copy of the BSD 2-Clause License can be found in the LICENSE
% file in the top-level directory of this distribution.
classdef srsPDCCHdmrsUnittest < srsTest.srsBlockUnittest
properties (Constant)
%Name of the tested block.
srsBlock = 'dmrs_pdcch_processor'
%Type of the tested block.
srsBlockType = 'phy/upper/signal_processors'
end
properties (ClassSetupParameter)
%Path to results folder (old 'dmrs_pdcch_processor' tests will be erased).
outputPath = {['testPDCCHdmrs', char(datetime('now', 'Format', 'yyyyMMdd''T''HHmmss'))]}
end
properties (TestParameter)
%PHY-layer cell ID (0...1007).
NCellID = num2cell(0:1007)
%Slot index (0...19).
NSlot = num2cell(0:19)
%Defines the subcarrier spacing (0, 1).
numerology = {0, 1}
%CORESET duration (1, 2, 3).
Duration = {1, 2, 3}
%CCE-to-REG mapping ('interleaved', 'noninteleaved').
CCEREGMapping = {'interleaved','noninterleaved'}
%PDCCH aggregation level (1, 2, 4, 8, 16).
AggregationLevel= {1, 2, 4, 8, 16}
end % of properties (TestParameter)
properties(Hidden)
randomizeTestvector
randomizeSlotNum0
randomizeSlotNum1
end
methods (Access = protected)
function addTestIncludesToHeaderFile(obj, fileID)
%addTestIncludesToHeaderFile Adds include directives to the test header file.
addTestIncludesToHeaderFilePHYsigproc(obj, fileID);
fprintf(fileID, '#include "srsran/ran/precoding/precoding_codebooks.h"\n');
end
function addTestDefinitionToHeaderFile(obj, fileID)
%addTestDetailsToHeaderFile Adds details (e.g., type/variable declarations) to the test header file.
fprintf(fileID, 'static const precoding_configuration default_precoding = precoding_configuration::make_wideband(make_single_port());\n');
fprintf(fileID, '\n');
addTestDefinitionToHeaderFilePHYsigproc(obj, fileID);
end
function initializeClassImpl(obj)
obj.randomizeTestvector = randperm(1008);
obj.randomizeSlotNum0 = randi([1, 10], 1, 1008);
obj.randomizeSlotNum1 = randi([1, 20], 1, 1008);
end
end % of methods (Access = protected)
methods (TestClassSetup)
function createRandomVector(obj)
obj.randomizeTestvector = randperm(1008);
end
end
methods (Test, TestTags = {'testvector'})
function testvectorGenerationCases(testCase, numerology, Duration, CCEREGMapping, AggregationLevel)
%testvectorGenerationCases Generates a test vector for the given numerology, Duration,
% CCEREGMapping and AggregationLevel, while using a random NCellID and a random NSlot.
import srsTest.helpers.cellarray2str
import srsLib.phy.upper.signal_processors.srsPDCCHdmrs
import srsLib.phy.helpers.srsGetUniqueSymbolsIndices
import srsTest.helpers.writeResourceGridEntryFile
import srsTest.helpers.cellarray2str
import srsTest.helpers.RBallocationMask2string
% generate a unique test ID by looking at the number of files generated so far
testID = testCase.generateTestID;
% use a unique NCellID, NSlot and rnti for each test
randomizedCellID = testCase.randomizeTestvector(testID + 1);
nCellID = testCase.NCellID{randomizedCellID};
if numerology == 0
randomizedSlot = testCase.randomizeSlotNum0(testID + 1);
else
randomizedSlot = testCase.randomizeSlotNum1(testID + 1);
end
nSlot = testCase.NSlot{randomizedSlot};
% current fixed parameter values (e.g., maximum grid size with current interleaving
% configuration, CORESET will use all available frequency resources)
nSizeGrid = 216;
nStartGrid = 0;
nFrame = 0;
cyclicPrefix = 'normal';
maxFrequencyResources = floor(nSizeGrid / 6);
frequencyResources = int2bit(2^maxFrequencyResources - 1, maxFrequencyResources).';
interleaverSize = 2;
REGBundleSize = 6;
searchSpaceType = 'ue';
rnti = 0;
nStartBWP = 0;
nSizeBWP = nSizeGrid;
allocatedCandidate = 1;
referencePointKrb = 0;
startSymbolIndex = 0;
DMRSScramblingID = nCellID;
DMRSamplitude = 1.0;
% only encode the PDCCH when it fits
isAggregationOK = (sum(frequencyResources) * Duration >= AggregationLevel);
isREGbundleSizeOK = (mod(sum(frequencyResources) * Duration, interleaverSize * REGBundleSize) == 0);
isCCEREGMappingOK = (strcmp(CCEREGMapping, 'noninterleaved') || ...
(strcmp(CCEREGMapping, 'interleaved') && isREGbundleSizeOK));
if (isAggregationOK && isCCEREGMappingOK)
% configure the carrier according to the test parameters
subcarrierSpacing = 15 * (2 .^ numerology);
carrier = nrCarrierConfig( ...
NCellID=nCellID, ...
SubcarrierSpacing=subcarrierSpacing, ...
NSizeGrid=nSizeGrid, ...
NStartGrid=nStartGrid, ...
NSlot=nSlot, ...
NFrame=nFrame, ...
CyclicPrefix=cyclicPrefix ...
);
% configure the CORESET according to the test parameters
coreset = nrCORESETConfig( ...
FrequencyResources=frequencyResources, ...
Duration=Duration, ...
CCEREGMapping=CCEREGMapping, ...
REGBundleSize=REGBundleSize, ...
InterleaverSize=interleaverSize ...
);
% configure the PDCCH according to the test parameters
pdcch = nrPDCCHConfig( ...
CORESET=coreset, ...
NStartBWP=nStartBWP, ...
NSizeBWP=nSizeBWP, ...
RNTI=rnti, ...
AggregationLevel=AggregationLevel, ...
AllocatedCandidate=allocatedCandidate, ...
DMRSScramblingID=DMRSScramblingID ...
);
pdcch.SearchSpace.SearchSpaceType = searchSpaceType;
% call the PDCCH DMRS symbol processor MATLAB functions
[DMRSsymbols, symbolIndices] = srsPDCCHdmrs(carrier, pdcch);
% put all generated DMRS symbols and indices in a single cell
[DMRSsymbolsVector, symbolIndicesVector] = ...
srsGetUniqueSymbolsIndices(DMRSsymbols, symbolIndices);
% write each complex symbol into a binary file, and the associated indices to another
testCase.saveDataFile('_test_output', testID, @writeResourceGridEntryFile, ...
DMRSsymbolsVector, symbolIndicesVector);
% generate a 'slot_point' configuration string
slotPointConfig = {numerology, nFrame, ...
floor(nSlot / carrier.SlotsPerSubframe), ...
rem(nSlot, carrier.SlotsPerSubframe)};
% generate a RB allocation mask string
rbAllocationMask = RBallocationMask2string(symbolIndicesVector);
% Convert cyclic prefix to string.
cpString = ['cyclic_prefix::', upper(cyclicPrefix)];
configCell = {...
slotPointConfig, ... % slot
cpString, ... % cp
referencePointKrb,... % reference_point_k_rb
rbAllocationMask, ... % rb_mask
startSymbolIndex, ... % start_symbol_index
Duration, ... % duration
DMRSScramblingID, ... % n_id
DMRSamplitude, ... % amplitude
'default_precoding',... % precoding
};
% generate the test case entry
testCaseString = testCase.testCaseToString(testID, ...
configCell, ...
true, '_test_output');
% add the test to the file header
testCase.addTestToHeaderFile(testCase.headerFileID, testCaseString);
end % of if (isAggregationOK && isCCEREGMappingOK)
end % of function testvectorGenerationCases
end % of methods (Test, TestTags = {'testvector'})
end % of classdef srsPDCCHdmrsUnittest