-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsrsTransformPrecoderUnittest.m
146 lines (124 loc) · 6.19 KB
/
srsTransformPrecoderUnittest.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
%srsTransformPrecoderUnittest Unit tests for transform precoding functions.
% This class implements unit tests for the transform precoding
% functions using the matlab.unittest framework. The simplest use
% consists in creating an object with
% testCase = srsTransformPrecoderUnittest
% and then running all the tests with
% testResults = testCase.run
%
% srsTransformPrecoderUnittest Properties (Constant):
%
% srsBlock - The tested block (i.e., 'transform_precoder').
% srsBlockType - The type of the tested block, including layer
% (i.e., 'phy/generic_functions/transform_precoding').
%
% srsTransformPrecoderUnittest Properties (ClassSetupParameter):
%
% outputPath - Path to the folder where the test results are stored.
%
% srsTransformPrecoderUnittest Properties (TestParameter):
%
% NumPRB - Number of resource blocks.
% NumOFDMSymbols - Number of OFDM symbols to perform precoding.
%
% srsTransformPrecoderUnittest Methods (TestTags = {'testvector'}):
%
% testvectorGenerationCases - Generates a test vector according to the provided
% parameters.
%
% srsTransformPrecoderUnittest 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, nrTransformPrecode, nrTransformDeprecode.
% 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 srsTransformPrecoderUnittest < srsTest.srsBlockUnittest
properties (Constant)
%Name of the tested block.
srsBlock = 'transform_precoder'
%Type of the tested block.
srsBlockType = 'phy/generic_functions/transform_precoding'
%Number of OFDM symbols to apply transform precoding.
NumOFDMSymbols = 8
end
properties (ClassSetupParameter)
%Path to results folder (old 'transform_precoder' tests will be erased).
outputPath = {['testTransformPrecoder', char(datetime('now', 'Format', 'yyyyMMdd''T''HHmmss'))]}
end
properties (TestParameter)
%Valid number of RB to apply transform precode.
NumPRB = {...
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, ...
18, 20, 24, 25, 27, 30, 32, 36, 40, 45, 48, 50, ...
54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, ...
125, 128, 135, 144, 150, 160, 162, 180, 192, 200, 216, 225, ...
240, 243, 250, 256, 270};
end
methods (Access = protected)
function addTestIncludesToHeaderFile(~, fileID)
%addTestIncludesToHeaderFile Adds include directives to the test header file.
fprintf(fileID, '#include "srsran/adt/complex.h"\n');
fprintf(fileID, '#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 test_case_t {\n');
fprintf(fileID, ' unsigned M_rb;\n');
fprintf(fileID, ' file_vector<cf_t> deprecode_data_input;\n');
fprintf(fileID, ' file_vector<float> deprecode_noise_input;\n');
fprintf(fileID, ' file_vector<cf_t> deprecode_data_output;\n');
fprintf(fileID, ' file_vector<float> deprecode_noise_output;\n');
fprintf(fileID, '};\n');
end
end % of methods (Access = protected)
methods (Test, TestTags = {'testvector'})
function testvectorGenerationCases(testCase, NumPRB)
%testvectorGenerationCases Generates a test vectors given the MRB.
import srsTest.helpers.writeComplexFloatFile
import srsTest.helpers.writeFloatFile
import srsTest.helpers.randmod;
import srsLib.phy.generic_functions.transform_precoding.srsTransformDeprecode;
% Generate a unique test ID by looking at the number of files
% generated so far.
testID = testCase.generateTestID;
% Calculate total number of subcarriers.
NumSC = NumPRB * 12 * testCase.NumOFDMSymbols;
% Generate random QPSK subcarriers.
x = randmod('QPSK', [NumSC, 1]);
% Apply transform precoding.
precoded = nrTransformPrecode(x, NumPRB);
% Generate noise variance.
eqNoiseVar = rand() + rand(size(precoded)) / 10;
% Deprecode.
[deprecoded, noiseVar] = srsTransformDeprecode(precoded, eqNoiseVar, NumPRB, 1);
% Save data before transform precoding.
testCase.saveDataFile('_test_input_data', testID, @writeComplexFloatFile, precoded);
testCase.saveDataFile('_test_input_noise', testID, @writeFloatFile, eqNoiseVar);
% Save data after transform precoding.
testCase.saveDataFile('_test_output_data', testID, @writeComplexFloatFile, deprecoded);
testCase.saveDataFile('_test_output_noise', testID, @writeFloatFile, noiseVar);
testCaseString = testCase.testCaseToString(testID, ...
{NumPRB}, false, '_test_input_data', ...
'_test_input_noise', '_test_output_data', ...
'_test_output_noise');
% 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 srsTransformPrecoderUnittest