A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-spectrum-value-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gary Pei <guangyu.pei@boeing.com>
7 */
9
10#include <ns3/log.h>
11#include <ns3/spectrum-value.h>
12
13#include <cmath>
14
15namespace ns3
16{
17namespace lrwpan
18{
19
20NS_LOG_COMPONENT_DEFINE("LrWpanSpectrumValueHelper");
21
22Ptr<SpectrumModel>
23 g_LrWpanSpectrumModel; //!< Global object used to initialize the LrWpan Spectrum Model
24
25/**
26 * \ingroup lr-wpan
27 * \brief Helper class used to automatically initialize the LrWpan Spectrum Model objects
28 */
30{
31 public:
33 {
34 NS_LOG_FUNCTION(this);
35
36 Bands bands;
37 // 1 MHz resolution, with center frequency of 2400, 2401, ... 2483
38 // overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands)
39 for (int i = -1; i < 83; i++)
40 {
41 BandInfo bi;
42 bi.fl = 2400.5e6 + i * 1.0e6;
43 bi.fh = 2400.5e6 + (i + 1) * 1.0e6;
44 bi.fc = (bi.fl + bi.fh) / 2;
45 bands.push_back(bi);
46 }
48 }
49
50} g_LrWpanSpectrumModelInitializerInstance; //!< Global object used to initialize the LrWpan
51 //!< Spectrum Model
52
58
63
66{
67 NS_LOG_FUNCTION(this);
69
70 // txPower is expressed in dBm. We must convert it into natural unit (W).
71 txPower = pow(10., (txPower - 30) / 10);
72
73 // The effective occupied bandwidth of the signal is modelled to be 2 MHz.
74 // 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside.
75 // There are 5 bands containing signal power. The middle (center) band
76 // contains half of the power. The two inner side bands contain 49.5%.
77 // The two outer side bands contain roughly 0.5%.
78 double txPowerDensity = txPower / 2.0e6;
79
80 NS_ASSERT_MSG((channel >= 11 && channel <= 26), "Invalid channel numbers");
81
82 // The channel assignment is in section 6.1.2.1
83 // Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz
84 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] = txPowerDensity * 0.005;
85 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495;
86 (*txPsd)[2405 + 5 * (channel - 11) - 2400] = txPowerDensity; // center
87 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1] = txPowerDensity * 0.495;
88 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2] = txPowerDensity * 0.005;
89
90 // If more power is allocated to more subbands in future revisions of
91 // this model, make sure to renormalize so that the integral of the
92 // txPsd still equals txPower
93
94 return txPsd;
95}
96
99{
100 NS_LOG_FUNCTION(this);
102
103 static const double BOLTZMANN = 1.3803e-23;
104 // Nt is the power of thermal noise in W
105 double Nt = BOLTZMANN * 290.0;
106 // noise Floor (W) which accounts for thermal noise and non-idealities of the receiver
107 double noisePowerDensity = m_noiseFactor * Nt;
108
109 NS_ASSERT_MSG((channel >= 11 && channel <= 26), "Invalid channel numbers");
110
111 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity;
112 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 1] = noisePowerDensity;
113 (*noisePsd)[2405 + 5 * (channel - 11) - 2400] = noisePowerDensity;
114 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 1] = noisePowerDensity;
115 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 2] = noisePowerDensity;
116
117 return noisePsd;
118}
119
120void
125
126double
128{
129 NS_LOG_FUNCTION(psd);
130 double totalAvgPower = 0.0;
131
132 NS_ASSERT(psd->GetSpectrumModel() == g_LrWpanSpectrumModel);
133
134 // numerically integrate to get area under psd using 1 MHz resolution
135
136 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 2];
137 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 1];
138 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400];
139 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 1];
140 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 2];
141 totalAvgPower *= 1.0e6;
142
143 return totalAvgPower;
144}
145
146} // namespace lrwpan
147} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Helper class used to automatically initialize the LrWpan Spectrum Model objects.
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
static double TotalAvgPower(Ptr< const SpectrumValue > psd, uint32_t channel)
total average power of the signal is the integral of the PSD using the limits of the given channel
double m_noiseFactor
A scaling factor for the noise power.
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
void SetNoiseFactor(double f)
Set the noise factor added to the thermal noise.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
class ns3::lrwpan::LrWpanSpectrumModelInitializer g_LrWpanSpectrumModelInitializerInstance
Global object used to initialize the LrWpan Spectrum Model.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Ptr< SpectrumModel > g_LrWpanSpectrumModel
Global object used to initialize the LrWpan Spectrum Model.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< BandInfo > Bands
Container of BandInfo.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband