16#include "ns3/double.h"
18#include "ns3/net-device.h"
20#include "ns3/pointer.h"
21#include "ns3/simulator.h"
22#include "ns3/string.h"
54 TypeId(
"ns3::ThreeGppSpectrumPropagationLossModel")
56 .SetGroupName(
"Spectrum")
60 "The channel model. It needs to implement the MatrixBasedChannelModel interface",
112 size_t sAntNumElems = sW.
GetSize();
113 size_t uAntNumElems = uW.
GetSize();
114 NS_ASSERT(uAntNumElems == params->m_channel.GetNumRows());
115 NS_ASSERT(sAntNumElems == params->m_channel.GetNumCols());
117 <<
" s antenna elements, and with "
118 <<
" s ports: " << sAnt->GetNumPorts()
119 <<
" u ports: " << uAnt->GetNumPorts());
120 NS_ASSERT_MSG((sAnt !=
nullptr) && (uAnt !=
nullptr),
"Improper call to the method");
121 size_t numClusters = params->m_channel.GetNumPages();
129 for (
auto sPortIdx = 0; sPortIdx < sAnt->GetNumPorts(); sPortIdx++)
131 for (
auto uPortIdx = 0; uPortIdx < uAnt->GetNumPorts(); uPortIdx++)
133 for (
size_t cIndex = 0; cIndex < numClusters; cIndex++)
135 longTerm->Elem(uPortIdx, sPortIdx, cIndex) =
150 uint16_t cIndex)
const
155 auto sPortElems = sAnt->GetNumElemsPerPort();
156 auto uPortElems = uAnt->GetNumElemsPerPort();
157 auto startS = sAnt->ArrayIndexFromPortIndex(sPortIdx, 0);
158 auto startU = uAnt->ArrayIndexFromPortIndex(uPortIdx, 0);
159 std::complex<double> txSum(0, 0);
161 auto sIndex = startS;
166 const auto uElemsPerPort = uAnt->GetHElemsPerPort();
167 const auto sElemsPerPort = sAnt->GetHElemsPerPort();
168 for (
size_t tIndex = 0; tIndex < sPortElems; tIndex++, sIndex++)
170 std::complex<double> rxSum(0, 0);
171 auto uIndex = startU;
172 for (
size_t rIndex = 0; rIndex < uPortElems; rIndex++, uIndex++)
174 rxSum += uW[uIndex - startU] * params->m_channel(uIndex, sIndex, cIndex);
175 auto testV = (rIndex % uElemsPerPort);
176 auto ptInc = uElemsPerPort - 1;
179 auto incVal = uAnt->GetNumColumns() - uElemsPerPort;
184 txSum += sW[sIndex - startS] * rxSum;
185 auto testV = (tIndex % sElemsPerPort);
186 auto ptInc = sElemsPerPort - 1;
189 size_t incVal = sAnt->GetNumColumns() - sElemsPerPort;
202 const Vector& sSpeed,
203 const ns3::Vector& uSpeed,
206 bool isReverse)
const
211 size_t numCluster = channelMatrix->m_channel.GetNumPages();
216 double factor = 2 * M_PI * slotTime *
GetFrequency() / 3e8;
221 NS_ASSERT(numCluster <= channelParams->m_alpha.size());
222 NS_ASSERT(numCluster <= channelParams->m_D.size());
227 NS_ASSERT(numCluster <= longTerm->GetNumPages());
230 bool isSameDir = (channelParams->m_nodeIds == channelMatrix->m_nodeIds);
236 using DPV = std::vector<std::pair<double, double>>;
238 const auto& cachedAngleSincos = channelParams->m_cachedAngleSincos;
239 const DPV& zoa = cachedAngleSincos[isSameDir ? MBCM::ZOA_INDEX : MBCM::ZOD_INDEX];
240 const DPV& zod = cachedAngleSincos[isSameDir ? MBCM::ZOD_INDEX : MBCM::ZOA_INDEX];
241 const DPV& aoa = cachedAngleSincos[isSameDir ? MBCM::AOA_INDEX : MBCM::AOD_INDEX];
242 const DPV& aod = cachedAngleSincos[isSameDir ? MBCM::AOD_INDEX : MBCM::AOA_INDEX];
244 for (
size_t cIndex = 0; cIndex < numCluster; cIndex++)
257 double alpha = channelParams->m_alpha[cIndex];
258 double D = channelParams->m_D[cIndex];
263 ((zoa[cIndex].first * aoa[cIndex].second * uSpeed.x +
264 zoa[cIndex].first * aoa[cIndex].first * uSpeed.y + zoa[cIndex].second * uSpeed.z) +
265 (zod[cIndex].
first * aod[cIndex].
second * sSpeed.x +
266 zod[cIndex].first * aod[cIndex].first * sSpeed.y + zod[cIndex].second * sSpeed.z) +
268 doppler[cIndex] = std::complex<double>(cos(tempDoppler), sin(tempDoppler));
283 NS_ASSERT_MSG(rxParams->psd->GetValuesN() == rxParams->spectrumChannelMatrix->GetNumPages(),
284 "RX PSD and the spectrum channel matrix should have the same number of RBs ");
289 if (!rxParams->precodingMatrix)
295 page.Elem(0, 0, 0) = 1.0 / sqrt(rxParams->spectrumChannelMatrix->GetNumCols());
296 for (
size_t rowI = 0; rowI < rxParams->spectrumChannelMatrix->GetNumCols(); rowI++)
298 page.Elem(rowI, 0, 0) = page.Elem(0, 0, 0);
302 page.MakeNCopies(rxParams->spectrumChannelMatrix->GetNumPages()));
306 p = rxParams->precodingMatrix;
320 for (
uint32_t rbIdx = 0; rbIdx < rxParams->psd->GetValuesN(); ++rbIdx)
322 (*rxParams->psd)[rbIdx] = 0.0;
323 for (
size_t rxPort = 0; rxPort < hP.
GetNumRows(); ++rxPort)
325 for (
size_t txStream = 0; txStream < hP.
GetNumCols(); ++txStream)
327 (*rxParams->psd)[rbIdx] +=
328 std::real(std::conj(hP(rxPort, txStream, rbIdx)) * hP(rxPort, txStream, rbIdx));
344 bool isReverse)
const
346 size_t numCluster = channelMatrix->m_channel.GetNumPages();
347 auto numRb = inPsd->GetValuesN();
349 auto directionalLongTerm = isReverse ? longTerm->Transpose() : (*longTerm);
357 double rbWidth = inPsd->ConstBandsBegin()->fh - inPsd->ConstBandsBegin()->fl;
359 if (channelParams->m_cachedDelaySincos.GetNumRows() != numRb ||
360 channelParams->m_cachedDelaySincos.GetNumCols() != numCluster ||
361 channelParams->m_cachedRbWidth != rbWidth)
363 channelParams->m_cachedRbWidth = rbWidth;
365 auto sbit = inPsd->ConstBandsBegin();
366 for (
unsigned i = 0; i < numRb; i++)
368 double fsb = (*sbit).fc;
369 for (std::size_t cIndex = 0; cIndex < numCluster; cIndex++)
371 double delay = -2 * M_PI * fsb * (channelParams->m_delay[cIndex]);
372 channelParams->m_cachedDelaySincos(i, cIndex) =
373 std::complex<double>(cos(delay), sin(delay));
380 auto delaySincosCopy = channelParams->m_cachedDelaySincos;
381 for (
size_t iRb = 0; iRb < inPsd->GetValuesN(); iRb++)
383 for (std::size_t cIndex = 0; cIndex < numCluster; cIndex++)
385 delaySincosCopy(iRb, cIndex) *= doppler[cIndex];
393 auto vit = inPsd->ValuesBegin();
396 while (vit != inPsd->ValuesEnd())
400 auto sqrtVit = sqrt(*vit);
401 for (
auto rxPortIdx = 0; rxPortIdx < numRxPorts; rxPortIdx++)
403 for (
auto txPortIdx = 0; txPortIdx < numTxPorts; txPortIdx++)
405 std::complex<double> subsbandGain(0.0, 0.0);
406 for (
size_t cIndex = 0; cIndex < numCluster; cIndex++)
408 subsbandGain += directionalLongTerm(rxPortIdx, txPortIdx, cIndex) *
409 delaySincosCopy(iRb, cIndex);
413 chanSpct->Elem(rxPortIdx, txPortIdx, iRb) = sqrtVit * subsbandGain;
435 channelMatrix->IsReverse(aPhasedArrayModel->GetId(), bPhasedArrayModel->GetId());
436 auto sAntenna = isReverse ? bPhasedArrayModel : aPhasedArrayModel;
437 auto uAntenna = isReverse ? aPhasedArrayModel : bPhasedArrayModel;
443 sW = aPhasedArrayModel->GetBeamformingVector();
444 uW = bPhasedArrayModel->GetBeamformingVector();
448 sW = bPhasedArrayModel->GetBeamformingVector();
449 uW = aPhasedArrayModel->GetBeamformingVector();
453 bool notFound =
false;
456 uint64_t longTermId =
462 NS_LOG_DEBUG(
"found the long term component in the map");
468 update = (
m_longTermMap[longTermId]->m_channel->m_generatedTime !=
469 channelMatrix->m_generatedTime ||
478 if (update || notFound)
482 longTerm =
CalcLongTerm(channelMatrix, sAntenna, uAntenna);
484 longTermItem->m_longTerm = longTerm;
485 longTermItem->m_channel = channelMatrix;
486 longTermItem->m_sW = std::move(sW);
487 longTermItem->m_uW = std::move(uW);
505 NS_LOG_FUNCTION(
this << spectrumSignalParams << a << b << aPhasedArrayModel
506 << bPhasedArrayModel);
510 NS_ASSERT_MSG(aPhasedArrayModel,
"Antenna not found for node " << aId);
511 NS_LOG_DEBUG(
"a node " << aId <<
" antenna " << aPhasedArrayModel);
512 NS_ASSERT_MSG(bPhasedArrayModel,
"Antenna not found for node " << bId);
513 NS_LOG_DEBUG(
"b node " << bId <<
" antenna " << bPhasedArrayModel);
516 m_channelModel->GetChannel(a, b, aPhasedArrayModel, bPhasedArrayModel);
522 GetLongTerm(channelMatrix, aPhasedArrayModel, bPhasedArrayModel);
525 channelMatrix->IsReverse(aPhasedArrayModel->GetId(), bPhasedArrayModel->GetId());
534 aPhasedArrayModel->GetNumPorts(),
535 bPhasedArrayModel->GetNumPorts(),
Hold a value for an Attribute.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
This is an interface for a channel model that can be described by a channel matrix,...
static const uint8_t AOA_INDEX
index of the AOA value in the m_angle array
static const uint8_t ZOD_INDEX
index of the ZOD value in the m_angle array
static const uint8_t AOD_INDEX
index of the AOD value in the m_angle array
static const uint8_t ZOA_INDEX
index of the ZOA value in the m_angle array
static uint64_t GetKey(uint32_t a, uint32_t b)
Generate a unique value for the pair of unsigned integer of 32 bits, where the order does not matter,...
spectrum-aware propagation loss model that is compatible with PhasedArrayModel type of ns-3 antenna
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Hold variables of type string.
3GPP Spectrum Propagation Loss Model
void GetChannelModelAttribute(const std::string &name, AttributeValue &value) const
Returns the value of an attribute belonging to the associated MatrixBasedChannelModel instance.
Ptr< SpectrumSignalParameters > DoCalcRxPowerSpectralDensity(Ptr< const SpectrumSignalParameters > spectrumSignalParams, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, Ptr< const PhasedArrayModel > aPhasedArrayModel, Ptr< const PhasedArrayModel > bPhasedArrayModel) const override
Computes the received PSD.
Ptr< MatrixBasedChannelModel > m_channelModel
the model to generate the channel matrix
Ptr< MatrixBasedChannelModel::Complex3DVector > GenSpectrumChannelMatrix(Ptr< SpectrumValue > inPsd, Ptr< const MatrixBasedChannelModel::Complex3DVector > longTerm, Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, Ptr< const MatrixBasedChannelModel::ChannelParams > channelParams, PhasedArrayModel::ComplexVector doppler, uint8_t numTxPorts, uint8_t numRxPorts, bool isReverse) const
Computes the frequency-domain channel matrix with the dimensions numRxPorts*numTxPorts*numRBs.
Ptr< const MatrixBasedChannelModel::Complex3DVector > GetLongTerm(Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, Ptr< const PhasedArrayModel > aPhasedArrayModel, Ptr< const PhasedArrayModel > bPhasedArrayModel) const
Looks for the long term component in m_longTermMap.
void SetChannelModel(Ptr< MatrixBasedChannelModel > channel)
Set the channel model object.
Ptr< const MatrixBasedChannelModel::Complex3DVector > CalcLongTerm(Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, Ptr< const PhasedArrayModel > sAnt, Ptr< const PhasedArrayModel > uAnt) const
Computes the long term component.
~ThreeGppSpectrumPropagationLossModel() override
Destructor.
std::unordered_map< uint64_t, Ptr< const LongTerm > > m_longTermMap
map containing the long term components
double GetFrequency() const
Get the operating frequency.
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void SetChannelModelAttribute(const std::string &name, const AttributeValue &value)
Sets the value of an attribute belonging to the associated MatrixBasedChannelModel instance.
Ptr< MatrixBasedChannelModel > GetChannelModel() const
Get the channel model object.
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Get the type ID.
Ptr< SpectrumSignalParameters > CalcBeamformingGain(Ptr< const SpectrumSignalParameters > params, Ptr< const MatrixBasedChannelModel::Complex3DVector > longTerm, Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, Ptr< const MatrixBasedChannelModel::ChannelParams > channelParams, const Vector &sSpeed, const Vector &uSpeed, uint8_t numTxPorts, uint8_t numRxPorts, bool isReverse) const
Computes the beamforming gain and applies it to the TX PSD.
std::complex< double > CalculateLongTermComponent(Ptr< const MatrixBasedChannelModel::ChannelMatrix > params, Ptr< const PhasedArrayModel > sAnt, Ptr< const PhasedArrayModel > uAnt, uint16_t sPortIdx, uint16_t uPortIdx, uint16_t cIndex) const
Computes a longTerm component from a specific port of s device to the specific port of u device and f...
ThreeGppSpectrumPropagationLossModel()
Constructor.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
size_t GetNumRows() const
size_t GetNumCols() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#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.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
MatrixArray< std::complex< double > > ComplexMatrixArray
Create an alias for MatrixArray using complex type.