65#include "ns3/buildings-module.h"
66#include "ns3/core-module.h"
67#include "ns3/mobility-module.h"
68#include "ns3/network-module.h"
69#include "ns3/spectrum-signal-parameters.h"
70#include "ns3/three-gpp-channel-model.h"
71#include "ns3/three-gpp-propagation-loss-model.h"
72#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
73#include "ns3/uniform-planar-array.h"
112 auto antennaRows = antenna->GetNumRows();
113 auto antennaColumns = antenna->GetNumColumns();
114 auto numElemsPerPort = antenna->GetNumElemsPerPort();
116 double power = 1 / sqrt(numElemsPerPort);
117 size_t numPolarizations = antenna->IsDualPol() ? 2 : 1;
120 uint16_t bfIndex = 0;
121 for (
size_t pol = 0; pol < numPolarizations; pol++)
123 for (
uint32_t ind = 0; ind < antennaRows; ind++)
125 std::complex<double> c = 0.0;
126 if (antennaRows % 2 == 0)
128 c = exp(std::complex<double>(0, M_PI * ind * ind / antennaRows));
132 c = exp(std::complex<double>(0, M_PI * ind * (ind + 1) / antennaRows));
134 for (
uint32_t ind2 = 0; ind2 < antennaColumns; ind2++)
136 std::complex<double> d = 0.0;
137 if (antennaColumns % 2 == 0)
139 d = exp(std::complex<double>(0, M_PI * ind2 * ind2 / antennaColumns));
143 d = exp(std::complex<double>(0, M_PI * ind2 * (ind2 + 1) / antennaColumns));
145 omni[bfIndex] = (c * d * power);
151 antenna->SetBeamformingVector(omni);
166 double propagationGainLinear = std::pow(10.0, (propagationGainDb) / 10.0);
167 *(params.txParams->psd) *= propagationGainLinear;
177 const double kT_dBm_Hz = -174.0;
178 double kT_W_Hz = std::pow(10.0, (kT_dBm_Hz - 30) / 10.0);
179 double noiseFigureLinear = std::pow(10.0, params.noiseFigure / 10.0);
180 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
182 (*noisePsd) = noisePowerSpectralDensity;
185 f.open(
"3gpp-channel-consistency-output.txt", std::ios::out | std::ios::app);
187 << params.txMob->GetPosition().x <<
" " << params.txMob->GetPosition().y <<
" "
188 << params.rxMob->GetPosition().x <<
" " << params.rxMob->GetPosition().y <<
" "
189 << cond->GetLosCondition() <<
" "
190 << 10 * log10(
Sum(*rxPsd) /
Sum(*noisePsd)) <<
" "
191 << -propagationGainDb << std::endl;
203 std::ofstream outFile;
204 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
205 if (!outFile.is_open())
212 Box box = (*it)->GetBoundaries();
213 outFile << box.
xMin <<
" " << box.
yMin <<
" " << box.
xMax <<
" " << box.
yMax << std::endl;
218main(
int argc,
char* argv[])
220 double frequency = 30e9;
221 double txPow_dbm = 35.0;
222 double noiseFigure = 9.0;
226 double rbWidthHz = 720e3;
228 double gNBHeight = 10;
235 uint64_t stream = 10e3;
246 nodes.Get(0)->AddDevice(txDev);
247 txDev->SetNode(
nodes.Get(0));
248 nodes.Get(1)->AddDevice(rxDev);
249 rxDev->SetNode(
nodes.Get(1));
271 double buildingSizeX = 250 - 3.5 * 2 - 3;
272 double buildingSizeY = 433 - 3.5 * 2 - 3;
273 double streetWidth = 20;
274 double buildingHeight = 10;
277 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
278 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
280 std::vector<Ptr<Building>> buildingVector;
281 for (
uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
283 for (
uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
288 building->SetBoundaries(
Box(buildingIdX * (buildingSizeX + streetWidth),
289 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
290 buildingIdY * (buildingSizeY + streetWidth),
291 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
294 building->SetNRoomsX(1);
295 building->SetNRoomsY(1);
296 building->SetNFloors(1);
297 buildingVector.push_back(building);
303 txMob->SetPosition(Vector(maxAxisX / 2 - streetWidth / 2, -20, gNBHeight));
304 nodes.Get(0)->AggregateObject(txMob);
309 Waypoint(nextWaypoint, Vector(maxAxisX / 2 - streetWidth / 2, maxAxisY / 4, ueHeight)));
310 nextWaypoint +=
Seconds((maxAxisY - maxAxisY / 2 - streetWidth) / 2 / speed);
313 Vector(maxAxisX / 2 - streetWidth / 2, maxAxisY / 2 - streetWidth / 2, ueHeight)));
314 nextWaypoint +=
Seconds((maxAxisX - streetWidth) / 2 / speed);
316 Waypoint(nextWaypoint, Vector(0.0, maxAxisY / 2 - streetWidth / 2, ueHeight)));
318 nodes.Get(1)->AggregateObject(rxMob);
333 channelModel->SetAttribute(
"Scenario",
StringValue(
"UMi-StreetCanyon"));
334 channelModel->SetAttribute(
"Frequency",
DoubleValue(frequency));
336 channelModel->SetAttribute(
"UpdatePeriod",
TimeValue(timeRes));
337 stream += channelModel->AssignStreams(stream);
348 double freqSubBand = frequency;
349 for (
uint32_t n = 0; n < numRb; ++n)
353 freqSubBand += rbWidthHz / 2;
355 freqSubBand += rbWidthHz / 2;
362 double txPow_w = std::pow(10., (txPow_dbm - 30) / 10);
363 double txPowDens = (txPow_w / (numRb * rbWidthHz));
364 (*txPsd) = txPowDens;
365 txParams->psd = txPsd->Copy();
370 for (
int i = 0; i < simTime / timeRes; i++)
378 f.open(
"3gpp-channel-consistency-output.txt", std::ios::out);
379 f <<
"Time[s] TxPosX[m] TxPosY[m] RxPosX[m] RxPosY[m] ChannelState SNR[dB] Pathloss[dB]"
AttributeValue implementation for Boolean.
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'.
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.
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.
AttributeValue implementation for Time.
Hold an unsigned integer type.
Waypoint-based mobility model.
#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.
double Sum(const SpectrumValue &x)
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
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< 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 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 void CreateQuasiOmniBf(Ptr< PhasedArrayModel > antenna)
Set QuasiOmni beamforming vector to the antenna array.
static Ptr< ChannelConditionModel > m_condModel
the ChannelConditionModel object
static Ptr< ThreeGppPropagationLossModel > m_propagationLossModel
the log component
static void ComputeSnr(const ComputeSnrParams ¶ms)
Compute the average SNR.
static Ptr< ThreeGppSpectrumPropagationLossModel > m_spectrumLossModel
the SpectrumPropagationLossModel object