-
Notifications
You must be signed in to change notification settings - Fork 14
/
CheckSimulators.m
437 lines (365 loc) · 18.7 KB
/
CheckSimulators.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
%CheckSimulators Unit tests for the SRS link-level simulators.
% This class, based on the matlab.unittest.TestCase framework, performs basic
% tests on the simulators in 'apps/simulators'. In few words, it checks whether
% a simulator object can be created, if it is of the correct type and it runs
% a very short simulation.
%
% CheckSimulators Methods (Test, TestTags = {'matlab code'}):
%
% testPUSCHBLERmatlab - Verifies the PUSCHBLER simulator class using MATLAB objects only.
% testPRACHPERFmatlab - Verifies the PRACHPERF simulator class using MATLAB objects only.
% testPUCCHBLERF0matlab - Verifies the PUCCHBLER F0 simulator class using MATLAB objects only.
% testPUCCHBLERF1matlab - Verifies the PUCCHBLER F1 simulator class using MATLAB objects only.
% testPUCCHBLERF2matlab - Verifies the PUCCHBLER F2 simulator class using MATLAB objects only.
%
% CheckSimulators Methods (Test, TestTags = {'mex code'}):
%
% testPUSCHBLERmex - Verifies the PUSCHBLER simulator class also using MEX implementations.
% testPUCCHBLERF0mex - Verifies the PUCCHBLER F0 simulator class also using MEX implementations.
% testPUCCHBLERF1mex - Verifies the PUCCHBLER F1 simulator class also using MEX implementations.
% testPUCCHBLERF2mex - Verifies the PUCCHBLER F2 simulator class also using MEX implementations.
%
% Example
% runtests('CheckSimulators')
%
% 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 CheckSimulators < matlab.unittest.TestCase
properties (TestParameter)
%Channel estimator implementation type for mex PUSCH tests.
EstimatorImplPUSCH = {"MEX", "noMEX"}
%Test type for PUCCH tests.
PUCCHTestType = {"Detection", "False Alarm"}
end % of properties (TestParameter)
methods (TestMethodSetup)
function resetrandomgenerator(obj)
% Reset random genenator after storing current state.
orig = rng('default');
% Random generator will be restored after the method.
obj.addTeardown(@rng, orig);
end % of function resetrandomgenerator(obj)
end % of methods (TestMethodSetup)
methods (Test, TestTags = {'matlab code'})
function testPUSCHBLERmatlab(obj)
import matlab.unittest.fixtures.CurrentFolderFixture
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUSCHBLER'));
try
pp = PUSCHBLER;
catch ME
obj.assertFail(['Could not create a PUSCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUSCHBLER', 'The created object is not a PUSCHBLER object.');
snrs = -5.6:0.2:-4.8;
try
pp(snrs, 100)
catch ME
obj.assertFail(['PUSCHBLER could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
obj.assertEqual(pp.TBS, 1800, 'Wrong transport block size.');
obj.assertEqual(pp.MaxThroughput, 1.8, 'Wrong maximum throughput.');
obj.assertEqual(pp.ThroughputMATLAB, [0; 0; 0.0178; 0.1636; 0.5755], "Wrong througuput curve.", RelTol=0.02);
obj.assertEqual(pp.BlockErrorRateMATLAB, [1; 1; 0.9901; 0.9091; 0.6803], "Wrong BLER curve.", RelTol=0.02);
end % of function testPUSCHBLERmatlab(obj)
function testPRACHPERFmatlab(obj)
import matlab.unittest.fixtures.CurrentFolderFixture
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PRACHPERF'));
try
pp = PRACHPERF;
catch ME
obj.assertFail(['Could not create a PRACHPERF object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PRACHPERF', 'The created object is not a PRACHPERF object.');
snr = -14.2;
pp.IgnoreCFO = true;
% Disable verbose PRACH detector warnings.
prachwarn = warning('query', 'srsran_matlab:srsPRACHdetector');
warning('off', 'srsran_matlab:srsPRACHdetector');
% Run detection test.
try
pp(snr, 100)
catch ME
obj.assertFail(['PRACHPERF could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snr, 'Wrong SNR range.');
obj.assertEqual(pp.Occasions, 100, 'Wrong number of occasions.');
obj.assertEqual(pp.Detected, 100, 'Wrong number of detected preambles.');
obj.assertEqual(pp.DetectedPerfect, 100, 'Wrong number of perfectly detected preambles.');
obj.assertEqual(pp.ProbabilityDetection, 1, 'Wrong probability of detection.');
obj.assertEqual(pp.ProbabilityDetectionPerfect, 1, 'Wrong probability of perfect detection.');
obj.assertEqual(pp.OffsetError, [0.1781 0.2265], 'Wrong offset error.', RelTol=0.02);
% Run false alarm test.
pp.release;
pp.TestType = 'False Alarm';
try
pp(snr, 100)
catch ME
obj.assertFail(['PRACHPERF could not run because of exception: ', ...
ME.message]);
end
% Restore verbose PRACH detector warnings.
warning(prachwarn);
obj.assertEqual(pp.SNRrange, snr, 'Wrong SNR range.');
obj.assertEqual(pp.Occasions, 100, 'Wrong number of occasions.');
obj.assertEqual(pp.Detected, 2, 'Wrong number of detected preambles.', AbsTol=2);
obj.assertEqual(pp.ProbabilityFalseAlarm, 0.02, 'Wrong probability of detection.', AbsTol=0.02);
end % of function testPRACHPERFmatlab(obj)
function testPUCCHBLERF0matlab(obj, PUCCHTestType)
import matlab.unittest.fixtures.CurrentFolderFixture
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUCCHBLER/'));
try
pp = PUCCHBLER;
catch ME
obj.assertFail(['Could not create a PUCCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUCCHBLER', 'The created object is not a PUCCHBLER object.');
pp.PUCCHFormat = 0;
pp.PRBSet = 0;
pp.SymbolAllocation = [13 1];
pp.NumACKBits = 1;
pp.NRxAnts = 2;
pp.TestType = PUCCHTestType;
snrs = -15:2:1;
try
pp(snrs, 100);
catch ME
obj.assertFail(['PUCCHBLER could not run because of excetion: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
if (PUCCHTestType == "Detection")
obj.assertEqual(pp.SRDetectionRateMATLAB, ones(numel(snrs), 1), "Wrong SR detection curve.");
obj.assertGreaterThanOrEqual(pp.ACKDetectionRateMATLAB, ...
[0.025; 0.060; 0.110; 0.220; 0.380; 0.660; 0.880; 0.980; 0.999], ...
"Wrong ACK detection curve.");
else
obj.assertEqual(pp.FalseACKDetectionRateMATLAB, 0.016 * ones(numel(snrs), 1), ...
"Wrong false ACK detection rate curve.");
end
end % of function testPUCCHBLERF0matlab(obj, PUCCHTestType)
function testPUCCHBLERF1matlab(obj, PUCCHTestType)
import matlab.unittest.fixtures.CurrentFolderFixture
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUCCHBLER'));
try
pp = PUCCHBLER;
catch ME
obj.assertFail(['Could not create a PUCCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUCCHBLER', 'The created object is not a PUCCHBLER object.');
pp.PUCCHFormat = 1;
pp.PRBSet = 0;
pp.SymbolAllocation = [0 14];
pp.NumACKBits = 2;
pp.NRxAnts = 2;
pp.TestType = PUCCHTestType;
snrs = -32:2:-14;
try
pp(snrs, 100)
catch ME
obj.assertFail(['PUCCHBLER could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
if (PUCCHTestType == "Detection")
obj.assertLessThan(pp.NACK2ACKDetectionRateMATLAB, 0.01, "Wrong NACK-to-ACK detection curve.");
obj.assertEqual(pp.ACKDetectionRateMATLAB, [0.0106; 0.0164; 0.0213; 0.0397; 0.0658; 0.1112; 0.2012; 0.3820; 0.6383; 0.8617], ...
"Wrong ACK detection rate curve.", RelTol=0.02);
else
obj.assertEqual(pp.FalseACKDetectionRateMATLAB, 0.007 * ones(10, 1), "Wrong false ACK detection rate curve.", RelTol=0.02);
end
end % of function testPUCCHBLERF1matlab(obj, PUCCHTestType)
function testPUCCHBLERF2matlab(obj, PUCCHTestType)
import matlab.unittest.fixtures.CurrentFolderFixture
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUCCHBLER'));
try
pp = PUCCHBLER;
catch ME
obj.assertFail(['Could not create a PUCCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUCCHBLER', 'The created object is not a PUCCHBLER object.');
obj.assertEqual(pp.PUCCHFormat, 2, ['The PUCCH Format is set to ' num2str(pp.PUCCHFormat) ' instead of 2.']);
pp.NRxAnts = 2;
pp.TestType = PUCCHTestType;
snrs = -20:2:-4;
try
pp(snrs, 100)
catch ME
obj.assertFail(['PUCCHBLER could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
if (PUCCHTestType == "Detection")
obj.assertEqual(pp.BlockErrorRateMATLAB, [1; 0.9709; 0.9346; 0.8696; 0.7576; 0.5682; 0.2053; 0.0280; 0.0010], ...
"Wrong BLER curve.", RelTol=0.02);
else
obj.assertEqual(pp.FalseDetectionRateMATLAB, 0.005 * ones(9, 1), "Wrong false alarm curve.", RelTol=0.02);
end
end % of function testPUCCHBLERF2matlab(obj, PUCCHTestType)
end % of methods (Test, TestTags = {'matlab code'})
methods (Test, TestTags = {'mex code'})
function testPUSCHBLERmex(obj, EstimatorImplPUSCH)
import matlab.unittest.fixtures.CurrentFolderFixture
import matlab.unittest.constraints.IsFile
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUSCHBLER'));
try
pp = PUSCHBLER;
catch ME
obj.assertFail(['Could not create a PUSCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUSCHBLER', 'The created object is not a PUSCHBLER object.');
obj.assertThat('../../../+srsMEX/+phy/@srsPUSCHDecoder/pusch_decoder_mex.mexa64', IsFile, ...
'Could not find PUSCH decoder mex executable.');
obj.assertThat('../../../+srsMEX/+phy/@srsPUSCHDemodulator/pusch_demodulator_mex.mexa64', IsFile, ...
'Could not find PUSCH demodulator mex executable.');
obj.assertThat('../../../+srsMEX/+phy/@srsMultiPortChannelEstimator/multiport_channel_estimator_mex.mexa64', IsFile, ...
'Could not find channel estimator mex executable.');
pp.QuickSimulation = false;
pp.ImplementationType = 'srs';
pp.PerfectChannelEstimator = false;
pp.SRSEstimatorType = EstimatorImplPUSCH;
snrs = -5.0:0.2:-4.2;
try
pp(snrs, 100)
catch ME
obj.assertFail(['PUSCHBLER could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
obj.assertEqual(pp.TBS, 1800, 'Wrong transport block size.');
obj.assertEqual(pp.MaxThroughput, 1.8, 'Wrong maximum throughput.');
obj.assertGreaterThanOrEqual(pp.ThroughputSRS, [0; 0; 0.041; 0.30; 0.97], "Wrong throughput curve.");
obj.assertLessThanOrEqual(pp.BlockErrorRateSRS, [1.00; 1.00; 0.98; 0.83; 0.46], "Wrong BLER curve.");
end % of function testPUSCHBLERmex(obj)
function testPUCCHBLERF0mex(obj, PUCCHTestType)
import matlab.unittest.fixtures.CurrentFolderFixture
import matlab.unittest.constraints.IsFile
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUCCHBLER/'));
try
pp = PUCCHBLER;
catch ME
obj.assertFail(['Could not create a PUCCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUCCHBLER', 'The created object is not a PUCCHBLER object.');
obj.assertThat('../../../+srsMEX/+phy/@srsPUCCHProcessor/pucch_processor_mex.mexa64', IsFile, ...
'Could not find PUCCH processor mex executable.');
pp.PUCCHFormat = 0;
pp.PRBSet = 0;
pp.SymbolAllocation = [13 1];
pp.NumACKBits = 1;
pp.NRxAnts = 2;
pp.TestType = PUCCHTestType;
pp.ImplementationType = 'srs';
snrs = -15:2:1;
try
pp(snrs, 100);
catch ME
obj.assertFail(['PUCCHBLER could not run because of excetion: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
if (PUCCHTestType == "Detection")
obj.assertEqual(pp.SRDetectionRateSRS, ones(numel(snrs), 1), "Wrong SR detection curve.");
obj.assertGreaterThanOrEqual(pp.ACKDetectionRateSRS, ...
[0.010; 0.025; 0.063; 0.151; 0.328; 0.628; 0.880; 0.980; 0.999], ...
"Wrong ACK detection curve.");
else
obj.assertLessThanOrEqual(pp.FalseACKDetectionRateSRS, 0.008 * ones(numel(snrs), 1), ...
"Wrong false ACK detection rate curve.");
end
end % of function testPUCCHBLERF0mex(obj, PUCCHTestType)
function testPUCCHBLERF1mex(obj, PUCCHTestType)
import matlab.unittest.fixtures.CurrentFolderFixture
import matlab.unittest.constraints.IsFile
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUCCHBLER'));
try
pp = PUCCHBLER;
catch ME
obj.assertFail(['Could not create a PUCCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUCCHBLER', 'The created object is not a PUCCHBLER object.');
obj.assertThat('../../../+srsMEX/+phy/@srsPUCCHProcessor/pucch_processor_mex.mexa64', IsFile, ...
'Could not find PUCCH processor mex executable.');
pp.PUCCHFormat = 1;
pp.PRBSet = 0;
pp.SymbolAllocation = [0 14];
pp.NumACKBits = 2;
pp.NRxAnts = 2;
pp.TestType = PUCCHTestType;
pp.ImplementationType = 'srs';
pp.PerfectChannelEstimator = false;
snrs = -32:2:-14;
try
pp(snrs, 100)
catch ME
obj.assertFail(['PUCCHBLER could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
if (PUCCHTestType == "Detection")
obj.assertLessThan(pp.NACK2ACKDetectionRateSRS, 0.04, "Wrong NACK-to-ACK detection curve.");
obj.assertGreaterThanOrEqual(pp.ACKDetectionRateSRS, ...
[0.0077; 0.0096; 0.0183; 0.0280; 0.0415; 0.0735; 0.145; 0.28; 0.5261; 0.79], ...
"Wrong ACK detection rate curve.");
else
obj.assertEqual(pp.FalseACKDetectionRateSRS, 0.0075 * ones(10, 1), "Wrong false ACK detection rate curve.", RelTol=0.02);
end
end % of function testPUCCHBLERF1mex(obj, PUCCHTestType)
function testPUCCHBLERF2mex(obj, PUCCHTestType)
import matlab.unittest.fixtures.CurrentFolderFixture
import matlab.unittest.constraints.IsFile
obj.applyFixture(CurrentFolderFixture('../apps/simulators/PUCCHBLER'));
try
pp = PUCCHBLER;
catch ME
obj.assertFail(['Could not create a PUCCHBLER object because of exception: ', ...
ME.message]);
end
obj.assertClass(pp, 'PUCCHBLER', 'The created object is not a PUCCHBLER object.');
obj.assertEqual(pp.PUCCHFormat, 2, ['The PUCCH Format is set to ' num2str(pp.PUCCHFormat) ' instead of 2.']);
obj.assertThat('../../../+srsMEX/+phy/@srsPUCCHProcessor/pucch_processor_mex.mexa64', IsFile, ...
'Could not find PUCCH processor mex executable.');
pp.TestType = PUCCHTestType;
pp.NRxAnts = 2;
pp.ImplementationType = 'srs';
pp.PerfectChannelEstimator = false;
snrs = -20:2:-4;
try
pp(snrs, 100)
catch ME
obj.assertFail(['PUCCHBLER could not run because of exception: ', ...
ME.message]);
end
obj.assertEqual(pp.SNRrange, snrs, 'Wrong SNR range.');
if (PUCCHTestType == "Detection")
obj.assertLessThanOrEqual(pp.BlockErrorRateSRS, ...
[0.9434; 0.9434; 0.901; 0.7937; 0.6452; 0.4274; 0.241; 0.0560; 0.0040], ...
"Wrong BLER curve.");
else
obj.assertLessThanOrEqual(pp.FalseDetectionRateSRS, 0.007 * ones(9, 1), "Wrong false alarm curve.");
end
end % of function testPUCCHBLERF2mex(obj, PUCCHTestType)
end % of methods (Test, TestTags = {'mex code'})
end % of classdef CheckSimulators < matlab.unittest.TestCase