A Discrete-Event Network Simulator
API
three-gpp-spectrum-propagation-loss-model.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2015, NYU WIRELESS, Tandon School of Engineering,
4 * New York University
5 * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
6 * University of Padova
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include "ns3/log.h"
27#include "ns3/net-device.h"
28#include "ns3/node.h"
29#include "ns3/double.h"
30#include "ns3/string.h"
31#include "ns3/simulator.h"
32#include "ns3/pointer.h"
33#include <map>
34
35namespace ns3 {
36
37NS_LOG_COMPONENT_DEFINE ("ThreeGppSpectrumPropagationLossModel");
38
39NS_OBJECT_ENSURE_REGISTERED (ThreeGppSpectrumPropagationLossModel);
40
42{
43 NS_LOG_FUNCTION (this);
44}
45
47{
48 NS_LOG_FUNCTION (this);
49}
50
51void
53{
54 m_longTermMap.clear ();
55 m_channelModel->Dispose ();
56 m_channelModel = nullptr;
57}
58
61{
62 static TypeId tid = TypeId ("ns3::ThreeGppSpectrumPropagationLossModel")
64 .SetGroupName ("Spectrum")
65 .AddConstructor<ThreeGppSpectrumPropagationLossModel> ()
66 .AddAttribute("ChannelModel",
67 "The channel model. It needs to implement the MatrixBasedChannelModel interface",
68 StringValue("ns3::ThreeGppChannelModel"),
71 MakePointerChecker<MatrixBasedChannelModel> ())
72 ;
73 return tid;
74}
75
76void
78{
80}
81
84{
85 return m_channelModel;
86}
87
88double
90{
91 DoubleValue freq;
92 m_channelModel->GetAttribute ("Frequency", freq);
93 return freq.Get ();
94}
95
96void
98{
99 m_channelModel->SetAttribute (name, value);
100}
101
102void
104{
105 m_channelModel->GetAttribute (name, value);
106}
107
111 const PhasedArrayModel::ComplexVector &uW) const
112{
113 NS_LOG_FUNCTION (this);
114
115 uint16_t sAntenna = static_cast<uint16_t> (sW.size ());
116 uint16_t uAntenna = static_cast<uint16_t> (uW.size ());
117
118 NS_ASSERT (uAntenna == params->m_channel.size ());
119 NS_ASSERT (sAntenna == params->m_channel.at (0).size());
120
121 NS_LOG_DEBUG ("CalcLongTerm with sAntenna " << sAntenna << " uAntenna " << uAntenna);
122 //store the long term part to reduce computation load
123 //only the small scale fading needs to be updated if the large scale parameters and antenna weights remain unchanged.
125 uint8_t numCluster = static_cast<uint8_t> (params->m_channel[0][0].size ());
126
127 NS_ASSERT (uAntenna == params->m_channel.size ());
128 NS_ASSERT (sAntenna == params->m_channel.at (0).size());
129
130 for (uint8_t cIndex = 0; cIndex < numCluster; cIndex++)
131 {
132 std::complex<double> txSum (0, 0);
133 for (uint16_t sIndex = 0; sIndex < sAntenna; sIndex++)
134 {
135 std::complex<double> rxSum (0, 0);
136 for (uint16_t uIndex = 0; uIndex < uAntenna; uIndex++)
137 {
138 rxSum = rxSum + uW[uIndex] * params->m_channel[uIndex][sIndex][cIndex];
139 }
140 txSum = txSum + sW[sIndex] * rxSum;
141 }
142 longTerm.push_back (txSum);
143 }
144 return longTerm;
145}
146
152 const ns3::Vector &sSpeed, const ns3::Vector &uSpeed) const
153{
154 NS_LOG_FUNCTION (this);
155
156 Ptr<SpectrumValue> tempPsd = Copy<SpectrumValue> (txPsd);
157
158 //channel[rx][tx][cluster]
159 uint8_t numCluster = static_cast<uint8_t> (channelMatrix->m_channel[0][0].size ());
160
161 // compute the doppler term
162 // NOTE the update of Doppler is simplified by only taking the center angle of
163 // each cluster in to consideration.
164 double slotTime = Simulator::Now ().GetSeconds ();
165 double factor = 2 * M_PI * slotTime * GetFrequency () / 3e8;
167
168 // The following asserts might seem paranoic, but it is important to
169 // make sure that all the structures that are passed to this function
170 // are of the correct dimensions before using the operator [].
171 // If you dont understand the comment read about the difference of .at()
172 // and [] operators, ...
173 NS_ASSERT (numCluster <= channelParams->m_alpha.size ());
174 NS_ASSERT (numCluster <= channelParams->m_D.size());
175 NS_ASSERT (numCluster <= channelParams->m_angle[MatrixBasedChannelModel::ZOA_INDEX].size());
176 NS_ASSERT (numCluster <= channelParams->m_angle[MatrixBasedChannelModel::ZOD_INDEX].size());
177 NS_ASSERT (numCluster <= channelParams->m_angle[MatrixBasedChannelModel::AOA_INDEX].size());
178 NS_ASSERT (numCluster <= channelParams->m_angle[MatrixBasedChannelModel::AOD_INDEX].size());
179 NS_ASSERT (numCluster <= longTerm.size());
180
181 // check if channelParams structure is generated in direction s-to-u or u-to-s
182 bool isSameDirection = (channelParams->m_nodeIds == channelMatrix->m_nodeIds);
183
188
189 // if channel params is generated in the same direction in which we
190 // generate the channel matrix, angles and zenit od departure and arrival are ok,
191 // just set them to corresponding variable that will be used for the generation
192 // of channel matrix, otherwise we need to flip angles and zenits of departure and arrival
193 if (isSameDirection)
194 {
195 zoa = channelParams->m_angle[MatrixBasedChannelModel::ZOA_INDEX];
196 zod = channelParams->m_angle[MatrixBasedChannelModel::ZOD_INDEX];
197 aoa = channelParams->m_angle[MatrixBasedChannelModel::AOA_INDEX];
198 aod = channelParams->m_angle[MatrixBasedChannelModel::AOD_INDEX];
199 }
200 else
201 {
202 zod = channelParams->m_angle[MatrixBasedChannelModel::ZOA_INDEX];
203 zoa = channelParams->m_angle[MatrixBasedChannelModel::ZOD_INDEX];
204 aod = channelParams->m_angle[MatrixBasedChannelModel::AOA_INDEX];
205 aoa = channelParams->m_angle[MatrixBasedChannelModel::AOD_INDEX];
206 }
207
208 for (uint8_t cIndex = 0; cIndex < numCluster; cIndex++)
209 {
210 // Compute alpha and D as described in 3GPP TR 37.885 v15.3.0, Sec. 6.2.3
211 // These terms account for an additional Doppler contribution due to the
212 // presence of moving objects in the sorrounding environment, such as in
213 // vehicular scenarios.
214 // This contribution is applied only to the delayed (reflected) paths and
215 // must be properly configured by setting the value of
216 // m_vScatt, which is defined as "maximum speed of the vehicle in the
217 // layout".
218 // By default, m_vScatt is set to 0, so there is no additional Doppler
219 // contribution.
220
221 double alpha = channelParams->m_alpha [cIndex];
222 double D = channelParams->m_D [cIndex];
223
224 //cluster angle angle[direction][n], where direction = 0(aoa), 1(zoa).
225 double tempDoppler = factor * ((sin (zoa [cIndex] * M_PI / 180) * cos (aoa [cIndex] * M_PI / 180) * uSpeed.x
226 + sin (zoa [cIndex] * M_PI / 180) * sin (aoa [cIndex] * M_PI / 180) * uSpeed.y
227 + cos (zoa [cIndex] * M_PI / 180) * uSpeed.z)
228 + (sin (zod [cIndex] * M_PI / 180) * cos (aod [cIndex] * M_PI / 180) * sSpeed.x
229 + sin (zod [cIndex] * M_PI / 180) * sin (aod [cIndex] * M_PI / 180) * sSpeed.y
230 + cos (zod [cIndex] * M_PI / 180) * sSpeed.z) + 2 * alpha * D);
231 doppler.push_back (std::complex<double> (cos (tempDoppler), sin (tempDoppler)));
232 }
233
234 NS_ASSERT (numCluster <= doppler.size());
235
236 // apply the doppler term and the propagation delay to the long term component
237 // to obtain the beamforming gain
238 auto vit = tempPsd->ValuesBegin (); // psd iterator
239 auto sbit = tempPsd->ConstBandsBegin (); // band iterator
240 while (vit != tempPsd->ValuesEnd ())
241 {
242 if ((*vit) != 0.00)
243 {
244 std::complex<double> subsbandGain (0.0, 0.0);
245 double fsb = (*sbit).fc; // center frequency of the sub-band
246 for (uint8_t cIndex = 0; cIndex < numCluster; cIndex++)
247 {
248 double delay = -2 * M_PI * fsb * (channelParams->m_delay[cIndex]);
249 subsbandGain = subsbandGain + longTerm[cIndex] * doppler[cIndex] * std::complex<double> (cos (delay), sin (delay));
250 }
251 *vit = (*vit) * (norm (subsbandGain));
252 }
253 vit++;
254 sbit++;
255 }
256 return tempPsd;
257}
258
261 Ptr<const PhasedArrayModel> aPhasedArrayModel,
262 Ptr<const PhasedArrayModel> bPhasedArrayModel) const
263{
264 PhasedArrayModel::ComplexVector longTerm; // vector containing the long term component for each cluster
265
266 // check if the channel matrix was generated considering a as the s-node and
267 // b as the u-node or viceversa
269 if (!channelMatrix->IsReverse (aPhasedArrayModel->GetId (), bPhasedArrayModel->GetId ()))
270 {
271 sW = aPhasedArrayModel->GetBeamformingVector ();
272 uW = bPhasedArrayModel->GetBeamformingVector ();
273 }
274 else
275 {
276 sW = bPhasedArrayModel->GetBeamformingVector ();
277 uW = aPhasedArrayModel->GetBeamformingVector ();
278 }
279
280 bool update = false; // indicates whether the long term has to be updated
281 bool notFound = false; // indicates if the long term has not been computed yet
282
283 // compute the long term key, the key is unique for each tx-rx pair
284 uint64_t longTermId = MatrixBasedChannelModel::GetKey (aPhasedArrayModel->GetId (), bPhasedArrayModel->GetId ());
285
286 // look for the long term in the map and check if it is valid
287 if (m_longTermMap.find (longTermId) != m_longTermMap.end ())
288 {
289 NS_LOG_DEBUG ("found the long term component in the map");
290 longTerm = m_longTermMap[longTermId]->m_longTerm;
291
292 // check if the channel matrix has been updated
293 // or the s beam has been changed
294 // or the u beam has been changed
295 update = (m_longTermMap[longTermId]->m_channel->m_generatedTime != channelMatrix->m_generatedTime
296 || m_longTermMap[longTermId]->m_sW != sW
297 || m_longTermMap[longTermId]->m_uW != uW);
298
299 }
300 else
301 {
302 NS_LOG_DEBUG ("long term component NOT found");
303 notFound = true;
304 }
305
306 if (update || notFound)
307 {
308 NS_LOG_DEBUG ("compute the long term");
309 // compute the long term component
310 longTerm = CalcLongTerm (channelMatrix, sW, uW);
311
312 // store the long term
313 Ptr<LongTerm> longTermItem = Create<LongTerm> ();
314 longTermItem->m_longTerm = longTerm;
315 longTermItem->m_channel = channelMatrix;
316 longTermItem->m_sW = sW;
317 longTermItem->m_uW = uW;
318
319 m_longTermMap[longTermId] = longTermItem;
320 }
321
322 return longTerm;
323}
324
329 Ptr<const PhasedArrayModel> aPhasedArrayModel,
330 Ptr<const PhasedArrayModel> bPhasedArrayModel) const
331{
332 NS_LOG_FUNCTION (this);
333 uint32_t aId = a->GetObject<Node> ()->GetId (); // id of the node a
334 uint32_t bId = b->GetObject<Node> ()->GetId (); // id of the node b
335
336 NS_ASSERT (aId != bId);
337 NS_ASSERT_MSG (a->GetDistanceFrom (b) > 0.0, "The position of a and b devices cannot be the same");
338
339 Ptr<SpectrumValue> rxPsd = Copy<SpectrumValue> (params->psd);
340
341 // retrieve the antenna of device a
342 NS_ASSERT_MSG (aPhasedArrayModel, "Antenna not found for node " << aId);
343 NS_LOG_DEBUG ("a node " << a->GetObject<Node> () << " antenna " << aPhasedArrayModel);
344
345 // retrieve the antenna of the device b
346 NS_ASSERT_MSG (bPhasedArrayModel, "Antenna not found for device " << bId);
347 NS_LOG_DEBUG ("b node " << bId << " antenna " << bPhasedArrayModel);
348
349 Ptr<const MatrixBasedChannelModel::ChannelMatrix> channelMatrix = m_channelModel->GetChannel (a, b, aPhasedArrayModel, bPhasedArrayModel);
351
352 // retrieve the long term component
353 PhasedArrayModel::ComplexVector longTerm = GetLongTerm (channelMatrix, aPhasedArrayModel, bPhasedArrayModel);
354
355 // apply the beamforming gain
356 rxPsd = CalcBeamformingGain (rxPsd, longTerm, channelMatrix, channelParams, a->GetVelocity (), b->GetVelocity ());
357
358 return rxPsd;
359}
360
361
362} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:69
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
double Get(void) const
Definition: double.cc:35
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
std::vector< double > DoubleVector
type definition for vectors of doubles
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,...
A network Node.
Definition: node.h:57
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
spectrum-aware propagation loss model that is compatible with PhasedArrayModel type of ns-3 antenna
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Values::iterator ValuesBegin()
Bands::const_iterator ConstBandsBegin() const
Values::iterator ValuesEnd()
Hold variables of type string.
Definition: string.h:41
void GetChannelModelAttribute(const std::string &name, AttributeValue &value) const
Returns the value of an attribute belonging to the associated MatrixBasedChannelModel instance.
Ptr< SpectrumValue > DoCalcRxPowerSpectralDensity(Ptr< const SpectrumSignalParameters > params, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, Ptr< const PhasedArrayModel > aPhasedArrayModel, Ptr< const PhasedArrayModel > bPhasedArrayModel) const override
Computes the received PSD.
PhasedArrayModel::ComplexVector GetLongTerm(Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, Ptr< const PhasedArrayModel > aPhasedArrayModel, Ptr< const PhasedArrayModel > bPhasedArrayModel) const
Looks for the long term component in m_longTermMap.
Ptr< MatrixBasedChannelModel > m_channelModel
the model to generate the channel matrix
void SetChannelModel(Ptr< MatrixBasedChannelModel > channel)
Set the channel model object.
std::unordered_map< uint64_t, Ptr< const LongTerm > > m_longTermMap
map containing the long term components
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.
Ptr< SpectrumValue > CalcBeamformingGain(Ptr< SpectrumValue > txPsd, PhasedArrayModel::ComplexVector longTerm, Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, Ptr< const MatrixBasedChannelModel::ChannelParams > channelParams, const Vector &sSpeed, const Vector &uSpeed) const
Computes the beamforming gain and applies it to the tx PSD.
PhasedArrayModel::ComplexVector CalcLongTerm(Ptr< const MatrixBasedChannelModel::ChannelMatrix > channelMatrix, const PhasedArrayModel::ComplexVector &sW, const PhasedArrayModel::ComplexVector &uW) const
Computes the long term component.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:274
#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.
Definition: object-base.h:45
const double norm
Normalization to obtain randoms on [0,1).
Definition: rng-stream.cc:64
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition: third.py:83