A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-channel-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
3 * University of Padova
4 * Copyright (c) 2015, NYU WIRELESS, Tandon School of Engineering,
5 * New York University
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
23
24#include "ns3/double.h"
25#include "ns3/integer.h"
26#include "ns3/log.h"
27#include "ns3/mobility-model.h"
28#include "ns3/node.h"
29#include "ns3/phased-array-model.h"
30#include "ns3/pointer.h"
31#include "ns3/string.h"
32#include <ns3/simulator.h>
33
34#include <algorithm>
35#include <map>
36#include <random>
37
38namespace ns3
39{
40
41NS_LOG_COMPONENT_DEFINE("ThreeGppChannelModel");
42
43NS_OBJECT_ENSURE_REGISTERED(ThreeGppChannelModel);
44
46static constexpr double DEG2RAD = M_PI / 180.0;
47
50static const double offSetAlpha[20] = {
51 0.0447, -0.0447, 0.1413, -0.1413, 0.2492, -0.2492, 0.3715, -0.3715, 0.5129, -0.5129,
52 0.6797, -0.6797, 0.8844, -0.8844, 1.1481, -1.1481, 1.5195, -1.5195, 2.1551, -2.1551,
53};
54
63static const double sqrtC_RMa_LOS[7][7] = {
64 {1, 0, 0, 0, 0, 0, 0},
65 {0, 1, 0, 0, 0, 0, 0},
66 {-0.5, 0, 0.866025, 0, 0, 0, 0},
67 {0, 0, 0, 1, 0, 0, 0},
68 {0, 0, 0, 0, 1, 0, 0},
69 {0.01, 0, -0.0519615, 0.73, -0.2, 0.651383, 0},
70 {-0.17, -0.02, 0.21362, -0.14, 0.24, 0.142773, 0.909661},
71};
72
82static const double sqrtC_RMa_NLOS[6][6] = {
83 {1, 0, 0, 0, 0, 0},
84 {-0.5, 0.866025, 0, 0, 0, 0},
85 {0.6, -0.11547, 0.791623, 0, 0, 0},
86 {0, 0, 0, 1, 0, 0},
87 {-0.04, -0.138564, 0.540662, -0.18, 0.809003, 0},
88 {-0.25, -0.606218, -0.240013, 0.26, -0.231685, 0.625392},
89};
90
99static const double sqrtC_RMa_O2I[6][6] = {
100 {1, 0, 0, 0, 0, 0},
101 {0, 1, 0, 0, 0, 0},
102 {0, 0, 1, 0, 0, 0},
103 {0, 0, -0.7, 0.714143, 0, 0},
104 {0, 0, 0.66, -0.123225, 0.741091, 0},
105 {0, 0, 0.47, 0.152631, -0.393194, 0.775373},
106};
107
116static const double sqrtC_UMa_LOS[7][7] = {
117 {1, 0, 0, 0, 0, 0, 0},
118 {0, 1, 0, 0, 0, 0, 0},
119 {-0.4, -0.4, 0.824621, 0, 0, 0, 0},
120 {-0.5, 0, 0.242536, 0.83137, 0, 0, 0},
121 {-0.5, -0.2, 0.630593, -0.484671, 0.278293, 0, 0},
122 {0, 0, -0.242536, 0.672172, 0.642214, 0.27735, 0},
123 {-0.8, 0, -0.388057, -0.367926, 0.238537, -3.58949e-15, 0.130931},
124};
125
135static const double sqrtC_UMa_NLOS[6][6] = {
136 {1, 0, 0, 0, 0, 0},
137 {-0.4, 0.916515, 0, 0, 0, 0},
138 {-0.6, 0.174574, 0.78072, 0, 0, 0},
139 {0, 0.654654, 0.365963, 0.661438, 0, 0},
140 {0, -0.545545, 0.762422, 0.118114, 0.327327, 0},
141 {-0.4, -0.174574, -0.396459, 0.392138, 0.49099, 0.507445},
142};
143
152static const double sqrtC_UMa_O2I[6][6] = {
153 {1, 0, 0, 0, 0, 0},
154 {-0.5, 0.866025, 0, 0, 0, 0},
155 {0.2, 0.57735, 0.791623, 0, 0, 0},
156 {0, 0.46188, -0.336861, 0.820482, 0, 0},
157 {0, -0.69282, 0.252646, 0.493742, 0.460857, 0},
158 {0, -0.23094, 0.16843, 0.808554, -0.220827, 0.464515},
159
160};
161
170static const double sqrtC_UMi_LOS[7][7] = {
171 {1, 0, 0, 0, 0, 0, 0},
172 {0.5, 0.866025, 0, 0, 0, 0, 0},
173 {-0.4, -0.57735, 0.711805, 0, 0, 0, 0},
174 {-0.5, 0.057735, 0.468293, 0.726201, 0, 0, 0},
175 {-0.4, -0.11547, 0.805464, -0.23482, 0.350363, 0, 0},
176 {0, 0, 0, 0.688514, 0.461454, 0.559471, 0},
177 {0, 0, 0.280976, 0.231921, -0.490509, 0.11916, 0.782603},
178};
179
189static const double sqrtC_UMi_NLOS[6][6] = {
190 {1, 0, 0, 0, 0, 0},
191 {-0.7, 0.714143, 0, 0, 0, 0},
192 {0, 0, 1, 0, 0, 0},
193 {-0.4, 0.168034, 0, 0.90098, 0, 0},
194 {0, -0.70014, 0.5, 0.130577, 0.4927, 0},
195 {0, 0, 0.5, 0.221981, -0.566238, 0.616522},
196};
197
206static const double sqrtC_UMi_O2I[6][6] = {
207 {1, 0, 0, 0, 0, 0},
208 {-0.5, 0.866025, 0, 0, 0, 0},
209 {0.2, 0.57735, 0.791623, 0, 0, 0},
210 {0, 0.46188, -0.336861, 0.820482, 0, 0},
211 {0, -0.69282, 0.252646, 0.493742, 0.460857, 0},
212 {0, -0.23094, 0.16843, 0.808554, -0.220827, 0.464515},
213};
214
223static const double sqrtC_office_LOS[7][7] = {
224 {1, 0, 0, 0, 0, 0, 0},
225 {0.5, 0.866025, 0, 0, 0, 0, 0},
226 {-0.8, -0.11547, 0.588784, 0, 0, 0, 0},
227 {-0.4, 0.23094, 0.520847, 0.717903, 0, 0, 0},
228 {-0.5, 0.288675, 0.73598, -0.348236, 0.0610847, 0, 0},
229 {0.2, -0.11547, 0.418943, 0.541106, 0.219905, 0.655744, 0},
230 {0.3, -0.057735, 0.73598, -0.348236, 0.0610847, -0.304997, 0.383375},
231};
232
242static const double sqrtC_office_NLOS[6][6] = {
243 {1, 0, 0, 0, 0, 0},
244 {-0.5, 0.866025, 0, 0, 0, 0},
245 {0, 0.46188, 0.886942, 0, 0, 0},
246 {-0.4, -0.23094, 0.120263, 0.878751, 0, 0},
247 {0, -0.311769, 0.55697, -0.249198, 0.728344, 0},
248 {0, -0.069282, 0.295397, 0.430696, 0.468462, 0.709214},
249};
250
252{
253 NS_LOG_FUNCTION(this);
254 m_uniformRv = CreateObject<UniformRandomVariable>();
255 m_uniformRvShuffle = CreateObject<UniformRandomVariable>();
256 m_uniformRvDoppler = CreateObject<UniformRandomVariable>();
257
258 m_normalRv = CreateObject<NormalRandomVariable>();
259 m_normalRv->SetAttribute("Mean", DoubleValue(0.0));
260 m_normalRv->SetAttribute("Variance", DoubleValue(1.0));
261}
262
264{
265 NS_LOG_FUNCTION(this);
266}
267
268void
270{
271 NS_LOG_FUNCTION(this);
273 {
274 m_channelConditionModel->Dispose();
275 }
276 m_channelMatrixMap.clear();
277 m_channelParamsMap.clear();
278 m_channelConditionModel = nullptr;
279}
280
281TypeId
283{
284 static TypeId tid =
285 TypeId("ns3::ThreeGppChannelModel")
286 .SetGroupName("Spectrum")
288 .AddConstructor<ThreeGppChannelModel>()
289 .AddAttribute("Frequency",
290 "The operating Frequency in Hz",
291 DoubleValue(500.0e6),
294 MakeDoubleChecker<double>())
295 .AddAttribute(
296 "Scenario",
297 "The 3GPP scenario (RMa, UMa, UMi-StreetCanyon, InH-OfficeOpen, InH-OfficeMixed)",
298 StringValue("UMa"),
302 .AddAttribute("ChannelConditionModel",
303 "Pointer to the channel condition model",
304 PointerValue(),
307 MakePointerChecker<ChannelConditionModel>())
308 .AddAttribute("UpdatePeriod",
309 "Specify the channel coherence time",
313 // attributes for the blockage model
314 .AddAttribute("Blockage",
315 "Enable blockage model A (sec 7.6.4.1)",
316 BooleanValue(false),
319 .AddAttribute("NumNonselfBlocking",
320 "number of non-self-blocking regions",
321 IntegerValue(4),
323 MakeIntegerChecker<uint16_t>())
324 .AddAttribute("PortraitMode",
325 "true for portrait mode, false for landscape mode",
326 BooleanValue(true),
329 .AddAttribute("BlockerSpeed",
330 "The speed of moving blockers, the unit is m/s",
331 DoubleValue(1),
333 MakeDoubleChecker<double>())
334 .AddAttribute("vScatt",
335 "Maximum speed of the vehicle in the layout (see 3GPP TR 37.885 v15.3.0, "
336 "Sec. 6.2.3)."
337 "Used to compute the additional contribution for the Doppler of"
338 "delayed (reflected) paths",
339 DoubleValue(0.0),
341 MakeDoubleChecker<double>(0.0))
342
343 ;
344 return tid;
345}
346
347void
349{
350 NS_LOG_FUNCTION(this);
352}
353
356{
357 NS_LOG_FUNCTION(this);
359}
360
361void
363{
364 NS_LOG_FUNCTION(this);
365 NS_ASSERT_MSG(f >= 500.0e6 && f <= 100.0e9,
366 "Frequency should be between 0.5 and 100 GHz but is " << f);
367 m_frequency = f;
368}
369
370double
372{
373 NS_LOG_FUNCTION(this);
374 return m_frequency;
375}
376
377void
378ThreeGppChannelModel::SetScenario(const std::string& scenario)
379{
380 NS_LOG_FUNCTION(this);
381 NS_ASSERT_MSG(scenario == "RMa" || scenario == "UMa" || scenario == "UMi-StreetCanyon" ||
382 scenario == "InH-OfficeOpen" || scenario == "InH-OfficeMixed" ||
383 scenario == "V2V-Urban" || scenario == "V2V-Highway",
384 "Unknown scenario, choose between: RMa, UMa, UMi-StreetCanyon, "
385 "InH-OfficeOpen, InH-OfficeMixed, V2V-Urban or V2V-Highway");
386 m_scenario = scenario;
387}
388
389std::string
391{
392 NS_LOG_FUNCTION(this);
393 return m_scenario;
394}
395
398 double hBS,
399 double hUT,
400 double distance2D) const
401{
402 NS_LOG_FUNCTION(this);
403
404 double fcGHz = m_frequency / 1.0e9;
405 Ptr<ParamsTable> table3gpp = Create<ParamsTable>();
406 // table3gpp includes the following parameters:
407 // numOfCluster, raysPerCluster, uLgDS, sigLgDS, uLgASD, sigLgASD,
408 // uLgASA, sigLgASA, uLgZSA, sigLgZSA, uLgZSD, sigLgZSD, offsetZOD,
409 // cDS, cASD, cASA, cZSA, uK, sigK, rTau, uXpr, sigXpr, shadowingStd
410
411 bool los = channelCondition->IsLos();
412 bool o2i = channelCondition->IsO2i();
413
414 // In NLOS case, parameter uK and sigK are not used and they are set to 0
415 if (m_scenario == "RMa")
416 {
417 if (los && !o2i)
418 {
419 // 3GPP mentioned that 3.91 ns should be used when the Cluster DS (cDS)
420 // entry is N/A.
421 table3gpp->m_numOfCluster = 11;
422 table3gpp->m_raysPerCluster = 20;
423 table3gpp->m_uLgDS = -7.49;
424 table3gpp->m_sigLgDS = 0.55;
425 table3gpp->m_uLgASD = 0.90;
426 table3gpp->m_sigLgASD = 0.38;
427 table3gpp->m_uLgASA = 1.52;
428 table3gpp->m_sigLgASA = 0.24;
429 table3gpp->m_uLgZSA = 0.47;
430 table3gpp->m_sigLgZSA = 0.40;
431 table3gpp->m_uLgZSD = 0.34;
432 table3gpp->m_sigLgZSD =
433 std::max(-1.0, -0.17 * (distance2D / 1000.0) - 0.01 * (hUT - 1.5) + 0.22);
434 table3gpp->m_offsetZOD = 0;
435 table3gpp->m_cDS = 3.91e-9;
436 table3gpp->m_cASD = 2;
437 table3gpp->m_cASA = 3;
438 table3gpp->m_cZSA = 3;
439 table3gpp->m_uK = 7;
440 table3gpp->m_sigK = 4;
441 table3gpp->m_rTau = 3.8;
442 table3gpp->m_uXpr = 12;
443 table3gpp->m_sigXpr = 4;
444 table3gpp->m_perClusterShadowingStd = 3;
445
446 for (uint8_t row = 0; row < 7; row++)
447 {
448 for (uint8_t column = 0; column < 7; column++)
449 {
450 table3gpp->m_sqrtC[row][column] = sqrtC_RMa_LOS[row][column];
451 }
452 }
453 }
454 else if (!los && !o2i)
455 {
456 table3gpp->m_numOfCluster = 10;
457 table3gpp->m_raysPerCluster = 20;
458 table3gpp->m_uLgDS = -7.43;
459 table3gpp->m_sigLgDS = 0.48;
460 table3gpp->m_uLgASD = 0.95;
461 table3gpp->m_sigLgASD = 0.45;
462 table3gpp->m_uLgASA = 1.52;
463 table3gpp->m_sigLgASA = 0.13;
464 table3gpp->m_uLgZSA = 0.58;
465 table3gpp->m_sigLgZSA = 0.37;
466 table3gpp->m_uLgZSD =
467 std::max(-1.0, -0.19 * (distance2D / 1000.0) - 0.01 * (hUT - 1.5) + 0.28);
468 table3gpp->m_sigLgZSD = 0.30;
469 table3gpp->m_offsetZOD = atan((35 - 3.5) / distance2D) - atan((35 - 1.5) / distance2D);
470 table3gpp->m_cDS = 3.91e-9;
471 table3gpp->m_cASD = 2;
472 table3gpp->m_cASA = 3;
473 table3gpp->m_cZSA = 3;
474 table3gpp->m_uK = 0;
475 table3gpp->m_sigK = 0;
476 table3gpp->m_rTau = 1.7;
477 table3gpp->m_uXpr = 7;
478 table3gpp->m_sigXpr = 3;
479 table3gpp->m_perClusterShadowingStd = 3;
480
481 for (uint8_t row = 0; row < 6; row++)
482 {
483 for (uint8_t column = 0; column < 6; column++)
484 {
485 table3gpp->m_sqrtC[row][column] = sqrtC_RMa_NLOS[row][column];
486 }
487 }
488 }
489 else // o2i
490 {
491 table3gpp->m_numOfCluster = 10;
492 table3gpp->m_raysPerCluster = 20;
493 table3gpp->m_uLgDS = -7.47;
494 table3gpp->m_sigLgDS = 0.24;
495 table3gpp->m_uLgASD = 0.67;
496 table3gpp->m_sigLgASD = 0.18;
497 table3gpp->m_uLgASA = 1.66;
498 table3gpp->m_sigLgASA = 0.21;
499 table3gpp->m_uLgZSA = 0.93;
500 table3gpp->m_sigLgZSA = 0.22;
501 table3gpp->m_uLgZSD =
502 std::max(-1.0, -0.19 * (distance2D / 1000.0) - 0.01 * (hUT - 1.5) + 0.28);
503 table3gpp->m_sigLgZSD = 0.30;
504 table3gpp->m_offsetZOD = atan((35 - 3.5) / distance2D) - atan((35 - 1.5) / distance2D);
505 table3gpp->m_cDS = 3.91e-9;
506 table3gpp->m_cASD = 2;
507 table3gpp->m_cASA = 3;
508 table3gpp->m_cZSA = 3;
509 table3gpp->m_uK = 0;
510 table3gpp->m_sigK = 0;
511 table3gpp->m_rTau = 1.7;
512 table3gpp->m_uXpr = 7;
513 table3gpp->m_sigXpr = 3;
514 table3gpp->m_perClusterShadowingStd = 3;
515
516 for (uint8_t row = 0; row < 6; row++)
517 {
518 for (uint8_t column = 0; column < 6; column++)
519 {
520 table3gpp->m_sqrtC[row][column] = sqrtC_RMa_O2I[row][column];
521 }
522 }
523 }
524 }
525 else if (m_scenario == "UMa")
526 {
527 if (los && !o2i)
528 {
529 table3gpp->m_numOfCluster = 12;
530 table3gpp->m_raysPerCluster = 20;
531 table3gpp->m_uLgDS = -6.955 - 0.0963 * log10(fcGHz);
532 table3gpp->m_sigLgDS = 0.66;
533 table3gpp->m_uLgASD = 1.06 + 0.1114 * log10(fcGHz);
534 table3gpp->m_sigLgASD = 0.28;
535 table3gpp->m_uLgASA = 1.81;
536 table3gpp->m_sigLgASA = 0.20;
537 table3gpp->m_uLgZSA = 0.95;
538 table3gpp->m_sigLgZSA = 0.16;
539 table3gpp->m_uLgZSD =
540 std::max(-0.5, -2.1 * distance2D / 1000.0 - 0.01 * (hUT - 1.5) + 0.75);
541 table3gpp->m_sigLgZSD = 0.40;
542 table3gpp->m_offsetZOD = 0;
543 table3gpp->m_cDS = std::max(0.25, -3.4084 * log10(fcGHz) + 6.5622) * 1e-9;
544 table3gpp->m_cASD = 5;
545 table3gpp->m_cASA = 11;
546 table3gpp->m_cZSA = 7;
547 table3gpp->m_uK = 9;
548 table3gpp->m_sigK = 3.5;
549 table3gpp->m_rTau = 2.5;
550 table3gpp->m_uXpr = 8;
551 table3gpp->m_sigXpr = 4;
552 table3gpp->m_perClusterShadowingStd = 3;
553
554 for (uint8_t row = 0; row < 7; row++)
555 {
556 for (uint8_t column = 0; column < 7; column++)
557 {
558 table3gpp->m_sqrtC[row][column] = sqrtC_UMa_LOS[row][column];
559 }
560 }
561 }
562 else
563 {
564 double uLgZSD = std::max(-0.5, -2.1 * distance2D / 1000.0 - 0.01 * (hUT - 1.5) + 0.9);
565
566 double afc = 0.208 * log10(fcGHz) - 0.782;
567 double bfc = 25;
568 double cfc = -0.13 * log10(fcGHz) + 2.03;
569 double efc = 7.66 * log10(fcGHz) - 5.96;
570
571 double offsetZOD = efc - std::pow(10, afc * log10(std::max(bfc, distance2D)) + cfc);
572
573 if (!los && !o2i)
574 {
575 table3gpp->m_numOfCluster = 20;
576 table3gpp->m_raysPerCluster = 20;
577 table3gpp->m_uLgDS = -6.28 - 0.204 * log10(fcGHz);
578 table3gpp->m_sigLgDS = 0.39;
579 table3gpp->m_uLgASD = 1.5 - 0.1144 * log10(fcGHz);
580 table3gpp->m_sigLgASD = 0.28;
581 table3gpp->m_uLgASA = 2.08 - 0.27 * log10(fcGHz);
582 table3gpp->m_sigLgASA = 0.11;
583 table3gpp->m_uLgZSA = -0.3236 * log10(fcGHz) + 1.512;
584 table3gpp->m_sigLgZSA = 0.16;
585 table3gpp->m_uLgZSD = uLgZSD;
586 table3gpp->m_sigLgZSD = 0.49;
587 table3gpp->m_offsetZOD = offsetZOD;
588 table3gpp->m_cDS = std::max(0.25, -3.4084 * log10(fcGHz) + 6.5622) * 1e-9;
589 table3gpp->m_cASD = 2;
590 table3gpp->m_cASA = 15;
591 table3gpp->m_cZSA = 7;
592 table3gpp->m_uK = 0;
593 table3gpp->m_sigK = 0;
594 table3gpp->m_rTau = 2.3;
595 table3gpp->m_uXpr = 7;
596 table3gpp->m_sigXpr = 3;
597 table3gpp->m_perClusterShadowingStd = 3;
598
599 for (uint8_t row = 0; row < 6; row++)
600 {
601 for (uint8_t column = 0; column < 6; column++)
602 {
603 table3gpp->m_sqrtC[row][column] = sqrtC_UMa_NLOS[row][column];
604 }
605 }
606 }
607 else //(o2i)
608 {
609 table3gpp->m_numOfCluster = 12;
610 table3gpp->m_raysPerCluster = 20;
611 table3gpp->m_uLgDS = -6.62;
612 table3gpp->m_sigLgDS = 0.32;
613 table3gpp->m_uLgASD = 1.25;
614 table3gpp->m_sigLgASD = 0.42;
615 table3gpp->m_uLgASA = 1.76;
616 table3gpp->m_sigLgASA = 0.16;
617 table3gpp->m_uLgZSA = 1.01;
618 table3gpp->m_sigLgZSA = 0.43;
619 table3gpp->m_uLgZSD = uLgZSD;
620 table3gpp->m_sigLgZSD = 0.49;
621 table3gpp->m_offsetZOD = offsetZOD;
622 table3gpp->m_cDS = 11e-9;
623 table3gpp->m_cASD = 5;
624 table3gpp->m_cASA = 8;
625 table3gpp->m_cZSA = 3;
626 table3gpp->m_uK = 0;
627 table3gpp->m_sigK = 0;
628 table3gpp->m_rTau = 2.2;
629 table3gpp->m_uXpr = 9;
630 table3gpp->m_sigXpr = 5;
631 table3gpp->m_perClusterShadowingStd = 4;
632
633 for (uint8_t row = 0; row < 6; row++)
634 {
635 for (uint8_t column = 0; column < 6; column++)
636 {
637 table3gpp->m_sqrtC[row][column] = sqrtC_UMa_O2I[row][column];
638 }
639 }
640 }
641 }
642 }
643 else if (m_scenario == "UMi-StreetCanyon")
644 {
645 if (los && !o2i)
646 {
647 table3gpp->m_numOfCluster = 12;
648 table3gpp->m_raysPerCluster = 20;
649 table3gpp->m_uLgDS = -0.24 * log10(1 + fcGHz) - 7.14;
650 table3gpp->m_sigLgDS = 0.38;
651 table3gpp->m_uLgASD = -0.05 * log10(1 + fcGHz) + 1.21;
652 table3gpp->m_sigLgASD = 0.41;
653 table3gpp->m_uLgASA = -0.08 * log10(1 + fcGHz) + 1.73;
654 table3gpp->m_sigLgASA = 0.014 * log10(1 + fcGHz) + 0.28;
655 table3gpp->m_uLgZSA = -0.1 * log10(1 + fcGHz) + 0.73;
656 table3gpp->m_sigLgZSA = -0.04 * log10(1 + fcGHz) + 0.34;
657 table3gpp->m_uLgZSD =
658 std::max(-0.21, -14.8 * distance2D / 1000.0 + 0.01 * std::abs(hUT - hBS) + 0.83);
659 table3gpp->m_sigLgZSD = 0.35;
660 table3gpp->m_offsetZOD = 0;
661 table3gpp->m_cDS = 5e-9;
662 table3gpp->m_cASD = 3;
663 table3gpp->m_cASA = 17;
664 table3gpp->m_cZSA = 7;
665 table3gpp->m_uK = 9;
666 table3gpp->m_sigK = 5;
667 table3gpp->m_rTau = 3;
668 table3gpp->m_uXpr = 9;
669 table3gpp->m_sigXpr = 3;
670 table3gpp->m_perClusterShadowingStd = 3;
671
672 for (uint8_t row = 0; row < 7; row++)
673 {
674 for (uint8_t column = 0; column < 7; column++)
675 {
676 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_LOS[row][column];
677 }
678 }
679 }
680 else
681 {
682 double uLgZSD =
683 std::max(-0.5, -3.1 * distance2D / 1000.0 + 0.01 * std::max(hUT - hBS, 0.0) + 0.2);
684 double offsetZOD = -1 * std::pow(10, -1.5 * log10(std::max(10.0, distance2D)) + 3.3);
685 if (!los && !o2i)
686 {
687 table3gpp->m_numOfCluster = 19;
688 table3gpp->m_raysPerCluster = 20;
689 table3gpp->m_uLgDS = -0.24 * log10(1 + fcGHz) - 6.83;
690 table3gpp->m_sigLgDS = 0.16 * log10(1 + fcGHz) + 0.28;
691 table3gpp->m_uLgASD = -0.23 * log10(1 + fcGHz) + 1.53;
692 table3gpp->m_sigLgASD = 0.11 * log10(1 + fcGHz) + 0.33;
693 table3gpp->m_uLgASA = -0.08 * log10(1 + fcGHz) + 1.81;
694 table3gpp->m_sigLgASA = 0.05 * log10(1 + fcGHz) + 0.3;
695 table3gpp->m_uLgZSA = -0.04 * log10(1 + fcGHz) + 0.92;
696 table3gpp->m_sigLgZSA = -0.07 * log10(1 + fcGHz) + 0.41;
697 table3gpp->m_uLgZSD = uLgZSD;
698 table3gpp->m_sigLgZSD = 0.35;
699 table3gpp->m_offsetZOD = offsetZOD;
700 table3gpp->m_cDS = 11e-9;
701 table3gpp->m_cASD = 10;
702 table3gpp->m_cASA = 22;
703 table3gpp->m_cZSA = 7;
704 table3gpp->m_uK = 0;
705 table3gpp->m_sigK = 0;
706 table3gpp->m_rTau = 2.1;
707 table3gpp->m_uXpr = 8;
708 table3gpp->m_sigXpr = 3;
709 table3gpp->m_perClusterShadowingStd = 3;
710
711 for (uint8_t row = 0; row < 6; row++)
712 {
713 for (uint8_t column = 0; column < 6; column++)
714 {
715 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_NLOS[row][column];
716 }
717 }
718 }
719 else //(o2i)
720 {
721 table3gpp->m_numOfCluster = 12;
722 table3gpp->m_raysPerCluster = 20;
723 table3gpp->m_uLgDS = -6.62;
724 table3gpp->m_sigLgDS = 0.32;
725 table3gpp->m_uLgASD = 1.25;
726 table3gpp->m_sigLgASD = 0.42;
727 table3gpp->m_uLgASA = 1.76;
728 table3gpp->m_sigLgASA = 0.16;
729 table3gpp->m_uLgZSA = 1.01;
730 table3gpp->m_sigLgZSA = 0.43;
731 table3gpp->m_uLgZSD = uLgZSD;
732 table3gpp->m_sigLgZSD = 0.35;
733 table3gpp->m_offsetZOD = offsetZOD;
734 table3gpp->m_cDS = 11e-9;
735 table3gpp->m_cASD = 5;
736 table3gpp->m_cASA = 8;
737 table3gpp->m_cZSA = 3;
738 table3gpp->m_uK = 0;
739 table3gpp->m_sigK = 0;
740 table3gpp->m_rTau = 2.2;
741 table3gpp->m_uXpr = 9;
742 table3gpp->m_sigXpr = 5;
743 table3gpp->m_perClusterShadowingStd = 4;
744
745 for (uint8_t row = 0; row < 6; row++)
746 {
747 for (uint8_t column = 0; column < 6; column++)
748 {
749 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_O2I[row][column];
750 }
751 }
752 }
753 }
754 }
755 else if (m_scenario == "InH-OfficeMixed" || m_scenario == "InH-OfficeOpen")
756 {
757 NS_ASSERT_MSG(!o2i, "The indoor scenario does out support outdoor to indoor");
758 if (los)
759 {
760 table3gpp->m_numOfCluster = 15;
761 table3gpp->m_raysPerCluster = 20;
762 table3gpp->m_uLgDS = -0.01 * log10(1 + fcGHz) - 7.692;
763 table3gpp->m_sigLgDS = 0.18;
764 table3gpp->m_uLgASD = 1.60;
765 table3gpp->m_sigLgASD = 0.18;
766 table3gpp->m_uLgASA = -0.19 * log10(1 + fcGHz) + 1.781;
767 table3gpp->m_sigLgASA = 0.12 * log10(1 + fcGHz) + 0.119;
768 table3gpp->m_uLgZSA = -0.26 * log10(1 + fcGHz) + 1.44;
769 table3gpp->m_sigLgZSA = -0.04 * log10(1 + fcGHz) + 0.264;
770 table3gpp->m_uLgZSD = -1.43 * log10(1 + fcGHz) + 2.228;
771 table3gpp->m_sigLgZSD = 0.13 * log10(1 + fcGHz) + 0.30;
772 table3gpp->m_offsetZOD = 0;
773 table3gpp->m_cDS = 3.91e-9;
774 table3gpp->m_cASD = 5;
775 table3gpp->m_cASA = 8;
776 table3gpp->m_cZSA = 9;
777 table3gpp->m_uK = 7;
778 table3gpp->m_sigK = 4;
779 table3gpp->m_rTau = 3.6;
780 table3gpp->m_uXpr = 11;
781 table3gpp->m_sigXpr = 4;
782 table3gpp->m_perClusterShadowingStd = 6;
783
784 for (uint8_t row = 0; row < 7; row++)
785 {
786 for (uint8_t column = 0; column < 7; column++)
787 {
788 table3gpp->m_sqrtC[row][column] = sqrtC_office_LOS[row][column];
789 }
790 }
791 }
792 else
793 {
794 table3gpp->m_numOfCluster = 19;
795 table3gpp->m_raysPerCluster = 20;
796 table3gpp->m_uLgDS = -0.28 * log10(1 + fcGHz) - 7.173;
797 table3gpp->m_sigLgDS = 0.1 * log10(1 + fcGHz) + 0.055;
798 table3gpp->m_uLgASD = 1.62;
799 table3gpp->m_sigLgASD = 0.25;
800 table3gpp->m_uLgASA = -0.11 * log10(1 + fcGHz) + 1.863;
801 table3gpp->m_sigLgASA = 0.12 * log10(1 + fcGHz) + 0.059;
802 table3gpp->m_uLgZSA = -0.15 * log10(1 + fcGHz) + 1.387;
803 table3gpp->m_sigLgZSA = -0.09 * log10(1 + fcGHz) + 0.746;
804 table3gpp->m_uLgZSD = 1.08;
805 table3gpp->m_sigLgZSD = 0.36;
806 table3gpp->m_offsetZOD = 0;
807 table3gpp->m_cDS = 3.91e-9;
808 table3gpp->m_cASD = 5;
809 table3gpp->m_cASA = 11;
810 table3gpp->m_cZSA = 9;
811 table3gpp->m_uK = 0;
812 table3gpp->m_sigK = 0;
813 table3gpp->m_rTau = 3;
814 table3gpp->m_uXpr = 10;
815 table3gpp->m_sigXpr = 4;
816 table3gpp->m_perClusterShadowingStd = 3;
817
818 for (uint8_t row = 0; row < 6; row++)
819 {
820 for (uint8_t column = 0; column < 6; column++)
821 {
822 table3gpp->m_sqrtC[row][column] = sqrtC_office_NLOS[row][column];
823 }
824 }
825 }
826 }
827 else if (m_scenario == "V2V-Urban")
828 {
829 if (channelCondition->IsLos())
830 {
831 // 3GPP mentioned that 3.91 ns should be used when the Cluster DS (cDS)
832 // entry is N/A.
833 table3gpp->m_numOfCluster = 12;
834 table3gpp->m_raysPerCluster = 20;
835 table3gpp->m_uLgDS = -0.2 * log10(1 + fcGHz) - 7.5;
836 table3gpp->m_sigLgDS = 0.1;
837 table3gpp->m_uLgASD = -0.1 * log10(1 + fcGHz) + 1.6;
838 table3gpp->m_sigLgASD = 0.1;
839 table3gpp->m_uLgASA = -0.1 * log10(1 + fcGHz) + 1.6;
840 table3gpp->m_sigLgASA = 0.1;
841 table3gpp->m_uLgZSA = -0.1 * log10(1 + fcGHz) + 0.73;
842 table3gpp->m_sigLgZSA = -0.04 * log10(1 + fcGHz) + 0.34;
843 table3gpp->m_uLgZSD = -0.1 * log10(1 + fcGHz) + 0.73;
844 table3gpp->m_sigLgZSD = -0.04 * log10(1 + fcGHz) + 0.34;
845 table3gpp->m_offsetZOD = 0;
846 table3gpp->m_cDS = 5;
847 table3gpp->m_cASD = 17;
848 table3gpp->m_cASA = 17;
849 table3gpp->m_cZSA = 7;
850 table3gpp->m_uK = 3.48;
851 table3gpp->m_sigK = 2;
852 table3gpp->m_rTau = 3;
853 table3gpp->m_uXpr = 9;
854 table3gpp->m_sigXpr = 3;
855 table3gpp->m_perClusterShadowingStd = 4;
856
857 for (uint8_t row = 0; row < 7; row++)
858 {
859 for (uint8_t column = 0; column < 7; column++)
860 {
861 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_LOS[row][column];
862 }
863 }
864 }
865 else if (channelCondition->IsNlos())
866 {
867 table3gpp->m_numOfCluster = 19;
868 table3gpp->m_raysPerCluster = 20;
869 table3gpp->m_uLgDS = -0.3 * log10(1 + fcGHz) - 7;
870 table3gpp->m_sigLgDS = 0.28;
871 table3gpp->m_uLgASD = -0.08 * log10(1 + fcGHz) + 1.81;
872 table3gpp->m_sigLgASD = 0.05 * log10(1 + fcGHz) + 0.3;
873 table3gpp->m_uLgASA = -0.08 * log10(1 + fcGHz) + 1.81;
874 table3gpp->m_sigLgASA = 0.05 * log10(1 + fcGHz) + 0.3;
875 table3gpp->m_uLgZSA = -0.04 * log10(1 + fcGHz) + 0.92;
876 table3gpp->m_sigLgZSA = -0.07 * log10(1 + fcGHz) + 0.41;
877 table3gpp->m_uLgZSD = -0.04 * log10(1 + fcGHz) + 0.92;
878 table3gpp->m_sigLgZSD = -0.07 * log10(1 + fcGHz) + 0.41;
879 table3gpp->m_offsetZOD = 0;
880 table3gpp->m_cDS = 11;
881 table3gpp->m_cASD = 22;
882 table3gpp->m_cASA = 22;
883 table3gpp->m_cZSA = 7;
884 table3gpp->m_uK = 0; // N/A
885 table3gpp->m_sigK = 0; // N/A
886 table3gpp->m_rTau = 2.1;
887 table3gpp->m_uXpr = 8;
888 table3gpp->m_sigXpr = 3;
889 table3gpp->m_perClusterShadowingStd = 4;
890
891 for (uint8_t row = 0; row < 6; row++)
892 {
893 for (uint8_t column = 0; column < 6; column++)
894 {
895 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_NLOS[row][column];
896 }
897 }
898 }
899 else if (channelCondition->IsNlosv())
900 {
901 table3gpp->m_numOfCluster = 19;
902 table3gpp->m_raysPerCluster = 20;
903 table3gpp->m_uLgDS = -0.4 * log10(1 + fcGHz) - 7;
904 table3gpp->m_sigLgDS = 0.1;
905 table3gpp->m_uLgASD = -0.1 * log10(1 + fcGHz) + 1.7;
906 table3gpp->m_sigLgASD = 0.1;
907 table3gpp->m_uLgASA = -0.1 * log10(1 + fcGHz) + 1.7;
908 table3gpp->m_sigLgASA = 0.1;
909 table3gpp->m_uLgZSA = -0.04 * log10(1 + fcGHz) + 0.92;
910 table3gpp->m_sigLgZSA = -0.07 * log10(1 + fcGHz) + 0.41;
911 table3gpp->m_uLgZSD = -0.04 * log10(1 + fcGHz) + 0.92;
912 table3gpp->m_sigLgZSD = -0.07 * log10(1 + fcGHz) + 0.41;
913 table3gpp->m_offsetZOD = 0;
914 table3gpp->m_cDS = 11;
915 table3gpp->m_cASD = 22;
916 table3gpp->m_cASA = 22;
917 table3gpp->m_cZSA = 7;
918 table3gpp->m_uK = 0;
919 table3gpp->m_sigK = 4.5;
920 table3gpp->m_rTau = 2.1;
921 table3gpp->m_uXpr = 8;
922 table3gpp->m_sigXpr = 3;
923 table3gpp->m_perClusterShadowingStd = 4;
924
925 for (uint8_t row = 0; row < 6; row++)
926 {
927 for (uint8_t column = 0; column < 6; column++)
928 {
929 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_LOS[row][column];
930 }
931 }
932 }
933 else
934 {
935 NS_FATAL_ERROR("Unknown channel condition");
936 }
937 }
938 else if (m_scenario == "V2V-Highway")
939 {
940 if (channelCondition->IsLos())
941 {
942 table3gpp->m_numOfCluster = 12;
943 table3gpp->m_raysPerCluster = 20;
944 table3gpp->m_uLgDS = -8.3;
945 table3gpp->m_sigLgDS = 0.2;
946 table3gpp->m_uLgASD = 1.4;
947 table3gpp->m_sigLgASD = 0.1;
948 table3gpp->m_uLgASA = 1.4;
949 table3gpp->m_sigLgASA = 0.1;
950 table3gpp->m_uLgZSA = -0.1 * log10(1 + fcGHz) + 0.73;
951 table3gpp->m_sigLgZSA = -0.04 * log10(1 + fcGHz) + 0.34;
952 table3gpp->m_uLgZSD = -0.1 * log10(1 + fcGHz) + 0.73;
953 table3gpp->m_sigLgZSD = -0.04 * log10(1 + fcGHz) + 0.34;
954 table3gpp->m_offsetZOD = 0;
955 table3gpp->m_cDS = 5;
956 table3gpp->m_cASD = 17;
957 table3gpp->m_cASA = 17;
958 table3gpp->m_cZSA = 7;
959 table3gpp->m_uK = 9;
960 table3gpp->m_sigK = 3.5;
961 table3gpp->m_rTau = 3;
962 table3gpp->m_uXpr = 9;
963 table3gpp->m_sigXpr = 3;
964 table3gpp->m_perClusterShadowingStd = 4;
965
966 for (uint8_t row = 0; row < 7; row++)
967 {
968 for (uint8_t column = 0; column < 7; column++)
969 {
970 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_LOS[row][column];
971 }
972 }
973 }
974 else if (channelCondition->IsNlosv())
975 {
976 table3gpp->m_numOfCluster = 19;
977 table3gpp->m_raysPerCluster = 20;
978 table3gpp->m_uLgDS = -8.3;
979 table3gpp->m_sigLgDS = 0.3;
980 table3gpp->m_uLgASD = 1.5;
981 table3gpp->m_sigLgASD = 0.1;
982 table3gpp->m_uLgASA = 1.5;
983 table3gpp->m_sigLgASA = 0.1;
984 table3gpp->m_uLgZSA = -0.04 * log10(1 + fcGHz) + 0.92;
985 table3gpp->m_sigLgZSA = -0.07 * log10(1 + fcGHz) + 0.41;
986 table3gpp->m_uLgZSD = -0.04 * log10(1 + fcGHz) + 0.92;
987 table3gpp->m_sigLgZSD = -0.07 * log10(1 + fcGHz) + 0.41;
988 table3gpp->m_offsetZOD = 0;
989 table3gpp->m_cDS = 11;
990 table3gpp->m_cASD = 22;
991 table3gpp->m_cASA = 22;
992 table3gpp->m_cZSA = 7;
993 table3gpp->m_uK = 0;
994 table3gpp->m_sigK = 4.5;
995 table3gpp->m_rTau = 2.1;
996 table3gpp->m_uXpr = 8.0;
997 table3gpp->m_sigXpr = 3;
998 table3gpp->m_perClusterShadowingStd = 4;
999
1000 for (uint8_t row = 0; row < 6; row++)
1001 {
1002 for (uint8_t column = 0; column < 6; column++)
1003 {
1004 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_LOS[row][column];
1005 }
1006 }
1007 }
1008 else if (channelCondition->IsNlos())
1009 {
1011 "The fast fading parameters for the NLOS condition in the Highway scenario are not "
1012 "defined in TR 37.885, use the ones defined in TDoc R1-1803671 instead");
1013
1014 table3gpp->m_numOfCluster = 19;
1015 table3gpp->m_raysPerCluster = 20;
1016 table3gpp->m_uLgDS = -0.3 * log10(1 + fcGHz) - 7;
1017 table3gpp->m_sigLgDS = 0.28;
1018 table3gpp->m_uLgASD = -0.08 * log10(1 + fcGHz) + 1.81;
1019 table3gpp->m_sigLgASD = 0.05 * log10(1 + fcGHz) + 0.3;
1020 table3gpp->m_uLgASA = -0.08 * log10(1 + fcGHz) + 1.81;
1021 table3gpp->m_sigLgASA = 0.05 * log10(1 + fcGHz) + 0.3;
1022 table3gpp->m_uLgZSA = -0.04 * log10(1 + fcGHz) + 0.92;
1023 table3gpp->m_sigLgZSA = -0.07 * log10(1 + fcGHz) + 0.41;
1024 table3gpp->m_uLgZSD = -0.04 * log10(1 + fcGHz) + 0.92;
1025 table3gpp->m_sigLgZSD = -0.07 * log10(1 + fcGHz) + 0.41;
1026 table3gpp->m_offsetZOD = 0;
1027 table3gpp->m_cDS = 11;
1028 table3gpp->m_cASD = 22;
1029 table3gpp->m_cASA = 22;
1030 table3gpp->m_cZSA = 7;
1031 table3gpp->m_uK = 0; // N/A
1032 table3gpp->m_sigK = 0; // N/A
1033 table3gpp->m_rTau = 2.1;
1034 table3gpp->m_uXpr = 8;
1035 table3gpp->m_sigXpr = 3;
1036 table3gpp->m_perClusterShadowingStd = 4;
1037
1038 for (uint8_t row = 0; row < 6; row++)
1039 {
1040 for (uint8_t column = 0; column < 6; column++)
1041 {
1042 table3gpp->m_sqrtC[row][column] = sqrtC_UMi_NLOS[row][column];
1043 }
1044 }
1045 }
1046 else
1047 {
1048 NS_FATAL_ERROR("Unknown channel condition");
1049 }
1050 }
1051 else
1052 {
1053 NS_FATAL_ERROR("unknown scenarios");
1054 }
1055
1056 return table3gpp;
1057}
1058
1059bool
1061 Ptr<const ChannelCondition> channelCondition) const
1062{
1063 NS_LOG_FUNCTION(this);
1064
1065 bool update = false;
1066
1067 // if the channel condition is different the channel has to be updated
1068 if (!channelCondition->IsEqual(channelParams->m_losCondition, channelParams->m_o2iCondition))
1069 {
1070 NS_LOG_DEBUG("Update the channel condition");
1071 update = true;
1072 }
1073
1074 // if the coherence time is over the channel has to be updated
1075 if (!m_updatePeriod.IsZero() &&
1076 Simulator::Now() - channelParams->m_generatedTime > m_updatePeriod)
1077 {
1078 NS_LOG_DEBUG("Generation time " << channelParams->m_generatedTime.As(Time::NS) << " now "
1079 << Now().As(Time::NS));
1080 update = true;
1081 }
1082
1083 return update;
1084}
1085
1086bool
1088 Ptr<const ChannelMatrix> channelMatrix)
1089{
1090 return channelParams->m_generatedTime > channelMatrix->m_generatedTime;
1091}
1092
1098{
1099 NS_LOG_FUNCTION(this);
1100
1101 // Compute the channel params key. The key is reciprocal, i.e., key (a, b) = key (b, a)
1102 uint64_t channelParamsKey =
1103 GetKey(aMob->GetObject<Node>()->GetId(), bMob->GetObject<Node>()->GetId());
1104 // Compute the channel matrix key. The key is reciprocal, i.e., key (a, b) = key (b, a)
1105 uint64_t channelMatrixKey = GetKey(aAntenna->GetId(), bAntenna->GetId());
1106
1107 // retrieve the channel condition
1108 Ptr<const ChannelCondition> condition =
1109 m_channelConditionModel->GetChannelCondition(aMob, bMob);
1110
1111 // Check if the channel is present in the map and return it, otherwise
1112 // generate a new channel
1113 bool updateParams = false;
1114 bool updateMatrix = false;
1115 bool notFoundParams = false;
1116 bool notFoundMatrix = false;
1117 Ptr<ChannelMatrix> channelMatrix;
1118 Ptr<ThreeGppChannelParams> channelParams;
1119
1120 if (m_channelParamsMap.find(channelParamsKey) != m_channelParamsMap.end())
1121 {
1122 channelParams = m_channelParamsMap[channelParamsKey];
1123 // check if it has to be updated
1124 updateParams = ChannelParamsNeedsUpdate(channelParams, condition);
1125 }
1126 else
1127 {
1128 NS_LOG_DEBUG("channel params not found");
1129 notFoundParams = true;
1130 }
1131
1132 double x = aMob->GetPosition().x - bMob->GetPosition().x;
1133 double y = aMob->GetPosition().y - bMob->GetPosition().y;
1134 double distance2D = sqrt(x * x + y * y);
1135
1136 // NOTE we assume hUT = min (height(a), height(b)) and
1137 // hBS = max (height (a), height (b))
1138 double hUt = std::min(aMob->GetPosition().z, bMob->GetPosition().z);
1139 double hBs = std::max(aMob->GetPosition().z, bMob->GetPosition().z);
1140
1141 // get the 3GPP parameters
1142 Ptr<const ParamsTable> table3gpp = GetThreeGppTable(condition, hBs, hUt, distance2D);
1143
1144 if (notFoundParams || updateParams)
1145 {
1146 // Step 4: Generate large scale parameters. All LSPS are uncorrelated.
1147 // Step 5: Generate Delays.
1148 // Step 6: Generate cluster powers.
1149 // Step 7: Generate arrival and departure angles for both azimuth and elevation.
1150 // Step 8: Coupling of rays within a cluster for both azimuth and elevation
1151 // shuffle all the arrays to perform random coupling
1152 // Step 9: Generate the cross polarization power ratios
1153 // Step 10: Draw initial phases
1154 channelParams = GenerateChannelParameters(condition, table3gpp, aMob, bMob);
1155 // store or replace the channel parameters
1156 m_channelParamsMap[channelParamsKey] = channelParams;
1157 }
1158
1159 if (m_channelMatrixMap.find(channelMatrixKey) != m_channelMatrixMap.end())
1160 {
1161 // channel matrix present in the map
1162 NS_LOG_DEBUG("channel matrix present in the map");
1163 channelMatrix = m_channelMatrixMap[channelMatrixKey];
1164 updateMatrix = ChannelMatrixNeedsUpdate(channelParams, channelMatrix);
1165 }
1166 else
1167 {
1168 NS_LOG_DEBUG("channel matrix not found");
1169 notFoundMatrix = true;
1170 }
1171
1172 // If the channel is not present in the map or if it has to be updated
1173 // generate a new realization
1174 if (notFoundMatrix || updateMatrix)
1175 {
1176 // channel matrix not found or has to be updated, generate a new one
1177 channelMatrix = GetNewChannel(channelParams, table3gpp, aMob, bMob, aAntenna, bAntenna);
1178 channelMatrix->m_antennaPair =
1179 std::make_pair(aAntenna->GetId(),
1180 bAntenna->GetId()); // save antenna pair, with the exact order of s and u
1181 // antennas at the moment of the channel generation
1182
1183 // store or replace the channel matrix in the channel map
1184 m_channelMatrixMap[channelMatrixKey] = channelMatrix;
1185 }
1186
1187 return channelMatrix;
1188}
1189
1192{
1193 NS_LOG_FUNCTION(this);
1194
1195 // Compute the channel key. The key is reciprocal, i.e., key (a, b) = key (b, a)
1196 uint64_t channelParamsKey =
1197 GetKey(aMob->GetObject<Node>()->GetId(), bMob->GetObject<Node>()->GetId());
1198
1199 if (m_channelParamsMap.find(channelParamsKey) != m_channelParamsMap.end())
1200 {
1201 return m_channelParamsMap.find(channelParamsKey)->second;
1202 }
1203 else
1204 {
1205 NS_LOG_WARN("Channel params map not found. Returning a nullptr.");
1206 return nullptr;
1207 }
1208}
1209
1212 const Ptr<const ParamsTable> table3gpp,
1213 const Ptr<const MobilityModel> aMob,
1214 const Ptr<const MobilityModel> bMob) const
1215{
1216 NS_LOG_FUNCTION(this);
1217 // create a channel matrix instance
1218 Ptr<ThreeGppChannelParams> channelParams = Create<ThreeGppChannelParams>();
1219 channelParams->m_generatedTime = Simulator::Now();
1220 channelParams->m_nodeIds =
1221 std::make_pair(aMob->GetObject<Node>()->GetId(), bMob->GetObject<Node>()->GetId());
1222 channelParams->m_losCondition = channelCondition->GetLosCondition();
1223 channelParams->m_o2iCondition = channelCondition->GetO2iCondition();
1224
1225 // Step 4: Generate large scale parameters. All LSPS are uncorrelated.
1226 DoubleVector LSPsIndep;
1227 DoubleVector LSPs;
1228 uint8_t paramNum = 6;
1229 if (channelParams->m_losCondition == ChannelCondition::LOS)
1230 {
1231 paramNum = 7;
1232 }
1233
1234 // Generate paramNum independent LSPs.
1235 for (uint8_t iter = 0; iter < paramNum; iter++)
1236 {
1237 LSPsIndep.push_back(m_normalRv->GetValue());
1238 }
1239 for (uint8_t row = 0; row < paramNum; row++)
1240 {
1241 double temp = 0;
1242 for (uint8_t column = 0; column < paramNum; column++)
1243 {
1244 temp += table3gpp->m_sqrtC[row][column] * LSPsIndep[column];
1245 }
1246 LSPs.push_back(temp);
1247 }
1248
1249 // NOTE the shadowing is generated in the propagation loss model
1250 double DS;
1251 double ASD;
1252 double ASA;
1253 double ZSA;
1254 double ZSD;
1255 double kFactor = 0;
1256 if (channelParams->m_losCondition == ChannelCondition::LOS)
1257 {
1258 kFactor = LSPs[1] * table3gpp->m_sigK + table3gpp->m_uK;
1259 DS = pow(10, LSPs[2] * table3gpp->m_sigLgDS + table3gpp->m_uLgDS);
1260 ASD = pow(10, LSPs[3] * table3gpp->m_sigLgASD + table3gpp->m_uLgASD);
1261 ASA = pow(10, LSPs[4] * table3gpp->m_sigLgASA + table3gpp->m_uLgASA);
1262 ZSD = pow(10, LSPs[5] * table3gpp->m_sigLgZSD + table3gpp->m_uLgZSD);
1263 ZSA = pow(10, LSPs[6] * table3gpp->m_sigLgZSA + table3gpp->m_uLgZSA);
1264 }
1265 else
1266 {
1267 DS = pow(10, LSPs[1] * table3gpp->m_sigLgDS + table3gpp->m_uLgDS);
1268 ASD = pow(10, LSPs[2] * table3gpp->m_sigLgASD + table3gpp->m_uLgASD);
1269 ASA = pow(10, LSPs[3] * table3gpp->m_sigLgASA + table3gpp->m_uLgASA);
1270 ZSD = pow(10, LSPs[4] * table3gpp->m_sigLgZSD + table3gpp->m_uLgZSD);
1271 ZSA = pow(10, LSPs[5] * table3gpp->m_sigLgZSA + table3gpp->m_uLgZSA);
1272 }
1273 ASD = std::min(ASD, 104.0);
1274 ASA = std::min(ASA, 104.0);
1275 ZSD = std::min(ZSD, 52.0);
1276 ZSA = std::min(ZSA, 52.0);
1277
1278 // save DS and K_factor parameters in the structure
1279 channelParams->m_DS = DS;
1280 channelParams->m_K_factor = kFactor;
1281
1282 NS_LOG_INFO("K-factor=" << kFactor << ", DS=" << DS << ", ASD=" << ASD << ", ASA=" << ASA
1283 << ", ZSD=" << ZSD << ", ZSA=" << ZSA);
1284
1285 // Step 5: Generate Delays.
1286 DoubleVector clusterDelay;
1287 double minTau = 100.0;
1288 for (uint8_t cIndex = 0; cIndex < table3gpp->m_numOfCluster; cIndex++)
1289 {
1290 double tau = -1 * table3gpp->m_rTau * DS * log(m_uniformRv->GetValue(0, 1)); //(7.5-1)
1291 if (minTau > tau)
1292 {
1293 minTau = tau;
1294 }
1295 clusterDelay.push_back(tau);
1296 }
1297
1298 for (uint8_t cIndex = 0; cIndex < table3gpp->m_numOfCluster; cIndex++)
1299 {
1300 clusterDelay[cIndex] -= minTau;
1301 }
1302 std::sort(clusterDelay.begin(), clusterDelay.end()); //(7.5-2)
1303
1304 /* since the scaled Los delays are not to be used in cluster power generation,
1305 * we will generate cluster power first and resume to compute Los cluster delay later.*/
1306
1307 // Step 6: Generate cluster powers.
1308 DoubleVector clusterPower;
1309 double powerSum = 0;
1310 for (uint8_t cIndex = 0; cIndex < table3gpp->m_numOfCluster; cIndex++)
1311 {
1312 double power =
1313 exp(-1 * clusterDelay[cIndex] * (table3gpp->m_rTau - 1) / table3gpp->m_rTau / DS) *
1314 pow(10,
1315 -1 * m_normalRv->GetValue() * table3gpp->m_perClusterShadowingStd / 10.0); //(7.5-5)
1316 powerSum += power;
1317 clusterPower.push_back(power);
1318 }
1319 channelParams->m_clusterPower = clusterPower;
1320
1321 double powerMax = 0;
1322
1323 for (uint8_t cIndex = 0; cIndex < table3gpp->m_numOfCluster; cIndex++)
1324 {
1325 channelParams->m_clusterPower[cIndex] =
1326 channelParams->m_clusterPower[cIndex] / powerSum; //(7.5-6)
1327 }
1328
1329 DoubleVector clusterPowerForAngles; // this power is only for equation (7.5-9) and (7.5-14), not
1330 // for (7.5-22)
1331 if (channelParams->m_losCondition == ChannelCondition::LOS)
1332 {
1333 double kLinear = pow(10, kFactor / 10.0);
1334
1335 for (uint8_t cIndex = 0; cIndex < table3gpp->m_numOfCluster; cIndex++)
1336 {
1337 if (cIndex == 0)
1338 {
1339 clusterPowerForAngles.push_back(channelParams->m_clusterPower[cIndex] /
1340 (1 + kLinear) +
1341 kLinear / (1 + kLinear)); //(7.5-8)
1342 }
1343 else
1344 {
1345 clusterPowerForAngles.push_back(channelParams->m_clusterPower[cIndex] /
1346 (1 + kLinear)); //(7.5-8)
1347 }
1348 if (powerMax < clusterPowerForAngles[cIndex])
1349 {
1350 powerMax = clusterPowerForAngles[cIndex];
1351 }
1352 }
1353 }
1354 else
1355 {
1356 for (uint8_t cIndex = 0; cIndex < table3gpp->m_numOfCluster; cIndex++)
1357 {
1358 clusterPowerForAngles.push_back(channelParams->m_clusterPower[cIndex]); //(7.5-6)
1359 if (powerMax < clusterPowerForAngles[cIndex])
1360 {
1361 powerMax = clusterPowerForAngles[cIndex];
1362 }
1363 }
1364 }
1365
1366 // remove clusters with less than -25 dB power compared to the maxim cluster power;
1367 // double thresh = pow(10, -2.5);
1368 double thresh = 0.0032;
1369 for (uint8_t cIndex = table3gpp->m_numOfCluster; cIndex > 0; cIndex--)
1370 {
1371 if (clusterPowerForAngles[cIndex - 1] < thresh * powerMax)
1372 {
1373 clusterPowerForAngles.erase(clusterPowerForAngles.begin() + cIndex - 1);
1374 channelParams->m_clusterPower.erase(channelParams->m_clusterPower.begin() + cIndex - 1);
1375 clusterDelay.erase(clusterDelay.begin() + cIndex - 1);
1376 }
1377 }
1378
1379 NS_ASSERT(channelParams->m_clusterPower.size() < UINT8_MAX);
1380 channelParams->m_reducedClusterNumber = channelParams->m_clusterPower.size();
1381 // Resume step 5 to compute the delay for LoS condition.
1382 if (channelParams->m_losCondition == ChannelCondition::LOS)
1383 {
1384 double cTau =
1385 0.7705 - 0.0433 * kFactor + 2e-4 * pow(kFactor, 2) + 17e-6 * pow(kFactor, 3); //(7.5-3)
1386 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1387 {
1388 clusterDelay[cIndex] = clusterDelay[cIndex] / cTau; //(7.5-4)
1389 }
1390 }
1391
1392 // Step 7: Generate arrival and departure angles for both azimuth and elevation.
1393
1394 double cNlos;
1395 // According to table 7.5-6, only cluster number equals to 8, 10, 11, 12, 19 and 20 is valid.
1396 // Not sure why the other cases are in Table 7.5-2.
1397 switch (table3gpp->m_numOfCluster) // Table 7.5-2
1398 {
1399 case 4:
1400 cNlos = 0.779;
1401 break;
1402 case 5:
1403 cNlos = 0.860;
1404 break;
1405 case 8:
1406 cNlos = 1.018;
1407 break;
1408 case 10:
1409 cNlos = 1.090;
1410 break;
1411 case 11:
1412 cNlos = 1.123;
1413 break;
1414 case 12:
1415 cNlos = 1.146;
1416 break;
1417 case 14:
1418 cNlos = 1.190;
1419 break;
1420 case 15:
1421 cNlos = 1.221;
1422 break;
1423 case 16:
1424 cNlos = 1.226;
1425 break;
1426 case 19:
1427 cNlos = 1.273;
1428 break;
1429 case 20:
1430 cNlos = 1.289;
1431 break;
1432 default:
1433 NS_FATAL_ERROR("Invalid cluster number");
1434 }
1435
1436 double cPhi = cNlos;
1437
1438 if (channelParams->m_losCondition == ChannelCondition::LOS)
1439 {
1440 cPhi *= (1.1035 - 0.028 * kFactor - 2e-3 * pow(kFactor, 2) +
1441 1e-4 * pow(kFactor, 3)); //(7.5-10))
1442 }
1443
1444 switch (table3gpp->m_numOfCluster) // Table 7.5-4
1445 {
1446 case 8:
1447 cNlos = 0.889;
1448 break;
1449 case 10:
1450 cNlos = 0.957;
1451 break;
1452 case 11:
1453 cNlos = 1.031;
1454 break;
1455 case 12:
1456 cNlos = 1.104;
1457 break;
1458 case 15:
1459 cNlos = 1.1088;
1460 break;
1461 case 19:
1462 cNlos = 1.184;
1463 break;
1464 case 20:
1465 cNlos = 1.178;
1466 break;
1467 default:
1468 NS_FATAL_ERROR("Invalid cluster number");
1469 }
1470
1471 double cTheta = cNlos;
1472 if (channelCondition->IsLos())
1473 {
1474 cTheta *= (1.3086 + 0.0339 * kFactor - 0.0077 * pow(kFactor, 2) +
1475 2e-4 * pow(kFactor, 3)); //(7.5-15)
1476 }
1477
1478 DoubleVector clusterAoa;
1479 DoubleVector clusterAod;
1480 DoubleVector clusterZoa;
1481 DoubleVector clusterZod;
1482 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1483 {
1484 double logCalc = -1 * log(clusterPowerForAngles[cIndex] / powerMax);
1485 double angle = 2 * sqrt(logCalc) / 1.4 / cPhi; //(7.5-9)
1486 clusterAoa.push_back(ASA * angle);
1487 clusterAod.push_back(ASD * angle);
1488 angle = logCalc / cTheta; //(7.5-14)
1489 clusterZoa.push_back(ZSA * angle);
1490 clusterZod.push_back(ZSD * angle);
1491 }
1492
1493 Angles sAngle(bMob->GetPosition(), aMob->GetPosition());
1494 Angles uAngle(aMob->GetPosition(), bMob->GetPosition());
1495
1496 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1497 {
1498 int Xn = 1;
1499 if (m_uniformRv->GetValue(0, 1) < 0.5)
1500 {
1501 Xn = -1;
1502 }
1503 clusterAoa[cIndex] = clusterAoa[cIndex] * Xn + (m_normalRv->GetValue() * ASA / 7.0) +
1504 RadiansToDegrees(uAngle.GetAzimuth()); //(7.5-11)
1505 clusterAod[cIndex] = clusterAod[cIndex] * Xn + (m_normalRv->GetValue() * ASD / 7.0) +
1506 RadiansToDegrees(sAngle.GetAzimuth());
1507 if (channelCondition->IsO2i())
1508 {
1509 clusterZoa[cIndex] =
1510 clusterZoa[cIndex] * Xn + (m_normalRv->GetValue() * ZSA / 7.0) + 90; //(7.5-16)
1511 }
1512 else
1513 {
1514 clusterZoa[cIndex] = clusterZoa[cIndex] * Xn + (m_normalRv->GetValue() * ZSA / 7.0) +
1515 RadiansToDegrees(uAngle.GetInclination()); //(7.5-16)
1516 }
1517 clusterZod[cIndex] = clusterZod[cIndex] * Xn + (m_normalRv->GetValue() * ZSD / 7.0) +
1519 table3gpp->m_offsetZOD; //(7.5-19)
1520 }
1521
1522 if (channelParams->m_losCondition == ChannelCondition::LOS)
1523 {
1524 // The 7.5-12 can be rewrite as Theta_n,ZOA = Theta_n,ZOA - (Theta_1,ZOA - Theta_LOS,ZOA) =
1525 // Theta_n,ZOA - diffZOA, Similar as AOD, ZSA and ZSD.
1526 double diffAoa = clusterAoa[0] - RadiansToDegrees(uAngle.GetAzimuth());
1527 double diffAod = clusterAod[0] - RadiansToDegrees(sAngle.GetAzimuth());
1528 double diffZsa = clusterZoa[0] - RadiansToDegrees(uAngle.GetInclination());
1529 double diffZsd = clusterZod[0] - RadiansToDegrees(sAngle.GetInclination());
1530
1531 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1532 {
1533 clusterAoa[cIndex] -= diffAoa; //(7.5-12)
1534 clusterAod[cIndex] -= diffAod;
1535 clusterZoa[cIndex] -= diffZsa; //(7.5-17)
1536 clusterZod[cIndex] -= diffZsd;
1537 }
1538 }
1539
1540 double sizeTemp = clusterZoa.size();
1541 for (uint8_t ind = 0; ind < 4; ind++)
1542 {
1543 DoubleVector angleDegree;
1544 switch (ind)
1545 {
1546 case 0:
1547 angleDegree = clusterAoa;
1548 break;
1549 case 1:
1550 angleDegree = clusterZoa;
1551 break;
1552 case 2:
1553 angleDegree = clusterAod;
1554 break;
1555 case 3:
1556 angleDegree = clusterZod;
1557 break;
1558 default:
1559 NS_FATAL_ERROR("Programming Error");
1560 }
1561 for (uint8_t nIndex = 0; nIndex < sizeTemp; nIndex++)
1562 {
1563 while (angleDegree[nIndex] > 360)
1564 {
1565 angleDegree[nIndex] -= 360;
1566 }
1567
1568 while (angleDegree[nIndex] < 0)
1569 {
1570 angleDegree[nIndex] += 360;
1571 }
1572
1573 if (ind == 1 || ind == 3)
1574 {
1575 if (angleDegree[nIndex] > 180)
1576 {
1577 angleDegree[nIndex] = 360 - angleDegree[nIndex];
1578 }
1579 }
1580 }
1581 switch (ind)
1582 {
1583 case 0:
1584 clusterAoa = angleDegree;
1585 break;
1586 case 1:
1587 clusterZoa = angleDegree;
1588 break;
1589 case 2:
1590 clusterAod = angleDegree;
1591 break;
1592 case 3:
1593 clusterZod = angleDegree;
1594 break;
1595 default:
1596 NS_FATAL_ERROR("Programming Error");
1597 }
1598 }
1599
1600 DoubleVector attenuationDb;
1601 if (m_blockage)
1602 {
1603 attenuationDb = CalcAttenuationOfBlockage(channelParams, clusterAoa, clusterZoa);
1604 for (uint8_t cInd = 0; cInd < channelParams->m_reducedClusterNumber; cInd++)
1605 {
1606 channelParams->m_clusterPower[cInd] =
1607 channelParams->m_clusterPower[cInd] / pow(10, attenuationDb[cInd] / 10.0);
1608 }
1609 }
1610 else
1611 {
1612 attenuationDb.push_back(0);
1613 }
1614
1615 // store attenuation
1616 channelParams->m_attenuation_dB = attenuationDb;
1617
1618 // Step 8: Coupling of rays within a cluster for both azimuth and elevation
1619 // shuffle all the arrays to perform random coupling
1621 channelParams->m_reducedClusterNumber,
1622 DoubleVector(table3gpp->m_raysPerCluster,
1623 0)); // rayAoaRadian[n][m], where n is cluster index, m is ray index
1625 channelParams->m_reducedClusterNumber,
1626 DoubleVector(table3gpp->m_raysPerCluster,
1627 0)); // rayAodRadian[n][m], where n is cluster index, m is ray index
1629 channelParams->m_reducedClusterNumber,
1630 DoubleVector(table3gpp->m_raysPerCluster,
1631 0)); // rayZoaRadian[n][m], where n is cluster index, m is ray index
1633 channelParams->m_reducedClusterNumber,
1634 DoubleVector(table3gpp->m_raysPerCluster,
1635 0)); // rayZodRadian[n][m], where n is cluster index, m is ray index
1636
1637 for (uint8_t nInd = 0; nInd < channelParams->m_reducedClusterNumber; nInd++)
1638 {
1639 for (uint8_t mInd = 0; mInd < table3gpp->m_raysPerCluster; mInd++)
1640 {
1641 double tempAoa = clusterAoa[nInd] + table3gpp->m_cASA * offSetAlpha[mInd]; //(7.5-13)
1642 double tempZoa = clusterZoa[nInd] + table3gpp->m_cZSA * offSetAlpha[mInd]; //(7.5-18)
1643 std::tie(rayAoaRadian[nInd][mInd], rayZoaRadian[nInd][mInd]) =
1644 WrapAngles(DegreesToRadians(tempAoa), DegreesToRadians(tempZoa));
1645
1646 double tempAod = clusterAod[nInd] + table3gpp->m_cASD * offSetAlpha[mInd]; //(7.5-13)
1647 double tempZod = clusterZod[nInd] +
1648 0.375 * pow(10, table3gpp->m_uLgZSD) * offSetAlpha[mInd]; //(7.5-20)
1649 std::tie(rayAodRadian[nInd][mInd], rayZodRadian[nInd][mInd]) =
1650 WrapAngles(DegreesToRadians(tempAod), DegreesToRadians(tempZod));
1651 }
1652 }
1653
1654 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1655 {
1656 Shuffle(&rayAodRadian[cIndex][0], &rayAodRadian[cIndex][table3gpp->m_raysPerCluster]);
1657 Shuffle(&rayAoaRadian[cIndex][0], &rayAoaRadian[cIndex][table3gpp->m_raysPerCluster]);
1658 Shuffle(&rayZodRadian[cIndex][0], &rayZodRadian[cIndex][table3gpp->m_raysPerCluster]);
1659 Shuffle(&rayZoaRadian[cIndex][0], &rayZoaRadian[cIndex][table3gpp->m_raysPerCluster]);
1660 }
1661
1662 // store values
1663 channelParams->m_rayAodRadian = rayAodRadian;
1664 channelParams->m_rayAoaRadian = rayAoaRadian;
1665 channelParams->m_rayZodRadian = rayZodRadian;
1666 channelParams->m_rayZoaRadian = rayZoaRadian;
1667
1668 // Step 9: Generate the cross polarization power ratios
1669 // Step 10: Draw initial phases
1670 Double2DVector crossPolarizationPowerRatios; // vector containing the cross polarization power
1671 // ratios, as defined by 7.5-21
1672 Double3DVector clusterPhase; // rayAoaRadian[n][m], where n is cluster index, m is ray index
1673 for (uint8_t nInd = 0; nInd < channelParams->m_reducedClusterNumber; nInd++)
1674 {
1675 DoubleVector temp; // used to store the XPR values
1677 temp2; // used to store the PHI values for all the possible combination of polarization
1678 for (uint8_t mInd = 0; mInd < table3gpp->m_raysPerCluster; mInd++)
1679 {
1680 double uXprLinear = pow(10, table3gpp->m_uXpr / 10.0); // convert to linear
1681 double sigXprLinear = pow(10, table3gpp->m_sigXpr / 10.0); // convert to linear
1682
1683 temp.push_back(
1684 std::pow(10, (m_normalRv->GetValue() * sigXprLinear + uXprLinear) / 10.0));
1685 DoubleVector temp3; // used to store the PHI values
1686 for (uint8_t pInd = 0; pInd < 4; pInd++)
1687 {
1688 temp3.push_back(m_uniformRv->GetValue(-1 * M_PI, M_PI));
1689 }
1690 temp2.push_back(temp3);
1691 }
1692 crossPolarizationPowerRatios.push_back(temp);
1693 clusterPhase.push_back(temp2);
1694 }
1695 // store the cluster phase
1696 channelParams->m_clusterPhase = clusterPhase;
1697 channelParams->m_crossPolarizationPowerRatios = crossPolarizationPowerRatios;
1698
1699 uint8_t cluster1st = 0;
1700 uint8_t cluster2nd = 0; // first and second strongest cluster;
1701 double maxPower = 0;
1702 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1703 {
1704 if (maxPower < channelParams->m_clusterPower[cIndex])
1705 {
1706 maxPower = channelParams->m_clusterPower[cIndex];
1707 cluster1st = cIndex;
1708 }
1709 }
1710 channelParams->m_cluster1st = cluster1st;
1711 maxPower = 0;
1712 for (uint8_t cIndex = 0; cIndex < channelParams->m_reducedClusterNumber; cIndex++)
1713 {
1714 if (maxPower < channelParams->m_clusterPower[cIndex] && cluster1st != cIndex)
1715 {
1716 maxPower = channelParams->m_clusterPower[cIndex];
1717 cluster2nd = cIndex;
1718 }
1719 }
1720 channelParams->m_cluster2nd = cluster2nd;
1721
1722 NS_LOG_INFO("1st strongest cluster:" << +cluster1st
1723 << ", 2nd strongest cluster:" << +cluster2nd);
1724
1725 // store the delays and the angles for the subclusters
1726 if (cluster1st == cluster2nd)
1727 {
1728 clusterDelay.push_back(clusterDelay[cluster1st] + 1.28 * table3gpp->m_cDS);
1729 clusterDelay.push_back(clusterDelay[cluster1st] + 2.56 * table3gpp->m_cDS);
1730
1731 clusterAoa.push_back(clusterAoa[cluster1st]);
1732 clusterAoa.push_back(clusterAoa[cluster1st]);
1733
1734 clusterZoa.push_back(clusterZoa[cluster1st]);
1735 clusterZoa.push_back(clusterZoa[cluster1st]);
1736
1737 clusterAod.push_back(clusterAod[cluster1st]);
1738 clusterAod.push_back(clusterAod[cluster1st]);
1739
1740 clusterZod.push_back(clusterZod[cluster1st]);
1741 clusterZod.push_back(clusterZod[cluster1st]);
1742 }
1743 else
1744 {
1745 double min;
1746 double max;
1747 if (cluster1st < cluster2nd)
1748 {
1749 min = cluster1st;
1750 max = cluster2nd;
1751 }
1752 else
1753 {
1754 min = cluster2nd;
1755 max = cluster1st;
1756 }
1757 clusterDelay.push_back(clusterDelay[min] + 1.28 * table3gpp->m_cDS);
1758 clusterDelay.push_back(clusterDelay[min] + 2.56 * table3gpp->m_cDS);
1759 clusterDelay.push_back(clusterDelay[max] + 1.28 * table3gpp->m_cDS);
1760 clusterDelay.push_back(clusterDelay[max] + 2.56 * table3gpp->m_cDS);
1761
1762 clusterAoa.push_back(clusterAoa[min]);
1763 clusterAoa.push_back(clusterAoa[min]);
1764 clusterAoa.push_back(clusterAoa[max]);
1765 clusterAoa.push_back(clusterAoa[max]);
1766
1767 clusterZoa.push_back(clusterZoa[min]);
1768 clusterZoa.push_back(clusterZoa[min]);
1769 clusterZoa.push_back(clusterZoa[max]);
1770 clusterZoa.push_back(clusterZoa[max]);
1771
1772 clusterAod.push_back(clusterAod[min]);
1773 clusterAod.push_back(clusterAod[min]);
1774 clusterAod.push_back(clusterAod[max]);
1775 clusterAod.push_back(clusterAod[max]);
1776
1777 clusterZod.push_back(clusterZod[min]);
1778 clusterZod.push_back(clusterZod[min]);
1779 clusterZod.push_back(clusterZod[max]);
1780 clusterZod.push_back(clusterZod[max]);
1781 }
1782
1783 channelParams->m_delay = clusterDelay;
1784 channelParams->m_angle.clear();
1785 channelParams->m_angle.push_back(clusterAoa);
1786 channelParams->m_angle.push_back(clusterZoa);
1787 channelParams->m_angle.push_back(clusterAod);
1788 channelParams->m_angle.push_back(clusterZod);
1789
1790 // Precompute angles sincos
1791 channelParams->m_cachedAngleSincos.resize(channelParams->m_angle.size());
1792 for (size_t direction = 0; direction < channelParams->m_angle.size(); direction++)
1793 {
1794 channelParams->m_cachedAngleSincos[direction].resize(
1795 channelParams->m_angle[direction].size());
1796 for (size_t cluster = 0; cluster < channelParams->m_angle[direction].size(); cluster++)
1797 {
1798 channelParams->m_cachedAngleSincos[direction][cluster] = {
1799 sin(channelParams->m_angle[direction][cluster] * DEG2RAD),
1800 cos(channelParams->m_angle[direction][cluster] * DEG2RAD)};
1801 }
1802 }
1803
1804 // Compute alpha and D as described in 3GPP TR 37.885 v15.3.0, Sec. 6.2.3
1805 // These terms account for an additional Doppler contribution due to the
1806 // presence of moving objects in the surrounding environment, such as in
1807 // vehicular scenarios.
1808 // This contribution is applied only to the delayed (reflected) paths and
1809 // must be properly configured by setting the value of
1810 // m_vScatt, which is defined as "maximum speed of the vehicle in the
1811 // layout".
1812 // By default, m_vScatt is set to 0, so there is no additional Doppler
1813 // contribution.
1814
1815 DoubleVector dopplerTermAlpha;
1816 DoubleVector dopplerTermD;
1817
1818 // 2 or 4 is added to account for additional subrays for the 1st and 2nd clusters, if there is
1819 // only one cluster then would be added 2 more subrays (see creation of Husn channel matrix)
1820 uint8_t updatedClusterNumber = (channelParams->m_reducedClusterNumber == 1)
1821 ? channelParams->m_reducedClusterNumber + 2
1822 : channelParams->m_reducedClusterNumber + 4;
1823
1824 for (uint8_t cIndex = 0; cIndex < updatedClusterNumber; cIndex++)
1825 {
1826 double alpha = 0;
1827 double D = 0;
1828 if (cIndex != 0)
1829 {
1830 alpha = m_uniformRvDoppler->GetValue(-1, 1);
1832 }
1833 dopplerTermAlpha.push_back(alpha);
1834 dopplerTermD.push_back(D);
1835 }
1836 channelParams->m_alpha = dopplerTermAlpha;
1837 channelParams->m_D = dopplerTermD;
1838
1839 return channelParams;
1840}
1841
1844 Ptr<const ParamsTable> table3gpp,
1845 const Ptr<const MobilityModel> sMob,
1846 const Ptr<const MobilityModel> uMob,
1848 Ptr<const PhasedArrayModel> uAntenna) const
1849{
1850 NS_LOG_FUNCTION(this);
1851
1852 NS_ASSERT_MSG(m_frequency > 0.0, "Set the operating frequency first!");
1853
1854 // create a channel matrix instance
1855 Ptr<ChannelMatrix> channelMatrix = Create<ChannelMatrix>();
1856 channelMatrix->m_generatedTime = Simulator::Now();
1857 // save in which order is generated this matrix
1858 channelMatrix->m_nodeIds =
1859 std::make_pair(sMob->GetObject<Node>()->GetId(), uMob->GetObject<Node>()->GetId());
1860 // check if channelParams structure is generated in direction s-to-u or u-to-s
1861 bool isSameDirection = (channelParams->m_nodeIds == channelMatrix->m_nodeIds);
1862
1867
1868 // if channel params is generated in the same direction in which we
1869 // generate the channel matrix, angles and zenith od departure and arrival are ok,
1870 // just set them to corresponding variable that will be used for the generation
1871 // of channel matrix, otherwise we need to flip angles and zeniths of departure and arrival
1872 if (isSameDirection)
1873 {
1874 rayAodRadian = channelParams->m_rayAodRadian;
1875 rayAoaRadian = channelParams->m_rayAoaRadian;
1876 rayZodRadian = channelParams->m_rayZodRadian;
1877 rayZoaRadian = channelParams->m_rayZoaRadian;
1878 }
1879 else
1880 {
1881 rayAodRadian = channelParams->m_rayAoaRadian;
1882 rayAoaRadian = channelParams->m_rayAodRadian;
1883 rayZodRadian = channelParams->m_rayZoaRadian;
1884 rayZoaRadian = channelParams->m_rayZodRadian;
1885 }
1886
1887 // Step 11: Generate channel coefficients for each cluster n and each receiver
1888 // and transmitter element pair u,s.
1889 // where n is cluster index, u and s are receive and transmit antenna element.
1890 size_t uSize = uAntenna->GetNumElems();
1891 size_t sSize = sAntenna->GetNumElems();
1892
1893 // NOTE: Since each of the strongest 2 clusters are divided into 3 sub-clusters,
1894 // the total cluster will generally be numReducedCLuster + 4.
1895 // However, it might be that m_cluster1st = m_cluster2nd. In this case the
1896 // total number of clusters will be numReducedCLuster + 2.
1897 uint16_t numOverallCluster = (channelParams->m_cluster1st != channelParams->m_cluster2nd)
1898 ? channelParams->m_reducedClusterNumber + 4
1899 : channelParams->m_reducedClusterNumber + 2;
1900 Complex3DVector hUsn(uSize, sSize, numOverallCluster); // channel coefficient hUsn (u, s, n);
1901 NS_ASSERT(channelParams->m_reducedClusterNumber <= channelParams->m_clusterPhase.size());
1902 NS_ASSERT(channelParams->m_reducedClusterNumber <= channelParams->m_clusterPower.size());
1903 NS_ASSERT(channelParams->m_reducedClusterNumber <=
1904 channelParams->m_crossPolarizationPowerRatios.size());
1905 NS_ASSERT(channelParams->m_reducedClusterNumber <= rayZoaRadian.size());
1906 NS_ASSERT(channelParams->m_reducedClusterNumber <= rayZodRadian.size());
1907 NS_ASSERT(channelParams->m_reducedClusterNumber <= rayAoaRadian.size());
1908 NS_ASSERT(channelParams->m_reducedClusterNumber <= rayAodRadian.size());
1909 NS_ASSERT(table3gpp->m_raysPerCluster <= channelParams->m_clusterPhase[0].size());
1910 NS_ASSERT(table3gpp->m_raysPerCluster <=
1911 channelParams->m_crossPolarizationPowerRatios[0].size());
1912 NS_ASSERT(table3gpp->m_raysPerCluster <= rayZoaRadian[0].size());
1913 NS_ASSERT(table3gpp->m_raysPerCluster <= rayZodRadian[0].size());
1914 NS_ASSERT(table3gpp->m_raysPerCluster <= rayAoaRadian[0].size());
1915 NS_ASSERT(table3gpp->m_raysPerCluster <= rayAodRadian[0].size());
1916
1917 double x = sMob->GetPosition().x - uMob->GetPosition().x;
1918 double y = sMob->GetPosition().y - uMob->GetPosition().y;
1919 double distance2D = sqrt(x * x + y * y);
1920 // NOTE we assume hUT = min (height(a), height(b)) and
1921 // hBS = max (height (a), height (b))
1922 double hUt = std::min(sMob->GetPosition().z, uMob->GetPosition().z);
1923 double hBs = std::max(sMob->GetPosition().z, uMob->GetPosition().z);
1924 // compute the 3D distance using eq. 7.4-1
1925 double distance3D = std::sqrt(distance2D * distance2D + (hBs - hUt) * (hBs - hUt));
1926
1927 Angles sAngle(uMob->GetPosition(), sMob->GetPosition());
1928 Angles uAngle(sMob->GetPosition(), uMob->GetPosition());
1929
1930 Double2DVector sinCosA; // cached multiplications of sin and cos of the ZoA and AoA angles
1931 Double2DVector sinSinA; // cached multiplications of sines of the ZoA and AoA angles
1932 Double2DVector cosZoA; // cached cos of the ZoA angle
1933 Double2DVector sinCosD; // cached multiplications of sin and cos of the ZoD and AoD angles
1934 Double2DVector sinSinD; // cached multiplications of the cosines of the ZoA and AoA angles
1935 Double2DVector cosZoD; // cached cos of the ZoD angle
1936
1937 // contains part of the ray expression, cached as independent from the u- and s-indexes,
1938 // but calculate it for different polarization angles of s and u
1939 std::map<std::pair<uint8_t, uint8_t>, Complex2DVector> raysPreComp;
1940 for (size_t polSa = 0; polSa < sAntenna->GetNumPols(); ++polSa)
1941 {
1942 for (size_t polUa = 0; polUa < uAntenna->GetNumPols(); ++polUa)
1943 {
1944 raysPreComp[std::make_pair(polSa, polUa)] =
1945 Complex2DVector(channelParams->m_reducedClusterNumber, table3gpp->m_raysPerCluster);
1946 }
1947 }
1948
1949 // resize to appropriate dimensions
1950 sinCosA.resize(channelParams->m_reducedClusterNumber);
1951 sinSinA.resize(channelParams->m_reducedClusterNumber);
1952 cosZoA.resize(channelParams->m_reducedClusterNumber);
1953 sinCosD.resize(channelParams->m_reducedClusterNumber);
1954 sinSinD.resize(channelParams->m_reducedClusterNumber);
1955 cosZoD.resize(channelParams->m_reducedClusterNumber);
1956 for (uint8_t nIndex = 0; nIndex < channelParams->m_reducedClusterNumber; nIndex++)
1957 {
1958 sinCosA[nIndex].resize(table3gpp->m_raysPerCluster);
1959 sinSinA[nIndex].resize(table3gpp->m_raysPerCluster);
1960 cosZoA[nIndex].resize(table3gpp->m_raysPerCluster);
1961 sinCosD[nIndex].resize(table3gpp->m_raysPerCluster);
1962 sinSinD[nIndex].resize(table3gpp->m_raysPerCluster);
1963 cosZoD[nIndex].resize(table3gpp->m_raysPerCluster);
1964 }
1965 // pre-compute the terms which are independent from uIndex and sIndex
1966 for (uint8_t nIndex = 0; nIndex < channelParams->m_reducedClusterNumber; nIndex++)
1967 {
1968 for (uint8_t mIndex = 0; mIndex < table3gpp->m_raysPerCluster; mIndex++)
1969 {
1970 DoubleVector initialPhase = channelParams->m_clusterPhase[nIndex][mIndex];
1971 NS_ASSERT(4 <= initialPhase.size());
1972 double k = channelParams->m_crossPolarizationPowerRatios[nIndex][mIndex];
1973
1974 // cache the component of the "rays" terms which depend on the random angle of arrivals
1975 // and departures and initial phases only
1976 for (uint8_t polUa = 0; polUa < uAntenna->GetNumPols(); ++polUa)
1977 {
1978 auto [rxFieldPatternPhi, rxFieldPatternTheta] = uAntenna->GetElementFieldPattern(
1979 Angles(channelParams->m_rayAoaRadian[nIndex][mIndex],
1980 channelParams->m_rayZoaRadian[nIndex][mIndex]),
1981 polUa);
1982 for (uint8_t polSa = 0; polSa < sAntenna->GetNumPols(); ++polSa)
1983 {
1984 auto [txFieldPatternPhi, txFieldPatternTheta] =
1985 sAntenna->GetElementFieldPattern(
1986 Angles(channelParams->m_rayAodRadian[nIndex][mIndex],
1987 channelParams->m_rayZodRadian[nIndex][mIndex]),
1988 polSa);
1989 raysPreComp[std::make_pair(polSa, polUa)](nIndex, mIndex) =
1990 std::complex<double>(cos(initialPhase[0]), sin(initialPhase[0])) *
1991 rxFieldPatternTheta * txFieldPatternTheta +
1992 std::complex<double>(cos(initialPhase[1]), sin(initialPhase[1])) *
1993 std::sqrt(1.0 / k) * rxFieldPatternTheta * txFieldPatternPhi +
1994 std::complex<double>(cos(initialPhase[2]), sin(initialPhase[2])) *
1995 std::sqrt(1.0 / k) * rxFieldPatternPhi * txFieldPatternTheta +
1996 std::complex<double>(cos(initialPhase[3]), sin(initialPhase[3])) *
1997 rxFieldPatternPhi * txFieldPatternPhi;
1998 }
1999 }
2000
2001 // cache the component of the "rxPhaseDiff" terms which depend on the random angle of
2002 // arrivals only
2003 double sinRayZoa = sin(rayZoaRadian[nIndex][mIndex]);
2004 double sinRayAoa = sin(rayAoaRadian[nIndex][mIndex]);
2005 double cosRayAoa = cos(rayAoaRadian[nIndex][mIndex]);
2006 sinCosA[nIndex][mIndex] = sinRayZoa * cosRayAoa;
2007 sinSinA[nIndex][mIndex] = sinRayZoa * sinRayAoa;
2008 cosZoA[nIndex][mIndex] = cos(rayZoaRadian[nIndex][mIndex]);
2009
2010 // cache the component of the "txPhaseDiff" terms which depend on the random angle of
2011 // departure only
2012 double sinRayZod = sin(rayZodRadian[nIndex][mIndex]);
2013 double sinRayAod = sin(rayAodRadian[nIndex][mIndex]);
2014 double cosRayAod = cos(rayAodRadian[nIndex][mIndex]);
2015 sinCosD[nIndex][mIndex] = sinRayZod * cosRayAod;
2016 sinSinD[nIndex][mIndex] = sinRayZod * sinRayAod;
2017 cosZoD[nIndex][mIndex] = cos(rayZodRadian[nIndex][mIndex]);
2018 }
2019 }
2020
2021 // The following for loops computes the channel coefficients
2022 // Keeps track of how many sub-clusters have been added up to now
2023 uint8_t numSubClustersAdded = 0;
2024 for (uint8_t nIndex = 0; nIndex < channelParams->m_reducedClusterNumber; nIndex++)
2025 {
2026 for (size_t uIndex = 0; uIndex < uSize; uIndex++)
2027 {
2028 Vector uLoc = uAntenna->GetElementLocation(uIndex);
2029
2030 for (size_t sIndex = 0; sIndex < sSize; sIndex++)
2031 {
2032 Vector sLoc = sAntenna->GetElementLocation(sIndex);
2033 // Compute the N-2 weakest cluster, assuming 0 slant angle and a
2034 // polarization slant angle configured in the array (7.5-22)
2035 if (nIndex != channelParams->m_cluster1st && nIndex != channelParams->m_cluster2nd)
2036 {
2037 std::complex<double> rays(0, 0);
2038 for (uint8_t mIndex = 0; mIndex < table3gpp->m_raysPerCluster; mIndex++)
2039 {
2040 // lambda_0 is accounted in the antenna spacing uLoc and sLoc.
2041 double rxPhaseDiff =
2042 2 * M_PI *
2043 (sinCosA[nIndex][mIndex] * uLoc.x + sinSinA[nIndex][mIndex] * uLoc.y +
2044 cosZoA[nIndex][mIndex] * uLoc.z);
2045
2046 double txPhaseDiff =
2047 2 * M_PI *
2048 (sinCosD[nIndex][mIndex] * sLoc.x + sinSinD[nIndex][mIndex] * sLoc.y +
2049 cosZoD[nIndex][mIndex] * sLoc.z);
2050 // NOTE Doppler is computed in the CalcBeamformingGain function and is
2051 // simplified to only account for the center angle of each cluster.
2052 rays += raysPreComp[std::make_pair(sAntenna->GetElemPol(sIndex),
2053 uAntenna->GetElemPol(uIndex))](nIndex,
2054 mIndex) *
2055 std::complex<double>(cos(rxPhaseDiff), sin(rxPhaseDiff)) *
2056 std::complex<double>(cos(txPhaseDiff), sin(txPhaseDiff));
2057 }
2058 rays *=
2059 sqrt(channelParams->m_clusterPower[nIndex] / table3gpp->m_raysPerCluster);
2060 hUsn(uIndex, sIndex, nIndex) = rays;
2061 }
2062 else //(7.5-28)
2063 {
2064 std::complex<double> raysSub1(0, 0);
2065 std::complex<double> raysSub2(0, 0);
2066 std::complex<double> raysSub3(0, 0);
2067
2068 for (uint8_t mIndex = 0; mIndex < table3gpp->m_raysPerCluster; mIndex++)
2069 {
2070 // ZML:Just remind me that the angle offsets for the 3 subclusters were not
2071 // generated correctly.
2072 double rxPhaseDiff =
2073 2 * M_PI *
2074 (sinCosA[nIndex][mIndex] * uLoc.x + sinSinA[nIndex][mIndex] * uLoc.y +
2075 cosZoA[nIndex][mIndex] * uLoc.z);
2076
2077 double txPhaseDiff =
2078 2 * M_PI *
2079 (sinCosD[nIndex][mIndex] * sLoc.x + sinSinD[nIndex][mIndex] * sLoc.y +
2080 cosZoD[nIndex][mIndex] * sLoc.z);
2081
2082 std::complex<double> raySub =
2083 raysPreComp[std::make_pair(sAntenna->GetElemPol(sIndex),
2084 uAntenna->GetElemPol(uIndex))](nIndex,
2085 mIndex) *
2086 std::complex<double>(cos(rxPhaseDiff), sin(rxPhaseDiff)) *
2087 std::complex<double>(cos(txPhaseDiff), sin(txPhaseDiff));
2088
2089 switch (mIndex)
2090 {
2091 case 9:
2092 case 10:
2093 case 11:
2094 case 12:
2095 case 17:
2096 case 18:
2097 raysSub2 += raySub;
2098 break;
2099 case 13:
2100 case 14:
2101 case 15:
2102 case 16:
2103 raysSub3 += raySub;
2104 break;
2105 default: // case 1,2,3,4,5,6,7,8,19,20
2106 raysSub1 += raySub;
2107 break;
2108 }
2109 }
2110 raysSub1 *=
2111 sqrt(channelParams->m_clusterPower[nIndex] / table3gpp->m_raysPerCluster);
2112 raysSub2 *=
2113 sqrt(channelParams->m_clusterPower[nIndex] / table3gpp->m_raysPerCluster);
2114 raysSub3 *=
2115 sqrt(channelParams->m_clusterPower[nIndex] / table3gpp->m_raysPerCluster);
2116 hUsn(uIndex, sIndex, nIndex) = raysSub1;
2117 hUsn(uIndex,
2118 sIndex,
2119 channelParams->m_reducedClusterNumber + numSubClustersAdded) = raysSub2;
2120 hUsn(uIndex,
2121 sIndex,
2122 channelParams->m_reducedClusterNumber + numSubClustersAdded + 1) =
2123 raysSub3;
2124 }
2125 }
2126 }
2127 if (nIndex == channelParams->m_cluster1st || nIndex == channelParams->m_cluster2nd)
2128 {
2129 numSubClustersAdded += 2;
2130 }
2131 }
2132
2133 if (channelParams->m_losCondition == ChannelCondition::LOS) //(7.5-29) && (7.5-30)
2134 {
2135 double lambda = 3.0e8 / m_frequency; // the wavelength of the carrier frequency
2136 std::complex<double> phaseDiffDueToDistance(cos(-2 * M_PI * distance3D / lambda),
2137 sin(-2 * M_PI * distance3D / lambda));
2138
2139 const double sinUAngleIncl = sin(uAngle.GetInclination());
2140 const double cosUAngleIncl = cos(uAngle.GetInclination());
2141 const double sinUAngleAz = sin(uAngle.GetAzimuth());
2142 const double cosUAngleAz = cos(uAngle.GetAzimuth());
2143 const double sinSAngleIncl = sin(sAngle.GetInclination());
2144 const double cosSAngleIncl = cos(sAngle.GetInclination());
2145 const double sinSAngleAz = sin(sAngle.GetAzimuth());
2146 const double cosSAngleAz = cos(sAngle.GetAzimuth());
2147
2148 for (size_t uIndex = 0; uIndex < uSize; uIndex++)
2149 {
2150 Vector uLoc = uAntenna->GetElementLocation(uIndex);
2151 double rxPhaseDiff = 2 * M_PI *
2152 (sinUAngleIncl * cosUAngleAz * uLoc.x +
2153 sinUAngleIncl * sinUAngleAz * uLoc.y + cosUAngleIncl * uLoc.z);
2154
2155 for (size_t sIndex = 0; sIndex < sSize; sIndex++)
2156 {
2157 Vector sLoc = sAntenna->GetElementLocation(sIndex);
2158 std::complex<double> ray(0, 0);
2159 double txPhaseDiff =
2160 2 * M_PI *
2161 (sinSAngleIncl * cosSAngleAz * sLoc.x + sinSAngleIncl * sinSAngleAz * sLoc.y +
2162 cosSAngleIncl * sLoc.z);
2163
2164 auto [rxFieldPatternPhi, rxFieldPatternTheta] = uAntenna->GetElementFieldPattern(
2165 Angles(uAngle.GetAzimuth(), uAngle.GetInclination()),
2166 uAntenna->GetElemPol(uIndex));
2167 auto [txFieldPatternPhi, txFieldPatternTheta] = sAntenna->GetElementFieldPattern(
2168 Angles(sAngle.GetAzimuth(), sAngle.GetInclination()),
2169 sAntenna->GetElemPol(sIndex));
2170
2171 ray = (rxFieldPatternTheta * txFieldPatternTheta -
2172 rxFieldPatternPhi * txFieldPatternPhi) *
2173 phaseDiffDueToDistance *
2174 std::complex<double>(cos(rxPhaseDiff), sin(rxPhaseDiff)) *
2175 std::complex<double>(cos(txPhaseDiff), sin(txPhaseDiff));
2176
2177 double kLinear = pow(10, channelParams->m_K_factor / 10.0);
2178 // the LOS path should be attenuated if blockage is enabled.
2179 hUsn(uIndex, sIndex, 0) =
2180 sqrt(1.0 / (kLinear + 1)) * hUsn(uIndex, sIndex, 0) +
2181 sqrt(kLinear / (1 + kLinear)) * ray /
2182 pow(10,
2183 channelParams->m_attenuation_dB[0] / 10.0); //(7.5-30) for tau = tau1
2184 for (size_t nIndex = 1; nIndex < hUsn.GetNumPages(); nIndex++)
2185 {
2186 hUsn(uIndex, sIndex, nIndex) *=
2187 sqrt(1.0 / (kLinear + 1)); //(7.5-30) for tau = tau2...tauN
2188 }
2189 }
2190 }
2191 }
2192
2193 NS_LOG_DEBUG("Husn (sAntenna, uAntenna):" << sAntenna->GetId() << ", " << uAntenna->GetId());
2194 for (size_t cIndex = 0; cIndex < hUsn.GetNumPages(); cIndex++)
2195 {
2196 for (size_t rowIdx = 0; rowIdx < hUsn.GetNumRows(); rowIdx++)
2197 {
2198 for (size_t colIdx = 0; colIdx < hUsn.GetNumCols(); colIdx++)
2199 {
2200 NS_LOG_DEBUG(" " << hUsn(rowIdx, colIdx, cIndex) << ",");
2201 }
2202 }
2203 }
2204
2205 NS_LOG_INFO("size of coefficient matrix (rows, columns, clusters) = ("
2206 << hUsn.GetNumRows() << ", " << hUsn.GetNumCols() << ", " << hUsn.GetNumPages()
2207 << ")");
2208 channelMatrix->m_channel = hUsn;
2209 return channelMatrix;
2210}
2211
2212std::pair<double, double>
2213ThreeGppChannelModel::WrapAngles(double azimuthRad, double inclinationRad)
2214{
2215 inclinationRad = WrapTo2Pi(inclinationRad);
2216 if (inclinationRad > M_PI)
2217 {
2218 // inclination must be in [0, M_PI]
2219 inclinationRad -= M_PI;
2220 azimuthRad += M_PI;
2221 }
2222
2223 azimuthRad = WrapTo2Pi(azimuthRad);
2224
2225 NS_ASSERT_MSG(0 <= inclinationRad && inclinationRad <= M_PI,
2226 "inclinationRad=" << inclinationRad << " not valid, should be in [0, pi]");
2227 NS_ASSERT_MSG(0 <= azimuthRad && azimuthRad <= 2 * M_PI,
2228 "azimuthRad=" << azimuthRad << " not valid, should be in [0, 2*pi]");
2229
2230 return std::make_pair(azimuthRad, inclinationRad);
2231}
2232
2236 const DoubleVector& clusterAOA,
2237 const DoubleVector& clusterZOA) const
2238{
2239 NS_LOG_FUNCTION(this);
2240
2241 auto clusterNum = clusterAOA.size();
2242
2243 // Initial power attenuation for all clusters to be 0 dB
2244 DoubleVector powerAttenuation(clusterNum, 0);
2245
2246 // step a: the number of non-self blocking blockers is stored in m_numNonSelfBlocking.
2247
2248 // step b:Generate the size and location of each blocker
2249 // generate self blocking (i.e., for blockage from the human body)
2250 // table 7.6.4.1-1 Self-blocking region parameters.
2251 // Defaults: landscape mode
2252 double phiSb = 40;
2253 double xSb = 160;
2254 double thetaSb = 110;
2255 double ySb = 75;
2256 if (m_portraitMode)
2257 {
2258 phiSb = 260;
2259 xSb = 120;
2260 thetaSb = 100;
2261 ySb = 80;
2262 }
2263
2264 // generate or update non-self blocking
2265 if (channelParams->m_nonSelfBlocking.empty()) // generate new blocking regions
2266 {
2267 for (uint16_t blockInd = 0; blockInd < m_numNonSelfBlocking; blockInd++)
2268 {
2269 // draw value from table 7.6.4.1-2 Blocking region parameters
2270 DoubleVector table;
2271 table.push_back(m_normalRv->GetValue()); // phi_k: store the normal RV that will be
2272 // mapped to uniform (0,360) later.
2273 if (m_scenario == "InH-OfficeMixed" || m_scenario == "InH-OfficeOpen")
2274 {
2275 table.push_back(m_uniformRv->GetValue(15, 45)); // x_k
2276 table.push_back(90); // Theta_k
2277 table.push_back(m_uniformRv->GetValue(5, 15)); // y_k
2278 table.push_back(2); // r
2279 }
2280 else
2281 {
2282 table.push_back(m_uniformRv->GetValue(5, 15)); // x_k
2283 table.push_back(90); // Theta_k
2284 table.push_back(5); // y_k
2285 table.push_back(10); // r
2286 }
2287 channelParams->m_nonSelfBlocking.push_back(table);
2288 }
2289 }
2290 else
2291 {
2292 double deltaX = sqrt(pow(channelParams->m_preLocUT.x - channelParams->m_locUT.x, 2) +
2293 pow(channelParams->m_preLocUT.y - channelParams->m_locUT.y, 2));
2294 // if deltaX and speed are both 0, the autocorrelation is 1, skip updating
2295 if (deltaX > 1e-6 || m_blockerSpeed > 1e-6)
2296 {
2297 double corrDis;
2298 // draw value from table 7.6.4.1-4: Spatial correlation distance for different
2299 // m_scenarios.
2300 if (m_scenario == "InH-OfficeMixed" || m_scenario == "InH-OfficeOpen")
2301 {
2302 // InH, correlation distance = 5;
2303 corrDis = 5;
2304 }
2305 else
2306 {
2307 if (channelParams->m_o2iCondition == ChannelCondition::O2I) // outdoor to indoor
2308 {
2309 corrDis = 5;
2310 }
2311 else // LOS or NLOS
2312 {
2313 corrDis = 10;
2314 }
2315 }
2316 double R;
2317 if (m_blockerSpeed > 1e-6) // speed not equal to 0
2318 {
2319 double corrT = corrDis / m_blockerSpeed;
2320 R = exp(-1 * (deltaX / corrDis +
2321 (Now().GetSeconds() - channelParams->m_generatedTime.GetSeconds()) /
2322 corrT));
2323 }
2324 else
2325 {
2326 R = exp(-1 * (deltaX / corrDis));
2327 }
2328
2329 NS_LOG_INFO("Distance change:"
2330 << deltaX << " Speed:" << m_blockerSpeed << " Time difference:"
2331 << Now().GetSeconds() - channelParams->m_generatedTime.GetSeconds()
2332 << " correlation:" << R);
2333
2334 // In order to generate correlated uniform random variables, we first generate
2335 // correlated normal random variables and map the normal RV to uniform RV. Notice the
2336 // correlation will change if the RV is transformed from normal to uniform. To
2337 // compensate the distortion, the correlation of the normal RV is computed such that the
2338 // uniform RV would have the desired correlation when transformed from normal RV.
2339
2340 // The following formula was obtained from MATLAB numerical simulation.
2341
2342 if (R * R * (-0.069) + R * 1.074 - 0.002 <
2343 1) // transform only when the correlation of normal RV is smaller than 1
2344 {
2345 R = R * R * (-0.069) + R * 1.074 - 0.002;
2346 }
2347 for (uint16_t blockInd = 0; blockInd < m_numNonSelfBlocking; blockInd++)
2348 {
2349 // Generate a new correlated normal RV with the following formula
2350 channelParams->m_nonSelfBlocking[blockInd][PHI_INDEX] =
2351 R * channelParams->m_nonSelfBlocking[blockInd][PHI_INDEX] +
2352 sqrt(1 - R * R) * m_normalRv->GetValue();
2353 }
2354 }
2355 }
2356
2357 // step c: Determine the attenuation of each blocker due to blockers
2358 for (std::size_t cInd = 0; cInd < clusterNum; cInd++)
2359 {
2360 NS_ASSERT_MSG(clusterAOA[cInd] >= 0 && clusterAOA[cInd] <= 360,
2361 "the AOA should be the range of [0,360]");
2362 NS_ASSERT_MSG(clusterZOA[cInd] >= 0 && clusterZOA[cInd] <= 180,
2363 "the ZOA should be the range of [0,180]");
2364
2365 // check self blocking
2366 NS_LOG_INFO("AOA=" << clusterAOA[cInd] << " Block Region[" << phiSb - xSb / 2.0 << ","
2367 << phiSb + xSb / 2.0 << "]");
2368 NS_LOG_INFO("ZOA=" << clusterZOA[cInd] << " Block Region[" << thetaSb - ySb / 2.0 << ","
2369 << thetaSb + ySb / 2.0 << "]");
2370 if (std::abs(clusterAOA[cInd] - phiSb) < (xSb / 2.0) &&
2371 std::abs(clusterZOA[cInd] - thetaSb) < (ySb / 2.0))
2372 {
2373 powerAttenuation[cInd] += 30; // attenuate by 30 dB.
2374 NS_LOG_INFO("Cluster[" << +cInd
2375 << "] is blocked by self blocking region and reduce 30 dB power,"
2376 "the attenuation is ["
2377 << powerAttenuation[cInd] << " dB]");
2378 }
2379
2380 // check non-self blocking
2381 for (uint16_t blockInd = 0; blockInd < m_numNonSelfBlocking; blockInd++)
2382 {
2383 // The normal RV is transformed to uniform RV with the desired correlation.
2384 double phiK =
2385 (0.5 * erfc(-1 * channelParams->m_nonSelfBlocking[blockInd][PHI_INDEX] / sqrt(2))) *
2386 360;
2387 while (phiK > 360)
2388 {
2389 phiK -= 360;
2390 }
2391
2392 while (phiK < 0)
2393 {
2394 phiK += 360;
2395 }
2396
2397 double xK = channelParams->m_nonSelfBlocking[blockInd][X_INDEX];
2398 double thetaK = channelParams->m_nonSelfBlocking[blockInd][THETA_INDEX];
2399 double yK = channelParams->m_nonSelfBlocking[blockInd][Y_INDEX];
2400
2401 NS_LOG_INFO("AOA=" << clusterAOA[cInd] << " Block Region[" << phiK - xK << ","
2402 << phiK + xK << "]");
2403 NS_LOG_INFO("ZOA=" << clusterZOA[cInd] << " Block Region[" << thetaK - yK << ","
2404 << thetaK + yK << "]");
2405
2406 if (std::abs(clusterAOA[cInd] - phiK) < (xK) &&
2407 std::abs(clusterZOA[cInd] - thetaK) < (yK))
2408 {
2409 double A1 = clusterAOA[cInd] - (phiK + xK / 2.0); //(7.6-24)
2410 double A2 = clusterAOA[cInd] - (phiK - xK / 2.0); //(7.6-25)
2411 double Z1 = clusterZOA[cInd] - (thetaK + yK / 2.0); //(7.6-26)
2412 double Z2 = clusterZOA[cInd] - (thetaK - yK / 2.0); //(7.6-27)
2413 int signA1;
2414 int signA2;
2415 int signZ1;
2416 int signZ2;
2417 // draw sign for the above parameters according to table 7.6.4.1-3 Description of
2418 // signs
2419 if (xK / 2.0 < clusterAOA[cInd] - phiK && clusterAOA[cInd] - phiK <= xK)
2420 {
2421 signA1 = -1;
2422 }
2423 else
2424 {
2425 signA1 = 1;
2426 }
2427 if (-1 * xK < clusterAOA[cInd] - phiK && clusterAOA[cInd] - phiK <= -1 * xK / 2.0)
2428 {
2429 signA2 = -1;
2430 }
2431 else
2432 {
2433 signA2 = 1;
2434 }
2435
2436 if (yK / 2.0 < clusterZOA[cInd] - thetaK && clusterZOA[cInd] - thetaK <= yK)
2437 {
2438 signZ1 = -1;
2439 }
2440 else
2441 {
2442 signZ1 = 1;
2443 }
2444 if (-1 * yK < clusterZOA[cInd] - thetaK &&
2445 clusterZOA[cInd] - thetaK <= -1 * yK / 2.0)
2446 {
2447 signZ2 = -1;
2448 }
2449 else
2450 {
2451 signZ2 = 1;
2452 }
2453 double lambda = 3e8 / m_frequency;
2454 double fA1 =
2455 atan(signA1 * M_PI / 2.0 *
2456 sqrt(M_PI / lambda * channelParams->m_nonSelfBlocking[blockInd][R_INDEX] *
2457 (1.0 / cos(DegreesToRadians(A1)) - 1))) /
2458 M_PI; //(7.6-23)
2459 double fA2 =
2460 atan(signA2 * M_PI / 2.0 *
2461 sqrt(M_PI / lambda * channelParams->m_nonSelfBlocking[blockInd][R_INDEX] *
2462 (1.0 / cos(DegreesToRadians(A2)) - 1))) /
2463 M_PI;
2464 double fZ1 =
2465 atan(signZ1 * M_PI / 2.0 *
2466 sqrt(M_PI / lambda * channelParams->m_nonSelfBlocking[blockInd][R_INDEX] *
2467 (1.0 / cos(DegreesToRadians(Z1)) - 1))) /
2468 M_PI;
2469 double fZ2 =
2470 atan(signZ2 * M_PI / 2.0 *
2471 sqrt(M_PI / lambda * channelParams->m_nonSelfBlocking[blockInd][R_INDEX] *
2472 (1.0 / cos(DegreesToRadians(Z2)) - 1))) /
2473 M_PI;
2474 double lDb = -20 * log10(1 - (fA1 + fA2) * (fZ1 + fZ2)); //(7.6-22)
2475 powerAttenuation[cInd] += lDb;
2476 NS_LOG_INFO("Cluster[" << +cInd << "] is blocked by no-self blocking, the loss is ["
2477 << lDb << "] dB");
2478 }
2479 }
2480 }
2481 return powerAttenuation;
2482}
2483
2484void
2485ThreeGppChannelModel::Shuffle(double* first, double* last) const
2486{
2487 for (auto i = (last - first) - 1; i > 0; --i)
2488 {
2489 std::swap(first[i], first[m_uniformRvShuffle->GetInteger(0, i)]);
2490 }
2491}
2492
2493int64_t
2495{
2496 NS_LOG_FUNCTION(this << stream);
2497 m_normalRv->SetStream(stream);
2498 m_uniformRv->SetStream(stream + 1);
2499 m_uniformRvShuffle->SetStream(stream + 2);
2500 m_uniformRvDoppler->SetStream(stream + 3);
2501 return 4;
2502}
2503
2504} // namespace ns3
Class holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:118
double GetInclination() const
Getter for inclination angle.
Definition: angles.cc:246
double GetAzimuth() const
Getter for azimuth angle.
Definition: angles.cc:240
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold a signed integer type.
Definition: integer.h:45
This is an interface for a channel model that can be described by a channel matrix,...
std::vector< double > DoubleVector
Type definition for vectors of doubles.
ComplexMatrixArray Complex2DVector
Create an alias for 2D complex vectors.
std::vector< Double2DVector > Double3DVector
Type definition for 3D matrices of doubles.
std::vector< DoubleVector > Double2DVector
Type definition for matrices of doubles.
static uint64_t GetKey(uint32_t a, uint32_t b)
Generate a unique value for the pair of unsigned integer of 32 bits, where the order does not matter,...
A network Node.
Definition: node.h:57
uint32_t GetId() const
Definition: node.cc:117
AttributeValue implementation for Pointer.
Definition: pointer.h:48
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Hold variables of type string.
Definition: string.h:56
DoubleVector CalcAttenuationOfBlockage(const Ptr< ThreeGppChannelModel::ThreeGppChannelParams > channelParams, const DoubleVector &clusterAOA, const DoubleVector &clusterZOA) const
Applies the blockage model A described in 3GPP TR 38.901.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
bool m_portraitMode
true if portrait mode, false if landscape
bool ChannelParamsNeedsUpdate(Ptr< const ThreeGppChannelParams > channelParams, Ptr< const ChannelCondition > channelCondition) const
Check if the channel params has to be updated.
virtual Ptr< const ParamsTable > GetThreeGppTable(Ptr< const ChannelCondition > channelCondition, double hBS, double hUT, double distance2D) const
Get the parameters needed to apply the channel generation procedure.
Ptr< NormalRandomVariable > m_normalRv
normal random variable
static const uint8_t Y_INDEX
index of the Y value in the m_nonSelfBlocking array
bool m_blockage
enables the blockage model A
Ptr< const ChannelParams > GetParams(Ptr< const MobilityModel > aMob, Ptr< const MobilityModel > bMob) const override
Looks for the channel params associated to the aMob and bMob pair in m_channelParamsMap.
~ThreeGppChannelModel() override
Destructor.
bool ChannelMatrixNeedsUpdate(Ptr< const ThreeGppChannelParams > channelParams, Ptr< const ChannelMatrix > channelMatrix)
Check if the channel matrix has to be updated (it needs update when the channel params generation tim...
static const uint8_t THETA_INDEX
index of the THETA value in the m_nonSelfBlocking array
std::unordered_map< uint64_t, Ptr< ThreeGppChannelParams > > m_channelParamsMap
map containing the common channel parameters per pair of nodes, the key of this map is reciprocal and...
static std::pair< double, double > WrapAngles(double azimuthRad, double inclinationRad)
Wrap an (azimuth, inclination) angle pair in a valid range.
double m_blockerSpeed
the blocker speed
Ptr< const ChannelMatrix > GetChannel(Ptr< const MobilityModel > aMob, Ptr< const MobilityModel > bMob, Ptr< const PhasedArrayModel > aAntenna, Ptr< const PhasedArrayModel > bAntenna) override
Looks for the channel matrix associated to the aMob and bMob pair in m_channelMatrixMap.
void SetFrequency(double f)
Sets the center frequency of the model.
std::unordered_map< uint64_t, Ptr< ChannelMatrix > > m_channelMatrixMap
map containing the channel realizations per pair of PhasedAntennaArray instances, the key of this map...
Ptr< UniformRandomVariable > m_uniformRv
uniform random variable
void DoDispose() override
Destructor implementation.
void SetScenario(const std::string &scenario)
Sets the propagation scenario.
void SetChannelConditionModel(Ptr< ChannelConditionModel > model)
Set the channel condition model.
Ptr< UniformRandomVariable > m_uniformRvDoppler
uniform random variable, used to compute the additional Doppler contribution
uint16_t m_numNonSelfBlocking
number of non-self-blocking regions
std::string GetScenario() const
Returns the propagation scenario.
virtual Ptr< ChannelMatrix > GetNewChannel(Ptr< const ThreeGppChannelParams > channelParams, Ptr< const ParamsTable > table3gpp, const Ptr< const MobilityModel > sMob, const Ptr< const MobilityModel > uMob, Ptr< const PhasedArrayModel > sAntenna, Ptr< const PhasedArrayModel > uAntenna) const
Compute the channel matrix between two nodes a and b, and their antenna arrays aAntenna and bAntenna ...
static const uint8_t PHI_INDEX
index of the PHI value in the m_nonSelfBlocking array
double m_frequency
the operating frequency
double m_vScatt
value used to compute the additional Doppler contribution for the delayed paths
Ptr< ChannelConditionModel > GetChannelConditionModel() const
Get the associated channel condition model.
Ptr< ChannelConditionModel > m_channelConditionModel
the channel condition model
std::string m_scenario
the 3GPP scenario
static const uint8_t R_INDEX
index of the R value in the m_nonSelfBlocking array
static TypeId GetTypeId()
Get the type ID.
void Shuffle(double *first, double *last) const
Shuffle the elements of a simple sequence container of type double.
Ptr< ThreeGppChannelParams > GenerateChannelParameters(const Ptr< const ChannelCondition > channelCondition, const Ptr< const ParamsTable > table3gpp, const Ptr< const MobilityModel > aMob, const Ptr< const MobilityModel > bMob) const
Prepare 3gpp channel parameters among the nodes a and b.
double GetFrequency() const
Returns the center frequency.
Time m_updatePeriod
the channel update period
static const uint8_t X_INDEX
index of the X value in the m_nonSelfBlocking array
Ptr< UniformRandomVariable > m_uniformRvShuffle
uniform random variable used to shuffle array in GetNewChannel
@ NS
nanosecond
Definition: nstime.h:119
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:315
AttributeValue implementation for Time.
Definition: nstime.h:1413
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:940
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
double GetValue(double min, double max)
Get the next random value drawn from the distribution.
uint32_t GetInteger(uint32_t min, uint32_t max)
Get the next random value drawn from the distribution.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:81
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Definition: integer.h:46
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:259
Ptr< const AttributeChecker > MakeStringChecker()
Definition: string.cc:30
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition: string.h:57
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1434
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr double DEG2RAD
Conversion factor: degrees to radians.
static const double offSetAlpha[20]
The ray offset angles within a cluster, given for rms angle spread normalized to 1.
static const double sqrtC_RMa_O2I[6][6]
The square root matrix for RMa O2I, which is generated using the Cholesky decomposition according to ...
static const double sqrtC_UMi_LOS[7][7]
The square root matrix for UMi LOS, which is generated using the Cholesky decomposition according to ...
static const double sqrtC_office_LOS[7][7]
The square root matrix for Indoor-Office LOS, which is generated using the Cholesky decomposition acc...
static const double sqrtC_UMa_O2I[6][6]
The square root matrix for UMa O2I, which is generated using the Cholesky decomposition according to ...
static const double sqrtC_RMa_NLOS[6][6]
The square root matrix for RMa NLOS, which is generated using the Cholesky decomposition according to...
static const double sqrtC_UMa_LOS[7][7]
The square root matrix for UMa LOS, which is generated using the Cholesky decomposition according to ...
static const double sqrtC_UMi_NLOS[6][6]
The square root matrix for UMi NLOS, which is generated using the Cholesky decomposition according to...
static const double sqrtC_RMa_LOS[7][7]
The square root matrix for RMa LOS, which is generated using the Cholesky decomposition according to ...
double DegreesToRadians(double degrees)
converts degrees to radians
Definition: angles.cc:39
static const double sqrtC_UMi_O2I[6][6]
The square root matrix for UMi O2I, which is generated using the Cholesky decomposition according to ...
static const double sqrtC_office_NLOS[6][6]
The square root matrix for Indoor-Office NLOS, which is generated using the Cholesky decomposition ac...
static const double sqrtC_UMa_NLOS[6][6]
The square root matrix for UMa NLOS, which is generated using the Cholesky decomposition according to...
double WrapTo2Pi(double a)
Wrap angle in [0, 2*M_PI)
Definition: angles.cc:117
double RadiansToDegrees(double radians)
converts radians to degrees
Definition: angles.cc:45