-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsrsPUCCHdmrsUnittest.m
422 lines (366 loc) · 16.7 KB
/
srsPUCCHdmrsUnittest.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
%srsPUCCHdmrsUnittest Unit tests for PUCCH DM-RS estimator functions.
% This class implements unit tests for the PUCCH DM-RS estimator functions using the
% matlab.unittest framework. The simplest use consists in creating an object with
% testCase = srsPUCCHdmrsUnittest
% and then running all the tests with
% testResults = testCase.run
%
% srsPUCCHdmrsUnittest Properties (Constant):
%
% srsBlock - The tested block (i.e., 'dmrs_pucch_estimator').
% srsBlockType - The type of the tested block, including layer
% (i.e., 'phy/upper/signal_processors').
%
% srsPUCCHdmrsUnittest Properties (ClassSetupParameter):
%
% outputPath - Path to the folder where the test results are stored.
%
% srsPUCCHdmrsUnittest Properties (TestParameter):
%
% numerology - Defines the subcarrier spacing (0, 1).
% format - PUCCH format (1, 2, 3, 4).
% intraSlotFreqHopping - Intra-slot frequency hopping (false - enabled, true - enabled)
%
% srsPUCCHdmrsUnittest Methods (TestTags = {'testvector'}):
%
% testvectorGenerationCases - Generates a test vector according to the provided
% parameters.
%
% srsPUCCHdmrsUnittest 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, nrPUCCHDMRS.
% 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 srsPUCCHdmrsUnittest < srsTest.srsBlockUnittest
properties (Constant)
%Name of the tested block.
srsBlock = 'dmrs_pucch_estimator'
%Type of the tested block.
srsBlockType = 'phy/upper/signal_processors'
end
properties (ClassSetupParameter)
%Path to results folder (old 'dmrs_pucch_estimator' tests will be erased).
outputPath = {['testPUCCHdmrs', char(datetime('now', 'Format', 'yyyyMMdd''T''HHmmss'))]}
end
properties (TestParameter)
%Defines the subcarrier spacing (0, 1).
numerology = {0, 1}
%PUCCH format indexes.
format = {1, 2, 3, 4}
%Intra-slot frequency hopping usage (inter-slot hopping is not tested).
intraSlotFreqHopping = {false, true}
%Two test vectors with randomized parameters (e.g. cell ID, slot number etc.)
%are generated for each set of unittest parameters.
testCaseTrial = {1, 2}
end % of properties (TestParameter)
properties(Hidden)
randomizeTestvector
end % of properties(Hidden)
properties(Constant, Hidden)
%PHY-layer cell ID (0...1007).
NCellID = num2cell(0:1007)
%Minimum and maximum symbol length allowed for each of five PUCCH formats.
formatLengthSymbols = [1 2; 4 14; 1 2; 4 14; 4 14]
%Possible length in number of PRBs for Format 3.
prbLengthFormat3 = [1:6, 8:10, 12, 15, 16]
%PUCCH format string following srsran repo API.
srsFormatName = 'pucch_format::FORMAT_';
%Number of symbols per slot considering normal cyclic prefix.
numSlotSymbols = 14;
end % of properties(Constant, Hidden)
methods (Access = protected)
function addTestIncludesToHeaderFile(obj, fileID)
%addTestIncludesToHeaderFile Adds include directives to the test header file.
addTestIncludesToHeaderFilePHYsigproc(obj, fileID);
fprintf(fileID, '#include <variant>\n');
end
function addTestDefinitionToHeaderFile(~, fileID)
%addTestDetailsToHeaderFile Adds details (e.g., type/variable declarations) to the test header file.
fprintf(fileID, 'using estimator_config = std::variant<\n');
fprintf(fileID, 'dmrs_pucch_estimator::format1_configuration,\n');
fprintf(fileID, 'dmrs_pucch_estimator::format2_configuration,\n');
fprintf(fileID, 'dmrs_pucch_estimator::format3_configuration,\n');
fprintf(fileID, 'dmrs_pucch_estimator::format4_configuration\n');
fprintf(fileID, '>;\n\n');
fprintf(fileID, 'struct test_case_t {\n');
fprintf(fileID, 'estimator_config config;\n');
fprintf(fileID, ...
'file_vector<resource_grid_reader_spy::expected_entry_t> symbols;\n');
fprintf(fileID, '};\n');
end
function initializeClassImpl(obj)
obj.randomizeTestvector = randperm(1008);
end
end % of methods (Access = protected)
methods (Access = private)
function PRBSet = generateRandomPRBallocation(testCase, gridSize, format)
%generateRandomPRBallocation Generates a PRB set starting from a random PRB index
% in the grid with a random valid length in number of PRBs.
%
% Parameters:
% gridSize - size of the resource grid.
% format - PUCCH format.
startPRB = randi([0, gridSize - 1]);
switch format
case {1, 4}
nofPRBs = 1;
setPRBsAsRange = false;
case 2
nofPRBs = randi([1, 16]);
setPRBsAsRange = true;
case 3
randId = randi([1, length(testCase.prbLengthFormat3)]);
nofPRBs = testCase.prbLengthFormat3(randId);
setPRBsAsRange = true;
end
% Make sure the PRB allocation is not beyond the resource grid.
if startPRB + nofPRBs > gridSize
nofPRBs = gridSize - startPRB;
end
% For formats 1 and 4 it is just a scalar.
PRBSet = startPRB;
% For formats 2 and 3 it is a range.
if setPRBsAsRange
endPRB = startPRB + nofPRBs - 1;
PRBSet = startPRB:endPRB;
end
end % of function generateRandomPRBallocation
end % of methods (Access = private)
methods (Test, TestTags = {'testvector'})
function testvectorGenerationCases(testCase, numerology, format, intraSlotFreqHopping, testCaseTrial) %#ok<INUSD>
%testvectorGenerationCases Generates a test vector for the given numerology, format and frequency hopping,
% while using a random NCellID, random NSlot and random symbol and PRB length.
import srsLib.phy.upper.signal_processors.srsPUCCHdmrs
import srsTest.helpers.writeResourceGridEntryFile
import srsTest.helpers.cellarray2str
import srsTest.helpers.logical2str;
% Generate a unique test ID by looking at the number of files
% generated so far.
testID = testCase.generateTestID;
% Use a unique NCellID, NSlot for each test.
randomizedCellID = testCase.randomizeTestvector(testID + 1);
nCellID = testCase.NCellID{randomizedCellID};
% Use a random slot number from the allowed range.
if numerology == 0
nSlot = randi([0, 9]);
else
nSlot = randi([0, 19]);
end
% Format name following srsran naming.
formatString = ['dmrs_pucch_estimator::format', num2str(format), '_configuration'];
% Fixed parameter values.
nSizeGrid = 52;
nStartGrid = 0;
nFrame = 0;
cyclicPrefix = 'normal';
groupHopping = 'neither';
frequencyHopping = 'neither';
secondHopStartPRB = 0;
% Fix nid and nid0 to physical CellID.
nid = nCellID;
nid0 = nCellID;
% Currently fixed to 1 port of random number from [0, 7].
ports = randi([0, 7]);
portsStr = cellarray2str({ports}, true);
% Random initial cyclic shift.
initialCyclicShift = randi([0, 11]);
% Random start PRB index and length in number of PRBs.
PRBSet = generateRandomPRBallocation(testCase, nSizeGrid, format);
nofPRBs = size(PRBSet, 2);
% Random start symbol and length in symbols.
symbolLength = randi([testCase.formatLengthSymbols(format + 1, 1), ...
testCase.formatLengthSymbols(format + 1, 2)]);
% Intra-slot frequency hopping requires at least 2 OFDM
% symbols.
if (intraSlotFreqHopping && symbolLength == 1)
symbolLength = 2;
end
maxStartSymbol = testCase.numSlotSymbols - symbolLength - 1;
if maxStartSymbol > 0
startSymbolIndex = randi([0, maxStartSymbol]);
else
startSymbolIndex = 0;
end
symbolAllocation = [startSymbolIndex symbolLength];
% Orthogonal Cover Code Index.
OCCI = 0;
if (format == 1)
% When intraslot frequency hopping is disabled, the OCCI value must be less
% than the floor of half of the number of OFDM symbols allocated for the PUCCH.
if ~intraSlotFreqHopping
OCCI = randi([0, (floor(symbolLength / 2) - 1)]);
else
% When intraslot frequency hopping is enabled, the OCCI value must be less
% than the floor of one-fourth of the number of OFDM symbols allocated for the PUCCH.
maxOCCindex = floor(symbolLength / 4) - 1;
if maxOCCindex == 0
OCCI = 0;
else
OCCI = randi([0, maxOCCindex]);
end
end
elseif (format == 4)
spreadingFactor = 2^randi([1 2]);
OCCI = randi([0 spreadingFactor-1]);
end
% Additional DM-RS.
additionalDMRS = false;
if (format == 3) || (format == 4)
additionalDMRS = randi([0 1]) == 1;
end
% Randomly select secondHopStartPRB if intra-slot frequency
% hopping is enabled.
if intraSlotFreqHopping
secondHopStartPRB = generateRandomSecondHopPRB(nSizeGrid, PRBSet);
% Set respective MATLAB parameter.
frequencyHopping = 'intraSlot';
end
% 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 PUCCH according to the test parameters.
pucch = createPUCCHConfig(format);
pucch.SymbolAllocation = symbolAllocation;
pucch.PRBSet = PRBSet;
pucch.FrequencyHopping = frequencyHopping;
pucch.SecondHopStartPRB = secondHopStartPRB;
pucch.OCCI = OCCI;
if ((format == 1) || (format == 3) || (format == 4))
pucch.GroupHopping = groupHopping;
end % of if ((format == 1) || (format == 3) || (format == 4))
if (format == 1)
pucch.InitialCyclicShift = initialCyclicShift;
end % of if (format == 1)
if (format == 3) || (format == 4)
pucch.AdditionalDMRS = additionalDMRS;
end % of if (format == 3) || (format == 4)
if (format == 4)
pucch.SpreadingFactor = spreadingFactor;
end % of if (format == 4)
% Call the PUCCH DM-RS symbol processor MATLAB functions.
[DMRSsymbols, DMRSindices] = srsPUCCHdmrs(carrier, pucch);
% Set the DM-RS port indexes.
DMRSindices(:, 3) = ports;
% Write the complex symbols along with their associated indices
% into a binary file.
testCase.saveDataFile('_test_output', testID, ...
@writeResourceGridEntryFile, DMRSsymbols, DMRSindices);
% Generate a 'slot_point' configuration string.
slotPointConfig = cellarray2str({numerology, nSlot}, true);
% Group hopping string following srsran naming.
GroupHoppingStr = ['pucch_group_hopping::', upper(groupHopping)];
% Write as true/false.
if intraSlotFreqHopping
secondHopStartPRBStr = cellarray2str({secondHopStartPRB}, true);
else
secondHopStartPRBStr = '{}';
end
commonConfig = {...
slotPointConfig, ... % slot
['cyclic_prefix::', upper(cyclicPrefix)], ... % cp
GroupHoppingStr, ... % group_hopping
startSymbolIndex, ... % start_symbol_index
symbolLength, ... % nof_symbols
PRBSet(1), ... % starting_prb
secondHopStartPRBStr, ... % second_hop_prb
portsStr, ... % ports
};
% Generate the test case entry.
if format == 1
config = {...
commonConfig, ...
nid, ... % n_id
initialCyclicShift, ... % initial_cyclic_shift
OCCI, ... % time_domain_occ
};
elseif format == 2
config = {...
commonConfig, ...
nofPRBs, ... % nof_prb
nid0, ... % n_id_0
};
elseif format == 3
config = {...
commonConfig, ...
nid, ... % n_id
nofPRBs, ... % nof_prb
additionalDMRS, ... % additional_dmrs
};
elseif format == 4
config = {...
commonConfig, ...
nid, ... % n_id
additionalDMRS, ... % additional_dmrs
OCCI, ... % occ_index
};
end
% Insert the name of the config type in the test case string.
configStr = ['dmrs_pucch_estimator::format', ...
char(string(format)), '_configuration', ...
cellarray2str(config, true)];
testCaseString = testCase.testCaseToString(testID, ...
{configStr}, false, '_test_output');
% Add the test to the file header.
testCase.addTestToHeaderFile(testCase.headerFileID, testCaseString);
end % of function testvectorGenerationCases
end % of methods (Test, TestTags = {'testvector'})
end % of classdef srsPUCCHdmrsUnittest
function secondHopStartPRB = generateRandomSecondHopPRB(gridSize, PRBSet)
%generateRandomSecondHopPRB Randomly select a valid starting PRB
% of a second hop in the grid.
%
% Parameters:
% gridSize - size of the resource grid.
% PRBSet - set of PRBs allocated for the first frequency hop.
nofPRBs = size(PRBSet, 2);
gridPRBs = 0:(gridSize - 1);
PRBcount = nofPRBs;
if nofPRBs == 1
% A fixup used for a single allocated PRB.
PRBcount = PRBcount - 1;
end
totalPRBs = gridPRBs + PRBcount;
validStartIndexes = (~ismember(totalPRBs, PRBSet)) & (totalPRBs < gridSize);
% Exclude PRBset used by the first hop.
validStartIndexes(PRBSet + 1) = 0;
validSecondHopPRBs = gridPRBs(validStartIndexes);
secondHopStartPRB = validSecondHopPRBs(randi([1, size(validSecondHopPRBs, 2)]));
end % of function generateRandomSecondHopPRB
function pucch = createPUCCHConfig(format)
switch format
case 1
pucch = nrPUCCH1Config;
case 2
pucch = nrPUCCH2Config;
case 3
pucch = nrPUCCH3Config;
case 4
pucch = nrPUCCH4Config;
otherwise
error('Unknown PUCCH format %d', format);
end
end % of function createPUCCHConfig(format)