23#include "ns3/channel-condition-model.h"
24#include "ns3/constant-position-mobility-model.h"
25#include "ns3/core-module.h"
26#include "ns3/geocentric-constant-position-mobility-model.h"
27#include "ns3/isotropic-antenna-model.h"
28#include "ns3/mobility-model.h"
29#include "ns3/net-device.h"
30#include "ns3/node-container.h"
32#include "ns3/parabolic-antenna-model.h"
33#include "ns3/simple-net-device.h"
34#include "ns3/spectrum-signal-parameters.h"
35#include "ns3/three-gpp-channel-model.h"
36#include "ns3/three-gpp-propagation-loss-model.h"
37#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
38#include "ns3/uniform-planar-array.h"
39#include <ns3/antenna-model.h>
66 unsigned int numRbs = std::floor(bwHz / rbWidthHz);
67 double f = fcHz - (numRbs * rbWidthHz / 2.0);
68 double powerTx = pwrDbm;
71 for (
uint32_t numrb = 0; numrb < numRbs; ++numrb)
85 double powerTxW = std::pow(10., (powerTx - 30) / 10);
86 double txPowerDensity = (powerTxW / bwHz);
88 for (
auto psd = txPsd->ValuesBegin(); psd != txPsd->ValuesEnd(); ++psd)
90 *psd = txPowerDensity;
109 unsigned int numRbs = std::floor(bwHz / rbWidthHz);
110 double f = fcHz - (numRbs * rbWidthHz / 2.0);
113 std::vector<int> rbsId;
114 for (
uint32_t numrb = 0; numrb < numRbs; ++numrb)
124 rbsId.push_back(numrb);
131 const double ktDbmHz = -174.0;
132 double ktWHz = std::pow(10.0, (ktDbmHz - 30) / 10.0);
133 double noiseFigureLinear = std::pow(10.0, noiseFigureDb / 10.0);
135 double noisePowerSpectralDensity = ktWHz * noiseFigureLinear;
137 for (
auto rbId : rbsId)
139 (*txPsd)[rbId] = noisePowerSpectralDensity;
182 double pResourceBlockBandwidth)
208 Vector aPos = thisDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
209 Vector bPos = otherDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
212 Angles completeAngle(bPos, aPos);
213 double hAngleRadian = completeAngle.
GetAzimuth();
217 uint64_t totNoArrayElements = thisAntenna->GetNumElems();
221 double power = 1.0 / sqrt(totNoArrayElements);
224 const double sinVAngleRadian = sin(vAngleRadian);
225 const double cosVAngleRadian = cos(vAngleRadian);
226 const double sinHAngleRadian = sin(hAngleRadian);
227 const double cosHAngleRadian = cos(hAngleRadian);
229 for (uint64_t ind = 0; ind < totNoArrayElements; ind++)
231 Vector loc = thisAntenna->GetElementLocation(ind);
232 double phase = -2 * M_PI *
233 (sinVAngleRadian * cosHAngleRadian * loc.x +
234 sinVAngleRadian * sinHAngleRadian * loc.y + cosVAngleRadian * loc.z);
235 antennaWeights[ind] = exp(std::complex<double>(0, phase)) * power;
239 thisAntenna->SetBeamformingVector(antennaWeights);
253 params.resourceBlockBandwidth);
255 NS_LOG_DEBUG(
"Average tx power " << 10 * log10(
Sum(*txPsd) * params.resourceBlockBandwidth)
262 params.resourceBlockBandwidth);
264 << 10 * log10(
Sum(*noisePsd) * params.resourceBlockBandwidth) <<
" dB");
268 NS_LOG_DEBUG(
"Pathloss " << -propagationGainDb <<
" dB");
269 double propagationGainLinear = std::pow(10.0, (propagationGainDb) / 10.0);
270 *(rxPsd) *= propagationGainLinear;
272 NS_ASSERT_MSG(params.txAntenna,
"params.txAntenna is nullptr!");
273 NS_ASSERT_MSG(params.rxAntenna,
"params.rxAntenna is nullptr!");
286 NS_LOG_DEBUG(
"Average rx power " << 10 * log10(
Sum(*rxSsp->psd) * params.bandwidth) <<
" dB");
289 NS_LOG_DEBUG(
"Average SNR " << 10 * log10(
Sum(*rxSsp->psd) /
Sum(*noisePsd)) <<
" dB");
293 << 10 * log10(
Sum(*rxSsp->psd) /
Sum(*noisePsd)) <<
" " << propagationGainDb
298main(
int argc,
char* argv[])
306 std::string scenario =
"NTN-Suburban";
309 double frequencyHz = 20e9;
310 double bandwidthHz = 400e6;
311 double RbBandwidthHz = 120e3;
314 double satEIRPDensity = 40;
315 double satAntennaGainDb = 58.5;
318 double vsatAntennaGainDb = 39.7;
319 double vsatAntennaNoiseFigureDb = 1.2;
324 cmd.AddValue(
"scenario",
325 "The 3GPP NTN scenario to use. Valid options are: "
326 "NTN-DenseUrban, NTN-Urban, NTN-Suburban, and NTN-Rural",
328 cmd.AddValue(
"frequencyHz",
"The carrier frequency in Hz", frequencyHz);
329 cmd.AddValue(
"bandwidthHz",
"The bandwidth in Hz", bandwidthHz);
330 cmd.AddValue(
"satEIRPDensity",
"The satellite EIRP density in dBW/MHz", satEIRPDensity);
331 cmd.AddValue(
"satAntennaGainDb",
"The satellite antenna gain in dB", satAntennaGainDb);
332 cmd.AddValue(
"vsatAntennaGainDb",
"The UE VSAT antenna gain in dB", vsatAntennaGainDb);
333 cmd.AddValue(
"vsatAntennaNoiseFigureDb",
334 "The UE VSAT antenna noise figure in dB",
335 vsatAntennaNoiseFigureDb);
336 cmd.Parse(argc, argv);
340 double txPowDbm = (satEIRPDensity + 10 * log10(bandwidthHz / 1e6) - satAntennaGainDb) + 30;
342 NS_LOG_DEBUG(
"Transmitting power: " << txPowDbm <<
"dBm, (" << pow(10., (txPowDbm - 30) / 10)
358 if (scenario ==
"NTN-DenseUrban")
365 else if (scenario ==
"NTN-Urban")
370 else if (scenario ==
"NTN-Suburban")
376 else if (scenario ==
"NTN-Rural")
426 txMob->SetGeographicPosition(Vector(45.40869, 11.89448, 35786000));
427 rxMob->SetGeographicPosition(Vector(45.40869, 11.89448, 14.0));
431 txMob->SetCoordinateTranslationReferencePoint(
432 Vector(45.40869, 11.89448, 0.0));
433 rxMob->SetCoordinateTranslationReferencePoint(
434 Vector(45.40869, 11.89448, 0.0));
474 resultsFile.open(
"ntn-snr-trace.txt", std::ios::out);
477 for (
int i = 0; i < floor(simTimeMs / timeResMs); i++)
484 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.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
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.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
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.
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
static Ptr< ThreeGppPropagationLossModel > m_propagationLossModel
the PropagationLossModel object
static void DoBeamforming(Ptr< NetDevice > thisDevice, Ptr< PhasedArrayModel > thisAntenna, Ptr< NetDevice > otherDevice)
Perform the beamforming using the DFT beamforming method.
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 Ptr< ThreeGppSpectrumPropagationLossModel > m_spectrumLossModel
the SpectrumPropagationLossModel object
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double fcHz, double pwrDbm, double bwHz, double rbWidthHz)
Create the PSD for the TX.