spectrum: Support passing the TX and RX PhasedArrayModel objects to spectrum model

This possibility is needed for the types of spectrum propagation models that need to have a pointer
to the TX and RX antenna arrays to perform calculations, such as e.g.,
ThreeGppSpectrumPropagationLossModel, which currently has hard limitation of having a maximum of 1
antenna array instance per device. ThreeGppSpectrumPropagationLossModel now inherits a new class
PhasedArraySpectrumPropagationLossModel. Its DoCalcRxPowerSpectralDensity function has now two
additional parameters: TX and RX antenna arrays. Also, AddDevice function is removed from
ThreeGppSpectrumPropagationLossModel, because it is not anymore needed to specify for each
device its TX/RX antenna, since these are now passed as parameters. Hence, to use
ThreeGppSpectrumPropagationLossModel, when implementing Spectrum PHY features,
modules should implement the function of SpectrumPhy GetAntenna to return the instance of
PhasedArrayModel of that SpectrumPhy. These instances will be passed by MultiModelSpectrumChannel
(one of the core classes in the spectrum module) to propagation classes, children of
PhasedArraySpectrumPropagationLossModel, when it is necessary to DoCalcRxPowerSpectralDensity to
callculate the propagation loss.

Additionally: Fixed pair key generation for 3gpp channel model: Previous implementation was
using a cantor function of two integer of 32 bits and as a results was giving a unique
representatio of 32 bits. This is wrong, because such function needed even more than 64
bits to represent that value. Even if in ns-3 simulation we are not going to have such large
node numbers, we should fix this. Instead of just changing 64 bits from cantor function, I propose to
replace the cantor function with just simple concatenation of two 32 bits.

I also propose moving min and max inside of the function, to prevent some eventual future errors
in using GetKey, because with the previous implementation there was assumption that who calls GetKey
will previously sort its parameters, and first provide the min value, and then the max value,
and this was not even documented.
This commit is contained in:
bbojovic
2021-07-01 08:44:46 +02:00
committed by Biljana Bojovic
parent 33f2ee841b
commit 4ca8b12ea0
21 changed files with 565 additions and 120 deletions

View File

