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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Gary Pei <guangyu.pei@boeing.com>
18 */
20
21#include <ns3/log.h>
22#include <ns3/spectrum-value.h>
23
24#include <cmath>
25
26namespace ns3
27{
28namespace lrwpan
29{
30
31NS_LOG_COMPONENT_DEFINE("LrWpanSpectrumValueHelper");
32
33Ptr<SpectrumModel>
34 g_LrWpanSpectrumModel; //!< Global object used to initialize the LrWpan Spectrum Model
35
36/**
37 * \ingroup lr-wpan
38 * \brief Helper class used to automatically initialize the LrWpan Spectrum Model objects
39 */
41{
42 public:
44 {
45 NS_LOG_FUNCTION(this);
46
47 Bands bands;
48 // 1 MHz resolution, with center frequency of 2400, 2401, ... 2483
49 // overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands)
50 for (int i = -1; i < 83; i++)
51 {
52 BandInfo bi;
53 bi.fl = 2400.5e6 + i * 1.0e6;
54 bi.fh = 2400.5e6 + (i + 1) * 1.0e6;
55 bi.fc = (bi.fl + bi.fh) / 2;
56 bands.push_back(bi);
57 }
58 g_LrWpanSpectrumModel = Create<SpectrumModel>(bands);
59 }
60
61} g_LrWpanSpectrumModelInitializerInstance; //!< Global object used to initialize the LrWpan
62 //!< Spectrum Model
63
65{
66 NS_LOG_FUNCTION(this);
67 m_noiseFactor = 1.0;
68}
69
71{
72 NS_LOG_FUNCTION(this);
73}
74
77{
78 NS_LOG_FUNCTION(this);
79 Ptr<SpectrumValue> txPsd = Create<SpectrumValue>(g_LrWpanSpectrumModel);
80
81 // txPower is expressed in dBm. We must convert it into natural unit (W).
82 txPower = pow(10., (txPower - 30) / 10);
83
84 // The effective occupied bandwidth of the signal is modelled to be 2 MHz.
85 // 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside.
86 // There are 5 bands containing signal power. The middle (center) band
87 // contains half of the power. The two inner side bands contain 49.5%.
88 // The two outer side bands contain roughly 0.5%.
89 double txPowerDensity = txPower / 2.0e6;
90
91 NS_ASSERT_MSG((channel >= 11 && channel <= 26), "Invalid channel numbers");
92
93 // The channel assignment is in section 6.1.2.1
94 // Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz
95 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] = txPowerDensity * 0.005;
96 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495;
97 (*txPsd)[2405 + 5 * (channel - 11) - 2400] = txPowerDensity; // center
98 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1] = txPowerDensity * 0.495;
99 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2] = txPowerDensity * 0.005;
100
101 // If more power is allocated to more subbands in future revisions of
102 // this model, make sure to renormalize so that the integral of the
103 // txPsd still equals txPower
104
105 return txPsd;
106}
107
110{
111 NS_LOG_FUNCTION(this);
112 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(g_LrWpanSpectrumModel);
113
114 static const double BOLTZMANN = 1.3803e-23;
115 // Nt is the power of thermal noise in W
116 double Nt = BOLTZMANN * 290.0;
117 // noise Floor (W) which accounts for thermal noise and non-idealities of the receiver
118 double noisePowerDensity = m_noiseFactor * Nt;
119
120 NS_ASSERT_MSG((channel >= 11 && channel <= 26), "Invalid channel numbers");
121
122 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity;
123 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 1] = noisePowerDensity;
124 (*noisePsd)[2405 + 5 * (channel - 11) - 2400] = noisePowerDensity;
125 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 1] = noisePowerDensity;
126 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 2] = noisePowerDensity;
127
128 return noisePsd;
129}
130
131void
133{
134 m_noiseFactor = f;
135}
136
137double
139{
140 NS_LOG_FUNCTION(psd);
141 double totalAvgPower = 0.0;
142
143 NS_ASSERT(psd->GetSpectrumModel() == g_LrWpanSpectrumModel);
144
145 // numerically integrate to get area under psd using 1 MHz resolution
146
147 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 2];
148 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 1];
149 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400];
150 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 1];
151 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 2];
152 totalAvgPower *= 1.0e6;
153
154 return totalAvgPower;
155}
156
157} // namespace lrwpan
158} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:66
#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:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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< 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