-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibEDM_channels.cpp
386 lines (325 loc) · 11.7 KB
/
libEDM_channels.cpp
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
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>
#include <fstream>
#include <libEDM_channels.h>
#include <libEDM_fft.h>
#include <libEDM_matrix.h>
using std::abs;
using std::cos;
using std::norm;
using std::polar;
//
// class AWGNChannel
//
dVector AWGNChannel::operator()(const dVector &input)
{
dVector output;
for (size_t i=0; i<input.size(); i++)
output.push_back(input[i] + globalRandom.gaussian(0.0, awgnStdDev));
return output;
}
cVector AWGNChannel::operator()(const cVector &input)
{
cVector output;
for (size_t i=0; i<input.size(); i++)
output.push_back(input[i] + globalRandom.complex_gaussian(0.0, awgnStdDev));
return output;
}
//
// class RayleighFadingProcess
//
cVector RayleighFadingProcess::operator() (const cVector &input, cVector &channel)
{
channel = compute_channel(input.size());
cVector output = input * channel;
return output;
}
//
// class SinusoidRFP
//
SinusoidRFP::SinusoidRFP (const double normalisedDoppler, const double weight, const size_t numSinusoids)
: _numSinusoids(numSinusoids), _index(0), _amplitude(weight / sqrt(static_cast<double>(_numSinusoids)))
{
_frequencies.resize(numSinusoids, 0.0);
for (size_t i=0; i<_numSinusoids; i++)
_frequencies[i] = -2.0 * M_PI * normalisedDoppler * cos(globalRandom.angle());
_phaseOffsets.resize(numSinusoids, 0.0);
for (size_t i=0; i<_numSinusoids; i++)
_phaseOffsets[i] = globalRandom.angle();
}
cVector SinusoidRFP::compute_channel (const size_t numSamples)
{
cVector channel(numSamples, 0.0);
for (size_t i=0; i<_numSinusoids; i++)
for (size_t n=0; n<numSamples; n++)
{
const double phase = _frequencies[i]*(_index+n) - _phaseOffsets[i];
channel[n] += polar(_amplitude, phase);
}
_index += numSamples;
return channel;
}
//
// class FilteredRFP
//
cVector FilteredRFP::compute_channel (const size_t numSamples)
{
// compute complex gaussian noise samples
cVector gaussianNoise;
for (size_t i=0; i<numSamples; i++)
gaussianNoise.push_back(globalRandom.complex_gaussian());
// compute channel by filtering gaussian noise and return
return _fadingFilter(gaussianNoise);
}
dVector FilteredRFP::coefficients (const size_t numTaps, const double normalisedDoppler, const double weight) const
{
dVector coefficients(numTaps);
const size_t centreTap = (numTaps - 1) / 2;
const double constant = pow(normalisedDoppler * M_1_PI, 0.25) * gam(0.75);
for (size_t n=0; n<numTaps; n++)
{
if ( n != centreTap )
{
const double temp = fabs(static_cast<double>(n) - centreTap);
coefficients[n] = constant * pow(temp, -0.25) * jv(0.25, 2.0 * M_PI * normalisedDoppler * temp);
}
else
coefficients[n] = sqrt(normalisedDoppler) * gam(0.75) / gam(1.25);
coefficients[n] *= weight;
}
return coefficients;
}
// class OFDMChannel
OFDMChannel::OFDMChannel (const Model model, const double speed_kmh, const double frequency_Hz) : doppler(speed_kmh * frequency_Hz / (3.6 * 299792458.0)), _time(0.0)
{
switch ( model )
{
case WINNER_SISO_URBAN_MACRO :
_tapDelays .resize(18);
_tapWeights.resize(18);
for (size_t path = 0; path < 6; path++)
{
double pathWeight_dB;
double pathDelay_s;
switch ( path )
{
case 0:
pathWeight_dB = 0.0;
pathDelay_s = 0.0;
break;
case 1:
pathWeight_dB = -1.425;
pathDelay_s = 467.0E-9;
break;
case 2:
pathWeight_dB = -4.217;
pathDelay_s = 1127.0E-9;
break;
case 3:
pathWeight_dB = -7.852;
pathDelay_s = 1981.0E-9;
break;
case 4:
pathWeight_dB = -12.037;
pathDelay_s = 3031.0E-9;
break;
case 5:
pathWeight_dB = -14.919;
pathDelay_s = 4908.0E-9;
break;
}
for (size_t subpath = 0; subpath < 3; subpath++)
{
double subpathWeight_dB;
double subpathDelay_s;
switch ( subpath )
{
case 0:
subpathWeight_dB = -3.031;
subpathDelay_s = 0.0E-9;
break;
case 1:
subpathWeight_dB = -5.229;
subpathDelay_s = 7.0E-9;
break;
case 2:
subpathWeight_dB = -6.990;
subpathDelay_s = 27.0E-9;
break;
}
_tapWeights[path*3 + subpath] = pow(10.0, 0.05 * (pathWeight_dB + subpathWeight_dB));
_tapDelays [path*3 + subpath] = pathDelay_s + subpathDelay_s;
}
}
break;
case WINNER_SISO_URBAN_MICRO:
_tapDelays .resize(24);
_tapWeights.resize(24);
for (size_t path = 0; path < 6; path++)
{
double pathWeight_dB;
double pathDelay_s;
switch ( path )
{
case 0:
pathWeight_dB = 0.0;
pathDelay_s = 0.0;
break;
case 1:
pathWeight_dB = -0.783;
pathDelay_s = 261.0E-9;
break;
case 2:
pathWeight_dB = -2.775;
pathDelay_s = 429.0E-9;
break;
case 3:
pathWeight_dB = -4.605;
pathDelay_s = 608.0E-9;
break;
case 4:
pathWeight_dB = -5.513;
pathDelay_s = 811.0E-9;
break;
case 5:
pathWeight_dB = -7.658;
pathDelay_s = 1019.0E-9;
break;
}
for (size_t subpath = 0; subpath < 4; subpath++)
{
double subpathWeight_dB;
double subpathDelay_s;
switch ( subpath )
{
case 0:
subpathWeight_dB = -4.559;
subpathDelay_s = 0.0E-9;
break;
case 1:
subpathWeight_dB = -6.021;
subpathDelay_s = 5.0E-9;
break;
case 2:
subpathWeight_dB = -6.990;
subpathDelay_s = 11.0E-9;
break;
case 3:
subpathWeight_dB = -6.990;
subpathDelay_s = 28.0E-9;
break;
}
_tapWeights[path*4 + subpath] = pow(10.0, 0.05 * (pathWeight_dB + subpathWeight_dB));
_tapDelays [path*4 + subpath] = pathDelay_s + subpathDelay_s;
}
}
break;
}
// normalise tapWeights
_tapWeights / _tapWeights.sum_of_squares();
// initialise Rayleigh fading taps
for (size_t i=0; i<_tapDelays.size(); i++)
_taps.push_back(new RayleighFadingProcess(doppler, _tapWeights[i], _tapDelays[i]));
}
double OFDMChannel::frequency_response (const double frequency_Hz) const
{
complex<double> voltageGain = complex<double>(0.0,0.0);
for (size_t tap = 0; tap < _taps.size(); tap++)
voltageGain += _taps[tap]->gain() * polar(1.0, -2.0 * M_PI * frequency_Hz * _taps[tap]->delay);
return norm(voltageGain);
}
dVector OFDMChannel::frequency_response (const double startFrequency_Hz, const double stepFrequency_Hz, const size_t numFrequencies) const
{
dVector powerGains(numFrequencies);
for (size_t index = 0; index < numFrequencies; index++)
powerGains[index] = frequency_response(startFrequency_Hz + stepFrequency_Hz * index);
return powerGains;
}
dVector OFDMChannel::frequency_response (const double frequencyInterval_Hz, const double timeInterval_s) const
{
size_t numPoints = round(1.0 / (frequencyInterval_Hz * timeInterval_s));
// sample impulse response with resolution timeInterval_s
cVector impulseResponse(numPoints, complex<double>(0.0,0.0));
for (size_t tap = 0; tap < _taps.size(); tap++)
{
size_t bin = round(_taps[tap]->delay / timeInterval_s);
if ( impulseResponse[bin] == complex<double>(0.0,0.0) )
impulseResponse[bin] = _taps[tap]->gain();
else
impulseResponse[bin] = sqrt(sqr(impulseResponse[bin]) + sqr(_taps[tap]->gain()));
}
cVector fft = FFT::fft(impulseResponse, true);
return norm(fft);
}
void OFDMChannel::set_time (const double time)
{
_time = time;
for (size_t i=0; i<_taps.size(); i++)
_taps[i]->update(time);
}
OFDMChannel::RayleighFadingProcess::RayleighFadingProcess (const double doppler, const double weight, const double delay, const size_t numSinusoids)
: _numSinusoids(numSinusoids), _amplitude(weight / sqrt(static_cast<double>(_numSinusoids))), delay(delay), _time(-1.0)
{
_frequencies.resize(numSinusoids, 0.0);
for (size_t i=0; i<_numSinusoids; i++)
_frequencies[i] = -2.0 * M_PI * doppler * cos(globalRandom.angle());
_phaseOffsets.resize(numSinusoids, 0.0);
for (size_t i=0; i<_numSinusoids; i++)
_phaseOffsets[i] = globalRandom.angle();
update(0.0);
}
void OFDMChannel::RayleighFadingProcess::update (const double time)
{
if (time != _time)
{
_time = time;
_gain = complex<double>(0.0,0.0);
for (size_t i=0; i<_numSinusoids; i++)
{
const double phase = _frequencies[i]*time - _phaseOffsets[i];
_gain += polar(_amplitude, phase);
}
}
}
/*
cVector MultipathRayleighChannel::operator()(const cVector &input, cMatrix &channel)
{
const size_t length = input.size();
const size_t maxDelay = tapDelays.back();
cVector output(length + maxDelay);
const size_t fftSize = pow(2.0, ceil(log2(length)));
const size_t numNoiseSamples = ceil(normalisedDoppler * fftSize);
dVector F(fftSize);
F.ramp(0.0, 1.0 / fftSize, 1.0, 0.5);
cVector S(fftSize, 0.0);
double norm = 0.0;
for (size_t i=0; i<fftSize; i++)
if ( fabs(F[i]) < normalisedDoppler )
{
const double temp = 1.5 / (M_PI * normalisedDoppler * sqrt(1.0-sqr(F[i]/normalisedDoppler)));
norm += temp;
S[i] = sqrt(temp) * fftSize;
}
S /= norm;
channel.set_size(tapDelays.size(), length, 0.0);
for (size_t i=0; i<tapDelays.size(); i++)
{
cVector randomSamples;
for (size_t j=0; j<numNoiseSamples; j++)
randomSamples.push_back(globalRandom.complex_gaussian());
for (size_t j=0; j<fftSize - 2*numNoiseSamples; j++)
randomSamples.push_back(0.0);
for (size_t j=0; j<numNoiseSamples; j++)
randomSamples.push_back(globalRandom.complex_gaussian());
cVector x = FFT::ifft(S * randomSamples);
cVector y = x.mid(0,length);
for (size_t j=0; j<length; j++)
channel[i][j] = y[j] * normalisedLinearTapWeigths[i];
cVector tapContribution(length + maxDelay);
tapContribution.replace_mid(tapDelays[i], input * channel[i]);
output += tapContribution;
}
return AWGNChannel::operator ()(output);
}
*/