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{
28
29NS_LOG_COMPONENT_DEFINE("LrWpanSpectrumValueHelper");
30
31Ptr<SpectrumModel>
33
39{
40 public:
42 {
43 NS_LOG_FUNCTION(this);
44
45 Bands bands;
46 // 1 MHz resolution, with center frequency of 2400, 2401, ... 2483
47 // overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands)
48 for (int i = -1; i < 83; i++)
49 {
50 BandInfo bi;
51 bi.fl = 2400.5e6 + i * 1.0e6;
52 bi.fh = 2400.5e6 + (i + 1) * 1.0e6;
53 bi.fc = (bi.fl + bi.fh) / 2;
54 bands.push_back(bi);
55 }
56 g_LrWpanSpectrumModel = Create<SpectrumModel>(bands);
57 }
58
61
63{
64 NS_LOG_FUNCTION(this);
65 m_noiseFactor = 1.0;
66}
67
69{
70 NS_LOG_FUNCTION(this);
71}
72
75{
76 NS_LOG_FUNCTION(this);
77 Ptr<SpectrumValue> txPsd = Create<SpectrumValue>(g_LrWpanSpectrumModel);
78
79 // txPower is expressed in dBm. We must convert it into natural unit (W).
80 txPower = pow(10., (txPower - 30) / 10);
81
82 // The effective occupied bandwidth of the signal is modelled to be 2 MHz.
83 // 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside.
84 // There are 5 bands containing signal power. The middle (center) band
85 // contains half of the power. The two inner side bands contain 49.5%.
86 // The two outer side bands contain roughly 0.5%.
87 double txPowerDensity = txPower / 2.0e6;
88
89 NS_ASSERT_MSG((channel >= 11 && channel <= 26), "Invalid channel numbers");
90
91 // The channel assignment is in section 6.1.2.1
92 // Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz
93 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] = txPowerDensity * 0.005;
94 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495;
95 (*txPsd)[2405 + 5 * (channel - 11) - 2400] = txPowerDensity; // center
96 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1] = txPowerDensity * 0.495;
97 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2] = txPowerDensity * 0.005;
98
99 // If more power is allocated to more subbands in future revisions of
100 // this model, make sure to renormalize so that the integral of the
101 // txPsd still equals txPower
102
103 return txPsd;
104}
105
108{
109 NS_LOG_FUNCTION(this);
110 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(g_LrWpanSpectrumModel);
111
112 static const double BOLTZMANN = 1.3803e-23;
113 // Nt is the power of thermal noise in W
114 double Nt = BOLTZMANN * 290.0;
115 // noise Floor (W) which accounts for thermal noise and non-idealities of the receiver
116 double noisePowerDensity = m_noiseFactor * Nt;
117
118 NS_ASSERT_MSG((channel >= 11 && channel <= 26), "Invalid channel numbers");
119
120 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity;
121 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 1] = noisePowerDensity;
122 (*noisePsd)[2405 + 5 * (channel - 11) - 2400] = noisePowerDensity;
123 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 1] = noisePowerDensity;
124 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 2] = noisePowerDensity;
125
126 return noisePsd;
127}
128
129void
131{
133}
134
135double
137{
138 NS_LOG_FUNCTION(psd);
139 double totalAvgPower = 0.0;
140
141 NS_ASSERT(psd->GetSpectrumModel() == g_LrWpanSpectrumModel);
142
143 // numerically integrate to get area under psd using 1 MHz resolution
144
145 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 2];
146 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 1];
147 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400];
148 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 1];
149 totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 2];
150 totalAvgPower *= 1.0e6;
151
152 return totalAvgPower;
153}
154
155} // namespace ns3
double f(double x, void *params)
Definition: 80211b.c:70
Helper class used to automatically initialize the LrWpan Spectrum Model objects.
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
double m_noiseFactor
A scaling factor for the noise power.
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
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
void SetNoiseFactor(double f)
Set the noise factor added to the thermal noise.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
#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::LrWpanSpectrumModelInitializer g_LrWpanSpectrumModelInitializerInstance
Global object used to initialize the LrWpan Spectrum Model.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< SpectrumModel > g_LrWpanSpectrumModel
Global object used to initialize the LrWpan Spectrum Model.
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