69#include "ns3/buildings-module.h"
70#include "ns3/core-module.h"
71#include "ns3/mobility-module.h"
72#include "ns3/network-module.h"
73#include "ns3/spectrum-signal-parameters.h"
74#include "ns3/three-gpp-channel-model.h"
75#include "ns3/three-gpp-propagation-loss-model.h"
76#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
77#include "ns3/uniform-planar-array.h"
124 std::array<double, 3>
aoa;
125 std::array<double, 3>
zoa;
137 return 10.0 * std::log10(std::max(power, std::numeric_limits<double>::min()));
162 params.channelModel->GetChannel(params.txMob,
168 params.channelModel->GetParams(params.txMob, params.rxMob);
173 NS_ABORT_MSG_IF(channelMatrix ==
nullptr,
"The channel matrix is not available");
175 NS_ABORT_MSG_IF(channelParams ==
nullptr,
"The 3GPP channel parameters are not available");
178 "The channel matrix has fewer than three components");
181 "The channel has fewer than three cluster powers");
184 "The channel has fewer than three cluster delays");
189 "The channel has fewer than three cluster arrival angles");
191 const size_t numRows = channelMatrix->m_channel.GetNumRows();
192 const size_t numCols = channelMatrix->m_channel.GetNumCols();
193 const auto numElements =
static_cast<double>(numRows * numCols);
195 std::array<double, 3> componentPower{0.0, 0.0, 0.0};
197 for (
size_t componentIndex = 0; componentIndex < componentPower.size(); ++componentIndex)
199 for (
size_t row = 0; row < numRows; ++row)
201 for (
size_t col = 0; col < numCols; ++col)
203 componentPower[componentIndex] +=
204 std::norm(channelMatrix->m_channel(row, col, componentIndex));
208 componentPower[componentIndex] /= numElements;
219 {channelParams->m_delay[0], channelParams->m_delay[1], channelParams->m_delay[2]},
239 auto antennaRows = antenna->GetNumRows();
240 auto antennaColumns = antenna->GetNumColumns();
241 auto numElemsPerPort = antenna->GetNumElemsPerPort();
243 double power = 1 / std::sqrt(numElemsPerPort);
244 size_t numPolarizations = antenna->IsDualPol() ? 2 : 1;
247 uint16_t bfIndex = 0;
248 for (
size_t pol = 0; pol < numPolarizations; pol++)
250 for (
uint32_t ind = 0; ind < antennaRows; ind++)
252 std::complex<double> c = 0.0;
253 if (antennaRows % 2 == 0)
255 c = std::exp(std::complex<double>(0, M_PI * ind * ind / antennaRows));
259 c = std::exp(std::complex<double>(0, M_PI * ind * (ind + 1) / antennaRows));
261 for (
uint32_t ind2 = 0; ind2 < antennaColumns; ind2++)
263 std::complex<double> d = 0.0;
264 if (antennaColumns % 2 == 0)
266 d = std::exp(std::complex<double>(0, M_PI * ind2 * ind2 / antennaColumns));
271 std::complex<double>(0, M_PI * ind2 * (ind2 + 1) / antennaColumns));
273 omni[bfIndex] = (c * d * power);
279 antenna->SetBeamformingVector(omni);
294 double propagationGainLinear = std::pow(10.0, (propagationGainDb) / 10.0);
295 *(params.txParams->psd) *= propagationGainLinear;
303 params.txAntenna->GetBeamformingVector(),
304 params.rxAntenna->GetBeamformingVector());
309 const double kTDbmHz = -174.0;
310 double kT_W_Hz = std::pow(10.0, (kTDbmHz - 30) / 10.0);
311 double noiseFigureLinear = std::pow(10.0, params.noiseFigure / 10.0);
312 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
314 (*noisePsd) = noisePowerSpectralDensity;
317 f.open(
"3gpp-spatiotemporal-channel-consistency-output.txt", std::ios::out | std::ios::app);
319 << params.txMob->GetPosition().x <<
" " << params.txMob->GetPosition().y <<
" "
320 << params.rxMob->GetPosition().x <<
" " << params.rxMob->GetPosition().y <<
" "
321 << cond->GetLosCondition() <<
" "
322 << 10 * std::log10(
Sum(*rxPsd) /
Sum(*noisePsd)) <<
" "
323 << -propagationGainDb <<
" "
327 << metrics.
delay[0] <<
" " << metrics.
aoa[0] <<
" " << metrics.
zoa[0] <<
" "
328 << metrics.
delay[1] <<
" " << metrics.
aoa[1] <<
" " << metrics.
zoa[1] <<
" "
329 << metrics.
delay[2] <<
" " << metrics.
aoa[2] <<
" " << metrics.
zoa[2] <<
" "
344 std::ofstream outFile;
345 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
346 if (!outFile.is_open())
353 Box box = (*it)->GetBoundaries();
354 outFile << box.
xMin <<
" " << box.
yMin <<
" " << box.
xMax <<
" " << box.
yMax << std::endl;
359main(
int argc,
char* argv[])
361 double frequency = 30e9;
362 double txPowerDbm = 35.0;
363 double noiseFigure = 9.0;
365 double speed = 30.0 / 3.6;
366 double rbWidthHz = 720e3;
368 double gnbHeight = 10;
375 uint64_t stream = 10000;
386 nodes.Get(0)->AddDevice(txDev);
387 txDev->SetNode(
nodes.Get(0));
388 nodes.Get(1)->AddDevice(rxDev);
389 rxDev->SetNode(
nodes.Get(1));
411 double buildingSizeX = (250 - 3.5 * 2 - 3) / 2;
412 double buildingSizeY = (433 - 3.5 * 2 - 3) / 4;
413 double streetWidth = 20;
414 double buildingHeight = 10;
417 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
418 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
420 std::vector<Ptr<Building>> buildingVector;
421 for (
uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
423 for (
uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
428 building->SetBoundaries(
Box(buildingIdX * (buildingSizeX + streetWidth),
429 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
430 buildingIdY * (buildingSizeY + streetWidth),
431 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
434 building->SetNRoomsX(1);
435 building->SetNRoomsY(1);
436 building->SetNFloors(1);
437 buildingVector.push_back(building);
443 txMob->SetPosition(Vector(maxAxisX / 2 - streetWidth / 2, -20, gnbHeight));
444 nodes.Get(0)->AggregateObject(txMob);
446 const Vector firstPosition(maxAxisX / 2 - streetWidth / 2, -10, ueHeight);
447 const Vector secondPosition(maxAxisX / 2 - streetWidth / 2,
448 maxAxisY / 2 - streetWidth / 2,
450 const Vector thirdPosition(0.0, maxAxisY / 2 - streetWidth / 2, ueHeight);
459 const Time simTime = nextWaypoint;
460 nodes.Get(1)->AggregateObject(rxMob);
475 channelModel->SetAttribute(
"Scenario",
StringValue(
"UMi-StreetCanyon"));
476 channelModel->SetAttribute(
"Frequency",
DoubleValue(frequency));
478 channelModel->SetAttribute(
"UpdatePeriod",
TimeValue(updatePeriod));
479 stream += channelModel->AssignStreams(stream);
490 double freqSubBand = frequency;
491 for (
uint32_t n = 0; n < numRb; ++n)
495 freqSubBand += rbWidthHz / 2;
497 freqSubBand += rbWidthHz / 2;
504 double txPowerW = std::pow(10., (txPowerDbm - 30) / 10);
505 double txPowDens = (txPowerW / (numRb * rbWidthHz));
506 (*txPsd) = txPowDens;
507 txParams->psd = txPsd->Copy();
512 for (
int i = 0; i < simTime / updatePeriod; i++)
515 params{txMob, rxMob, txParams->Copy(), noiseFigure, txAntenna, rxAntenna, channelModel};
532 f.open(
"3gpp-spatiotemporal-channel-consistency-output.txt", std::ios::out);
533 f <<
"Time[s] TxPosX[m] TxPosY[m] RxPosX[m] RxPosY[m] ChannelState SNR[dB] Pathloss[dB] "
534 "1st_C_Power[dB] 2nd_C_Power[dB] 3rd_C_Power[dB] "
535 "1st_C_Delay[s] 1st_C_Aoa[Degree] 1st_C_Zoa[Degree] "
536 "2nd_C_Delay[s] 2nd_C_Aoa[Degree] 2nd_C_Zoa[Degree] "
537 "3rd_C_Delay[s] 3rd_C_Aoa[Degree] 3rd_C_Zoa[Degree] "
538 "C1ComponentPower[dB] C2ComponentPower[dB] C3ComponentPower[dB]"
double yMax
The y coordinate of the top bound of the box.
double xMin
The x coordinate of the left bound of the box.
double yMin
The y coordinate of the bottom bound of the box.
double xMax
The x coordinate of the right bound of the box.
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static const uint8_t AOA_INDEX
index of the AOA value in the m_angle array
static const uint8_t ZOA_INDEX
index of the ZOA value in the m_angle array
keep track of a set of node pointers.
ComplexMatrixArray ComplexVector
the underlying Valarray
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Hold an unsigned integer type.
Waypoint-based mobility model.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< BandInfo > Bands
Container of BandInfo.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
double Sum(const SpectrumValue &x)
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
Metrics for the first three channel components and clusters.
std::array< double, 3 > delay
C1, C2, and C3 delays in seconds.
std::array< double, 3 > aoa
C1, C2, and C3 azimuth arrival angles in degrees.
std::array< double, 3 > clusterPowerDb
C1, C2, and C3 cluster powers in dB, taken from the 3GPP channel parameters.
std::array< double, 3 > componentPowerDb
C1, C2, and C3 channel-component powers in dB, computed from the corresponding channel-matrix compone...
std::array< double, 3 > zoa
C1, C2, and C3 zenith arrival angles in degrees.
A structure that holds the parameters for the ComputeSnr function.
Ptr< PhasedArrayModel > txAntenna
the tx antenna array
Ptr< MobilityModel > rxMob
the rx mobility model
Ptr< ThreeGppChannelModel > channelModel
the channel model
Ptr< SpectrumSignalParameters > txParams
the params of the tx signal
double noiseFigure
the noise figure in dB
Ptr< PhasedArrayModel > rxAntenna
the rx antenna array
Ptr< MobilityModel > txMob
the tx mobility model
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband
static Ptr< ThreeGppSpectrumPropagationLossModel > g_spectrumLossModel
the SpectrumPropagationLossModel object
static Ptr< ThreeGppPropagationLossModel > g_propagationLossModel
the log component
static ChannelMetrics GetChannelMetrics(const ComputeSnrParams ¶ms)
Get metrics for the first three channel components and clusters.
static double PowerRatioToDb(double power)
Convert a non-negative linear power ratio to dB.
static void ComputeSnr(const ComputeSnrParams ¶ms)
Computes the SNR.
void PrintGnuplottableBuildingListToFile(std::string filename)
Generates a GNU-plottable file representing the buildings deployed in the scenario.
static Ptr< ChannelConditionModel > g_condModel
the ChannelConditionModel object
static void CreateQuasiOmniBf(Ptr< PhasedArrayModel > antenna)
Set QuasiOmni beamforming vector to the antenna array.
static void ComputeSnr(const ComputeSnrParams ¶ms)
Compute the average SNR.