23#include "ns3/antenna-model.h"
24#include "ns3/core-module.h"
25#include "ns3/geocentric-constant-position-mobility-model.h"
26#include "ns3/isotropic-antenna-model.h"
27#include "ns3/mobility-model.h"
28#include "ns3/node-container.h"
30#include "ns3/spectrum-signal-parameters.h"
31#include "ns3/three-gpp-channel-model.h"
32#include "ns3/three-gpp-propagation-loss-model.h"
33#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
34#include "ns3/uniform-planar-array.h"
61 unsigned int numRbs = std::floor(bwHz / rbWidthHz);
62 double f = fcHz - (numRbs * rbWidthHz / 2.0);
63 double powerTx = pwrDbm;
66 for (
uint32_t numrb = 0; numrb < numRbs; ++numrb)
80 double powerTxW = std::pow(10., (powerTx - 30) / 10);
81 double txPowerDensity = (powerTxW / bwHz);
83 for (
auto psd = txPsd->ValuesBegin(); psd != txPsd->ValuesEnd(); ++psd)
85 *psd = txPowerDensity;
104 unsigned int numRbs = std::floor(bwHz / rbWidthHz);
105 double f = fcHz - (numRbs * rbWidthHz / 2.0);
108 std::vector<int> rbsId;
109 for (
uint32_t numrb = 0; numrb < numRbs; ++numrb)
119 rbsId.push_back(numrb);
126 const double ktDbmHz = -174.0;
127 double ktWHz = std::pow(10.0, (ktDbmHz - 30) / 10.0);
128 double noiseFigureLinear = std::pow(10.0, noiseFigureDb / 10.0);
130 double noisePowerSpectralDensity = ktWHz * noiseFigureLinear;
132 for (
auto rbId : rbsId)
134 (*txPsd)[rbId] = noisePowerSpectralDensity;
147 Ptr<MobilityModel>
txMob;
148 Ptr<MobilityModel>
rxMob;
177 double pResourceBlockBandwidth)
201 Angles completeAngle(txMob->GetPosition(), rxMob->GetPosition());
202 double hAngleRadian = completeAngle.
GetAzimuth();
206 uint64_t totNoArrayElements = thisAntenna->GetNumElems();
210 double power = 1.0 / sqrt(totNoArrayElements);
213 const double sinVAngleRadian = sin(vAngleRadian);
214 const double cosVAngleRadian = cos(vAngleRadian);
215 const double sinHAngleRadian = sin(hAngleRadian);
216 const double cosHAngleRadian = cos(hAngleRadian);
218 for (uint64_t ind = 0; ind < totNoArrayElements; ind++)
220 Vector loc = thisAntenna->GetElementLocation(ind);
221 double phase = -2 * M_PI *
222 (sinVAngleRadian * cosHAngleRadian * loc.x +
223 sinVAngleRadian * sinHAngleRadian * loc.y + cosVAngleRadian * loc.z);
224 antennaWeights[ind] = exp(std::complex<double>(0, phase)) * power;
228 thisAntenna->SetBeamformingVector(antennaWeights);
242 params.resourceBlockBandwidth);
244 NS_LOG_DEBUG(
"Average tx power " << 10 * log10(
Sum(*txPsd) * params.resourceBlockBandwidth)
251 params.resourceBlockBandwidth);
253 << 10 * log10(
Sum(*noisePsd) * params.resourceBlockBandwidth) <<
" dB");
257 NS_LOG_DEBUG(
"Pathloss " << -propagationGainDb <<
" dB");
258 double propagationGainLinear = std::pow(10.0, (propagationGainDb) / 10.0);
259 *(rxPsd) *= propagationGainLinear;
261 NS_ASSERT_MSG(params.txAntenna,
"params.txAntenna is nullptr!");
262 NS_ASSERT_MSG(params.rxAntenna,
"params.rxAntenna is nullptr!");
275 NS_LOG_DEBUG(
"Average rx power " << 10 * log10(
Sum(*rxSsp->psd) * params.bandwidth) <<
" dB");
278 NS_LOG_DEBUG(
"Average SNR " << 10 * log10(
Sum(*rxSsp->psd) /
Sum(*noisePsd)) <<
" dB");
282 << 10 * log10(
Sum(*rxSsp->psd) /
Sum(*noisePsd)) <<
" " << propagationGainDb
287main(
int argc,
char* argv[])
295 std::string scenario =
"NTN-Suburban";
298 double frequencyHz = 20e9;
299 double bandwidthHz = 400e6;
300 double RbBandwidthHz = 120e3;
303 double satEIRPDensity = 40;
304 double satAntennaGainDb = 58.5;
307 double vsatAntennaGainDb = 39.7;
308 double vsatAntennaNoiseFigureDb = 1.2;
313 cmd.AddValue(
"scenario",
314 "The 3GPP NTN scenario to use. Valid options are: "
315 "NTN-DenseUrban, NTN-Urban, NTN-Suburban, and NTN-Rural",
317 cmd.AddValue(
"frequencyHz",
"The carrier frequency in Hz", frequencyHz);
318 cmd.AddValue(
"bandwidthHz",
"The bandwidth in Hz", bandwidthHz);
319 cmd.AddValue(
"satEIRPDensity",
"The satellite EIRP density in dBW/MHz", satEIRPDensity);
320 cmd.AddValue(
"satAntennaGainDb",
"The satellite antenna gain in dB", satAntennaGainDb);
321 cmd.AddValue(
"vsatAntennaGainDb",
"The UE VSAT antenna gain in dB", vsatAntennaGainDb);
322 cmd.AddValue(
"vsatAntennaNoiseFigureDb",
323 "The UE VSAT antenna noise figure in dB",
324 vsatAntennaNoiseFigureDb);
325 cmd.Parse(argc, argv);
329 double txPowDbm = (satEIRPDensity + 10 * log10(bandwidthHz / 1e6) - satAntennaGainDb) + 30;
331 NS_LOG_DEBUG(
"Transmitting power: " << txPowDbm <<
"dBm, (" << pow(10., (txPowDbm - 30) / 10)
347 if (scenario ==
"NTN-DenseUrban")
354 else if (scenario ==
"NTN-Urban")
359 else if (scenario ==
"NTN-Suburban")
365 else if (scenario ==
"NTN-Rural")
405 txMob->SetGeographicPosition(Vector(45.40869, 11.89448, 35786000));
406 rxMob->SetGeographicPosition(Vector(45.40869, 11.89448, 14.0));
410 txMob->SetCoordinateTranslationReferencePoint(
411 Vector(45.40869, 11.89448, 0.0));
412 rxMob->SetCoordinateTranslationReferencePoint(
413 Vector(45.40869, 11.89448, 0.0));
420 nodes.Get(0)->AggregateObject(txMob);
421 nodes.Get(1)->AggregateObject(rxMob);
453 resultsFile.open(
"ntn-snr-trace.txt", std::ios::out);
456 for (
int i = 0; i < floor(simTimeMs / timeResMs); i++)
463 vsatAntennaNoiseFigureDb,
Class holding the azimuth and inclination angles of spherical coordinates.
double GetInclination() const
Getter for inclination angle.
double GetAzimuth() const
Getter for azimuth angle.
AttributeValue implementation for Boolean.
Parse command-line arguments.
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.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
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.
Base class for the 3GPP channel condition models.
static TypeId GetTypeId()
Register this type.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Register this type.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Register this type.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Register this type.
static TypeId GetTypeId()
Get the type ID.
Base class for the 3GPP propagation models.
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.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void SetDefault(std::string name, const AttributeValue &value)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
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 MilliSeconds(uint64_t 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 > ConstCast(const Ptr< T2 > &p)
Cast a Ptr.
double Sum(const SpectrumValue &x)
A structure that holds the parameters for the ComputeSnr function.
ComputeSnrParams(Ptr< MobilityModel > pTxMob, Ptr< MobilityModel > pRxMob, double pTxPow, double pNoiseFigure, Ptr< PhasedArrayModel > pTxAntenna, Ptr< PhasedArrayModel > pRxAntenna, double pFrequency, double pBandwidth, double pResourceBlockBandwidth)
Constructor.
Ptr< PhasedArrayModel > txAntenna
the tx antenna array
Ptr< MobilityModel > rxMob
the rx mobility model
double bandwidth
the total bandwidth in Hz
double noiseFigure
the noise figure in dB
double resourceBlockBandwidth
the Resource Block bandwidth in Hz
double txPow
the tx power in dBm
double frequency
the carrier frequency in Hz
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
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(double fcHz, double noiseFigureDb, double bwHz, double rbWidthHz)
Create the noise PSD for the.
static std::ofstream resultsFile
The results file.
static void ComputeSnr(ComputeSnrParams ¶ms)
Compute the average SNR.
static void DoBeamforming(Ptr< MobilityModel > rxMob, Ptr< PhasedArrayModel > thisAntenna, Ptr< MobilityModel > txMob)
Perform the beamforming using the DFT beamforming method.
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double fcHz, double pwrDbm, double bwHz, double rbWidthHz)
Create the PSD for the TX.
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