-
Notifications
You must be signed in to change notification settings - Fork 1
/
inlerp.cc
329 lines (283 loc) · 8.7 KB
/
inlerp.cc
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
#include "ns3/nr-eesm-t1.h"
#include <fstream>
#include <iomanip>
#pragma region
std::string infostr = R"ASADO(// Copyright (c) 2022 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
// Interpolated by Espacio 5G (A.G. ; D.T.)
// SPDX-License-Identifier: GPL-2.0-only
#include "nr-eesm-t1.h"
namespace ns3
{
/**
* \brief Table of SE of the standard MCSs: 29 (0 to 28) MCSs as per Table1 in TS38.214
*/
static const std::vector<double> SpectralEfficiencyForMcs1 = {
// QPSK (M=2)
0.23,
0.31,
0.38,
0.49,
0.6,
0.74,
0.88,
1.03,
1.18,
1.33, // SEs of MCSs
// 16QAM (M=4)
1.33,
1.48,
1.70,
1.91,
2.16,
2.41,
2.57, // SEs of MCSs
// 64QAM (M=6)
2.57,
2.73,
3.03,
3.32,
3.61,
3.90,
4.21,
4.52,
4.82,
5.12,
5.33,
5.55 // SEs of MCSs
};
/**
* \brief Table of SE of the standard CQIs: 16 CQIs as per Table1 in TS38.214
*/
static const std::vector<double> SpectralEfficiencyForCqi1 = {0.0, // out of range
0.15,
0.23,
0.38,
0.6,
0.88,
1.18,
1.48,
1.91,
2.41,
2.73,
3.32,
3.9,
4.52,
5.12,
5.55};
/**
* \brief SINR to BLER mapping for MCSs in Table1
*/)ASADO";
std::string endstring = R"ASADO(/**
* \brief Table of beta values for each standard MCS in Table1 in TS38.214
*/
static const std::vector<double> BetaTable1 = {
1.6, 1.61, 1.63, 1.65, 1.67, 1.7, 1.73, 1.76, 1.79, 1.82,
3.97, 4.27, 4.71, 5.16, 5.66, 6.16, 6.5, 9.95, 10.97, 12.92,
14.96, 17.06, 19.33, 21.85, 24.51, 27.14, 29.94, 32.05, 34.28};
/**
* \brief Table of ECR of the standard MCSs: 29 MCSs as per Table1 in TS38.214
*/
static const std::vector<double> McsEcrTable1 = {
// QPSK (M=2)
0.12,
0.15,
0.19,
0.25,
0.30,
0.37,
0.44,
0.51,
0.59,
0.66, // ECRs of MCSs
// 16QAM (M=4)
0.33,
0.37,
0.42,
0.48,
0.54,
0.60,
0.64, // ECRs of MCSs
// 64QAM (M=6)
0.43,
0.46,
0.50,
0.55,
0.60,
0.65,
0.70,
0.75,
0.80,
0.85,
0.89,
0.93 // ECRs of MCSs
};
/**
* \brief Table of modulation order of the standard MCSs: 29 MCSs as per Table1
* in TS38.214
*/
static const std::vector<uint8_t> McsMTable1 = {
// QPSK (M=2)
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
// 16QAM (M=4)
4,
4,
4,
4,
4,
4,
4,
// 64QAM (M=6)
6,
6,
6,
6,
6,
6,
6,
6,
6,
6,
6,
6};
NrEesmT1::NrEesmT1()
{
m_betaTable = &BetaTable1;
m_mcsEcrTable = &McsEcrTable1;
m_simulatedBlerFromSINR = &BlerForSinr1;
m_mcsMTable = &McsMTable1;
m_spectralEfficiencyForMcs = &SpectralEfficiencyForMcs1;
m_spectralEfficiencyForCqi = &SpectralEfficiencyForCqi1;
}
} // namespace ns3
)ASADO";
#pragma endregion
using namespace ns3;
std::vector<std::vector<double>> interpolarPuntos(const std::vector<double>& X, const std::vector<double>& Y, int n);
int main()
{
int num_values = 100; // Total number of values will be num_values+2 because the first and last values are kept
std::cout << "[!] Remember to set the cwd to the project folder." << std::endl;
std::cout << "Interpolating a total of " << num_values << " samples." << std::endl;
NrEesmT1 table;
auto* tt = table.m_simulatedBlerFromSINR;
int mcsIndex = 0;
int BsgIndex = 0;
std::ofstream outfile("./to_replace_in_src/nr-eesm-t1.cc.txt");
outfile << infostr << std::endl;
outfile << "static const NrEesmErrorModel::SimulatedBlerFromSINR BlerForSinr1 = {" << std::endl;
for (const auto& BaseGrah : *tt)
{
outfile << "\t{ // BG TYPE " << BsgIndex << std::endl;
for (const auto& MCS : BaseGrah)
{
outfile << "\t { // MCS " << mcsIndex << std::endl;
for (const auto & CBS : MCS)
{
outfile << "\t {" << CBS.first << "U, // SINR and BLER for CBS " << CBS.first << std::endl;
auto& sinr = std::get<0>(CBS.second);
auto& bler = std::get<1>(CBS.second);
std::vector<std::vector<double>> interpVals = interpolarPuntos(sinr, bler, num_values);
auto sinrvector = interpVals.front();
auto blervectro = interpVals.back();
outfile << "\t NrEesmErrorModel::DoubleTuple{" << std::endl;
outfile << "\t {";
bool found_last = false;
for (const auto& sinrval : sinrvector)
{
if (sinrval == sinrvector.back() and !found_last)
{
outfile << std::setprecision(6) << std::scientific << sinrval;
found_last = true;
}
else if (found_last)
{
outfile << ", " << std::setprecision(6) << std::scientific << sinrval;
}
else
{
outfile << std::setprecision(6) << std::scientific << sinrval << ", ";
}
}
found_last = false;
outfile << "}, // SINR \n\t {";
for (const auto& blerval : blervectro)
{
if (blerval == blervectro.back() and !found_last)
{
outfile << std::setprecision(6) << std::scientific << blerval;
found_last = true;
}
else if (found_last)
{
outfile << ", " << std::setprecision(6) << std::scientific << blerval;
}
else
{
outfile << std::setprecision(6) << std::scientific << blerval << ", ";
}
}
outfile << "} // BLER" << std::endl;
outfile << "\t }" << std::endl;
outfile << "\t }," << std::endl;
}
outfile << "\t }," << std::endl;
mcsIndex++;
}
mcsIndex = 0;
outfile << "}," << std::endl;
BsgIndex++;
}
outfile << "};" << std::endl;
outfile << endstring << std::endl;
outfile << "// Interpolated with n=" << num_values << " samples.";
return 0;
}
std::vector<std::vector<double>> interpolarPuntos(const std::vector<double>& X, const std::vector<double>& Y, int n) {
std::vector<double> sinrInterpolados;
std::vector<double> blerInterpolados;
int numPuntos = X.size();
double incremento = (X[numPuntos - 1] - X[0]) / (n + 1);
if (X.size() < 2)
{
std::vector<std::vector<double>> puntosInterpolados;
puntosInterpolados.push_back(X);
puntosInterpolados.push_back(Y);
return puntosInterpolados;
}
// Agregar el primer punto original
sinrInterpolados.push_back(X[0]);
blerInterpolados.push_back(Y[0]);
for (int i = 0; i < n; i++) {
double xNuevo = X[0] + (i + 1) * incremento;
// Encontrar los puntos de referencia más cercanos
int j = 0;
while (X[j] < xNuevo) {
j++;
}
double x1 = X[j - 1];
double x2 = X[j];
double y1 = Y[j - 1];
double y2 = Y[j];
// Interpolación lineal
double yNuevo = y1 + (y2 - y1) * (xNuevo - x1) / (x2 - x1);
// Agregar el punto interpolado al vector de puntos
sinrInterpolados.push_back(xNuevo);
blerInterpolados.push_back(yNuevo);
}
// Agregar el último punto original
sinrInterpolados.push_back(X[numPuntos - 1]);
blerInterpolados.push_back(Y[numPuntos - 1]);
std::vector<std::vector<double>> puntosInterpolados;
puntosInterpolados.push_back(sinrInterpolados);
puntosInterpolados.push_back(blerInterpolados);
return puntosInterpolados;
}