-
Notifications
You must be signed in to change notification settings - Fork 14
/
srsPRACHDemodulatorUnittest.m
281 lines (235 loc) · 11.7 KB
/
srsPRACHDemodulatorUnittest.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
%srsPRACHDemodulatorUnittest Unit tests for PRACH waveform demodulator.
% This class implements unit tests for the PRACH waveform demodulator
% functions using the matlab.unittest framework. The simplest use
% consists in creating an object with
% testCase = srsPRACHDemodulatorUnittest
% and then running all the tests with
% testResults = testCase.run
%
% srsPRACHDemodulatorUnittest Properties (Constant):
%
% srsBlock - The tested block (i.e., 'ofdm_prach_demodulator').
% srsBlockType - The type of the tested block, including layer
% (i.e., 'phy/lower/modulation').
%
% srsPRACHDemodulatorUnittest Properties (ClassSetupParameter):
%
% outputPath - Path to the folder where the test results are stored.
%
% srsPRACHDemodulatorUnittest Properties (TestParameter):
%
% DuplexMode - Duplexing mode FDD or TDD.
% CarrierBandwidth - Carrier bandwidth in PRB.
% PreambleFormat - Generated preamble format.
% RestrictedSet - Restricted set type.
% ZeroCorrelationZone - Cyclic shift configuration index {0, 15}.
% RBOffset - Frequency-domain sequence mapping.
%
% srsPRACHDemodulatorUnittest Methods (TestTags = {'testvector'}):
%
% testvectorGenerationCases - Generates a test vectors according to the provided
% parameters.
%
% srsPRACHDemodulatorUnittest 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 srsPRACHDemodulatorUnittest < srsTest.srsBlockUnittest
properties (Constant)
%Name of the tested block.
srsBlock = 'ofdm_prach_demodulator'
%Type of the tested block.
srsBlockType = 'phy/lower/modulation'
%Preamble formats for FR1.
PreambleFormatsFR1 = {'0', '1', '2', '3', 'A1', 'A1/B1', 'A2', ...
'A2/B2', 'A3', 'A3/B3', 'B1', 'B4', 'C0', 'C2'}
%Preamble formats for FR2.
PreambleFormatsFR2 = {'A1', 'A1/B1', 'A2', 'A2/B2', 'A3', ...
'A3/B3', 'B1', 'B4', 'C0', 'C2'}
end
properties (ClassSetupParameter)
%Path to results folder (old 'ofdm_prach_demodulator' tests will be erased).
outputPath = {['testPRACHDemodulator', char(datetime('now', 'Format', 'yyyyMMdd''T''HHmmss'))]}
end
properties (TestParameter)
%Carrier duplexing mode, set to
% - FDD for paired spectrum with 15kHz subcarrier spacing, or
% - TDD for unpaired spectrum with 30kHz subcarrier spacing.
% - TDD-FR2 for unpaired spectrum in frequency range 2 with 120kHz subcarrier spacing.
DuplexMode = {'FDD', 'TDD', 'TDD-FR2'}
%Carrier bandwidth in PRB.
CarrierBandwidth = {79, 106, 212, 275}
%Restricted set type.
% Possible values are {'UnrestrictedSet', 'RestrictedSetTypeA', 'RestrictedSetTypeB'}.
RestrictedSet = {'UnrestrictedSet'}
%Zero correlation zone, cyclic shift configuration index.
ZeroCorrelationZone = {0}
%Frequency-domain sequence mapping.
% Starting resource block (RB) index of the initial uplink bandwidth
% part (BWP) relative to carrier resource grid.
RBOffset = {0, 2, 4, 10};
end
methods (Access = protected)
function addTestIncludesToHeaderFile(~, fileID)
%addTestIncludesToHeaderFile Adds include directives to the test header file.
fprintf(fileID, [...
'#include "srsran/phy/lower/modulation/ofdm_prach_demodulator.h"\n'...
'#include "srsran/phy/lower/sampling_rate.h"\n'...
'#include "srsran/support/file_vector.h"\n'...
]);
end
function addTestDefinitionToHeaderFile(~, fileID)
%addTestDetailsToHeaderFile Adds details (e.g., type/variable declarations) to the test header file.
fprintf(fileID, [...
'struct prach_context {\n'...
' sampling_rate srate;\n'...
' ofdm_prach_demodulator::configuration config;\n'...
'};\n'...
'\n'...
'struct test_case_t {\n'...
' prach_context context;\n'...
' file_vector<cf_t> input;\n'...
' file_vector<cf_t> output;\n'...
'};\n'...
]);
end
end % of methods (Access = protected)
methods (Test, TestTags = {'testvector'})
function testvectorGenerationCases(testCase, DuplexMode, CarrierBandwidth, RestrictedSet, ZeroCorrelationZone, RBOffset)
%testvectorGenerationCases Generates a test vector for the given
% DuplexMode, CarrierBandwidth, RestrictedSet,
% ZeroCorrelationZone and RBOffset. The parameters SequenceIndex,
% PreambleFormat and PreambleIndex are generated randomly.
import srsTest.helpers.writeComplexFloatFile
import srsLib.phy.helpers.srsConfigurePRACH
import srsLib.phy.upper.channel_processors.srsPRACHgenerator
% Generate a unique test ID
TestID = testCase.generateTestID;
% Set parameters that depend on the duplex mode.
switch DuplexMode
case 'FDD'
frequencyRange = 'FR1';
subcarrierSpacing = 15;
preambleFormats = testCase.PreambleFormatsFR1;
case 'TDD'
frequencyRange = 'FR1';
subcarrierSpacing = 30;
preambleFormats = testCase.PreambleFormatsFR1;
case 'TDD-FR2'
frequencyRange = 'FR2';
subcarrierSpacing = 120;
DuplexMode = 'TDD';
preambleFormats = testCase.PreambleFormatsFR2;
otherwise
error('Invalid duplex mode %s', DuplexMode);
end
PreambleFormat = preambleFormats{randi([1, numel(preambleFormats)])};
% Generate carrier configuration
carrier = nrCarrierConfig( ...
CyclicPrefix='normal', ...
NSizeGrid=CarrierBandwidth, ...
SubcarrierSpacing=subcarrierSpacing ...
);
% Generate PRACH configuration.
sequenceIndex = randi([0, 1023], 1, 1);
prach = srsConfigurePRACH( ...
PreambleFormat, ...
FrequencyRange=frequencyRange, ...
DuplexMode=DuplexMode, ...
SubcarrierSpacing=subcarrierSpacing, ...
SequenceIndex=sequenceIndex, ...
RestrictedSet=RestrictedSet, ...
ZeroCorrelationZone=ZeroCorrelationZone, ...
RBOffset=RBOffset ...
);
% Select a symbolic number of frequency-domain occasions.
NumFreqOccasions = 2;
% Get PRACH modulation information.
PrachOfdmInfo = nrPRACHOFDMInfo(carrier, prach);
% Allocate the modulated waveform.
waveform = zeros(sum(PrachOfdmInfo.SymbolLengths), 1);
% Prepare matrix with PRACH symbols to modulate.
PRACHSymbols = nan(prach.LRA, NumFreqOccasions, prach.NumTimeOccasions);
% Generate a waveform for each time and frequency occasion.
for TimeIndex = 1:prach.NumTimeOccasions
for FrequencyIndex = 1:NumFreqOccasions
% Select time- and frequency-domain occasion.
prach.TimeIndex = TimeIndex - 1;
prach.FrequencyIndex = FrequencyIndex - 1;
% Select a random preamble index.
prach.PreambleIndex = randi([0, 63]);
% Generate waveform for each occasion.
[occasionTmp, gridset, info] = srsPRACHgenerator(carrier, prach);
% Pad occasion with zeros to match the waveform size.
occasion = [occasionTmp; zeros(numel(waveform) - numel(occasionTmp), 1)];
% Combine the waveform of each occasion.
waveform = occasion + waveform;
% Store PRACH sequence.
PRACHSymbols(:, FrequencyIndex, TimeIndex) = info.PRACHSymbols(1:prach.LRA);
end % for FrequencyIndex = NumFreqOccasions
end % for TimeIndex = 0:prach.NumTimeOccasions
% Correct waveform scaling for the demodulator.
ofdmInfo = nrOFDMInfo(carrier);
prachInfo = nrPRACHOFDMInfo(carrier, prach);
scaling = sqrt(prach.LRA * ofdmInfo.Nfft / prachInfo.Nfft);
waveform = waveform * scaling;
% Reset time and frequency indexes.
prach.TimeIndex = 0;
prach.FrequencyIndex = 0;
% Select the starting symbol within the slot and duration in symbols.
StartSymbolWithinSlot = mod(prach.SymbolLocation, 14);
if strcmp(PreambleFormat, 'C0')
% Undoes MATLAB constrain, explained in nrPRACHConfig help.
StartSymbolWithinSlot = mod(prach.SymbolLocation * 2, 14);
end
% Convert the sampling rate to srsRAN format.
srsSampleRateString = sprintf('sampling_rate::from_MHz(%.2f)', gridset.Info.SampleRate / 1e6);
% Write the generated PRACH sequence into a binary file.
testCase.saveDataFile('_test_input', TestID, ...
@writeComplexFloatFile, waveform);
% Write the PRACH symbols into a binary file.
testCase.saveDataFile('_test_output', TestID, ...
@writeComplexFloatFile, PRACHSymbols);
srsPRACHFormat = sprintf('to_prach_format_type("%s")', PreambleFormat);
% Slot configuration.
slotConfig = {log2(carrier.SubcarrierSpacing/15), info.NPRACHSlot};
% srsran PRACH configuration
srsPRACHConfig = {...
slotConfig, ... % slot
srsPRACHFormat, ... % format
max([1, prach.NumTimeOccasions]), ... % nof_td_occasions
max([1, NumFreqOccasions]), ... % nof_fd_occasions
StartSymbolWithinSlot , ... % start_symbol
prach.RBOffset, ... % rb_offset
carrier.NSizeGrid, ... % nof_prb_ul_grid
};
% test context
srsTestContext = {
srsSampleRateString, ... % srate
srsPRACHConfig, ... % config
};
% Generate the test case entry
testCaseString = testCase.testCaseToString(TestID, ...
srsTestContext, true, '_test_input', '_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 srsPRACHDemodulatorUnittest