@@ -54,6 +54,42 @@ static Ptr<ThreeGppPropagationLossModel> m_propagationLossModel; //!< the Propag
static Ptr<ThreeGppSpectrumPropagationLossModel> m_spectrumLossModel; //!< the SpectrumPropagationLossModel object
static Ptr<ChannelConditionModel> m_condModel; //!< the ChannelConditionModel object
/*
* \brief A structure that holds the parameters for the ComputeSnr
* function. In this way the problem with the limited
* number of parameters of method Schedule is avoided.
*/
struct ComputeSnrParams
{
Ptr<MobilityModel> txMob; //!< the tx mobility model
Ptr<MobilityModel> rxMob; //!< the rx mobility model
Ptr<SpectrumValue> txPsd; //!< the PSD of the tx signal
double noiseFigure; //!< the noise figure in dB
Ptr<PhasedArrayModel> txAntenna; //!< the tx antenna array
Ptr<PhasedArrayModel> rxAntenna; //!< the rx antenna array
/**
* \brief Constructor
* \param pTxMob the tx mobility model
* \param pRxMob the rx mobility model
* \param pTxPsd the PSD of the tx signal
* \param pNoiseFigure the noise figure in dB
* \param pTxAntenna the tx antenna array
* \param pRxAntenna the rx antenna array
*/
ComputeSnrParams (Ptr<MobilityModel> pTxMob, Ptr<MobilityModel> pRxMob,
Ptr<SpectrumValue> pTxPsd, double pNoiseFigure,
Ptr<PhasedArrayModel> pTxAntenna, Ptr<PhasedArrayModel> pRxAntenna)
{
txMob = pTxMob;
rxMob = pRxMob;
txPsd = pTxPsd;
noiseFigure = pNoiseFigure;
txAntenna = pTxAntenna;
rxAntenna = pRxAntenna;
}
};
/**
* Perform the beamforming using the DFT beamforming method
* \param thisDevice the device performing the beamforming
@@ -78,36 +114,33 @@ DoBeamforming (Ptr<NetDevice> thisDevice, Ptr<PhasedArrayModel> thisAntenna, Ptr
/**
* Compute the average SNR
* \param txMob the tx mobility model
* \param rxMob the rx mobility model
* \param txPsd the PSD of the transmitting signal
* \param noiseFigure the noise figure in dB
* \param params A structure that holds a bunch of parameters needed by ComputSnr function to calculate the average SNR
*/
static void
ComputeSnr (Ptr<MobilityModel> txMob, Ptr<MobilityModel> rxMob, Ptr<const SpectrumValue> txPsd, double noiseFigure)
ComputeSnr (ComputeSnrParams& params)
{
Ptr<SpectrumValue> rxPsd = txPsd->Copy ();
Ptr<SpectrumValue> rxPsd = params.txPsd->Copy ();
// check the channel condition
Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition (txMob, rxMob);
Ptr<ChannelCondition> cond = m_condModel->GetChannelCondition (params.txMob, params.rxMob);
// apply the pathloss
double propagationGainDb = m_propagationLossModel->CalcRxPower (0, txMob, rxMob);
double propagationGainDb = m_propagationLossModel->CalcRxPower (0, params.txMob, params.rxMob);
NS_LOG_DEBUG ("Pathloss " << -propagationGainDb << " dB");
double propagationGainLinear = std::pow (10.0, (propagationGainDb) / 10.0);
*(rxPsd) *= propagationGainLinear;
// apply the fast fading and the beamforming gain
rxPsd = m_spectrumLossModel->CalcRxPowerSpectralDensity (rxPsd, txMob, rxMob);
rxPsd = m_spectrumLossModel->CalcRxPowerSpectralDensity (rxPsd, params.txMob, params.rxMob, params.txAntenna, params.rxAntenna);
NS_LOG_DEBUG ("Average rx power " << 10 * log10 (Sum (*rxPsd) * 180e3) << " dB");
// create the noise psd
// taken from lte-spectrum-value-helper
const double kT_dBm_Hz = -174.0; // dBm/Hz
double kT_W_Hz = std::pow (10.0, (kT_dBm_Hz - 30) / 10.0);
double noiseFigureLinear = std::pow (10.0, noiseFigure / 10.0);
double noiseFigureLinear = std::pow (10.0, params.noiseFigure / 10.0);
double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
Ptr<SpectrumValue> noisePsd = Create <SpectrumValue> (txPsd->GetSpectrumModel ());
Ptr<SpectrumValue> noisePsd = Create <SpectrumValue> (params.txPsd->GetSpectrumModel ());
(*noisePsd) = noisePowerSpectralDensity;
// compute the SNR
@@ -117,10 +150,10 @@ ComputeSnr (Ptr<MobilityModel> txMob, Ptr<MobilityModel> rxMob, Ptr<const Spectr
std::ofstream f;
f.open ("example-output.txt", std::ios::out | std::ios::app);
f << Simulator::Now ().GetSeconds () << " " // time [s]
<< txMob->GetPosition ().x << " "
<< txMob->GetPosition ().y << " "
<< rxMob->GetPosition ().x << " "
<< rxMob->GetPosition ().y << " "
<< params.txMob->GetPosition ().x << " "
<< params.txMob->GetPosition ().y << " "
<< params.rxMob->GetPosition ().x << " "
<< params.rxMob->GetPosition ().y << " "
<< cond->GetLosCondition () << " " // channel state
<< 10 * log10 (Sum (*rxPsd) / Sum (*noisePsd)) << " " // SNR [dB]
<< -propagationGainDb << std::endl; // pathloss [dB]
@@ -301,10 +334,6 @@ main (int argc, char *argv[])
m_spectrumLossModel = CreateObjectWithAttributes<ThreeGppSpectrumPropagationLossModel> ("ChannelModel", PointerValue (channelModel));
m_spectrumLossModel->SetAttribute ("vScatt", DoubleValue (vScatt));
// initialize the devices in the ThreeGppSpectrumPropagationLossModel
m_spectrumLossModel->AddDevice (txDev, txAntenna);
m_spectrumLossModel->AddDevice (rxDev, rxAntenna);
BuildingsHelper::Install (nodes);
// set the beamforming vectors
@@ -332,7 +361,7 @@ main (int argc, char *argv[])
for (int i = 0; i < simTime / timeRes; i++)
{
Simulator::Schedule (timeRes * i, &ComputeSnr, txMob, rxMob, txPsd, noiseFigure);
Simulator::Schedule (timeRes * i, &ComputeSnr, ComputeSnrParams (txMob, rxMob, txPsd, noiseFigure, txAntenna, rxAntenna));
}
// initialize the output file