A Discrete-Event Network Simulator
API
lr-wpan-spectrum-value-helper.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 The Boeing Company
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Gary Pei <guangyu.pei@boeing.com>
19 */
21#include <ns3/log.h>
22#include <ns3/spectrum-value.h>
23
24#include <cmath>
25
26namespace ns3 {
27
28NS_LOG_COMPONENT_DEFINE ("LrWpanSpectrumValueHelper");
29
31
37{
38public:
40 {
41 NS_LOG_FUNCTION (this);
42
43 Bands bands;
44 // 1 MHz resolution, with center frequency of 2400, 2401, ... 2483
45 // overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands)
46 for (int i = -1; i < 83; i++)
47 {
48 BandInfo bi;
49 bi.fl = 2400.5e6 + i * 1.0e6;
50 bi.fh = 2400.5e6 + (i + 1) * 1.0e6;
51 bi.fc = (bi.fl + bi.fh) / 2;
52 bands.push_back (bi);
53 }
54 g_LrWpanSpectrumModel = Create<SpectrumModel> (bands);
55 }
56
58
60{
61 NS_LOG_FUNCTION (this);
62 m_noiseFactor = 1.0;
63}
64
66{
67 NS_LOG_FUNCTION (this);
68}
69
72{
73 NS_LOG_FUNCTION (this);
74 Ptr<SpectrumValue> txPsd = Create <SpectrumValue> (g_LrWpanSpectrumModel);
75
76 // txPower is expressed in dBm. We must convert it into natural unit (W).
77 txPower = pow (10., (txPower - 30) / 10);
78
79 // The effective occupied bandwidth of the signal is modelled to be 2 MHz.
80 // 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside.
81 // There are 5 bands containing signal power. The middle (center) band
82 // contains half of the power. The two inner side bands contain 49.5%.
83 // The two outer side bands contain roughly 0.5%.
84 double txPowerDensity = txPower / 2.0e6;
85
86 NS_ASSERT_MSG ((channel >= 11 && channel <= 26), "Invalid channel numbers");
87
88 // The channel assignment is in section 6.1.2.1
89 // Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz
90 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] = txPowerDensity * 0.005;
91 (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495;
92 (*txPsd)[2405 + 5 * (channel - 11) - 2400] = txPowerDensity; // center
93 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1 ] = txPowerDensity * 0.495;
94 (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2 ] = txPowerDensity * 0.005;
95
96 // If more power is allocated to more subbands in future revisions of
97 // this model, make sure to renormalize so that the integral of the
98 // txPsd still equals txPower
99
100 return txPsd;
101}
102
105{
106 NS_LOG_FUNCTION (this);
107 Ptr<SpectrumValue> noisePsd = Create <SpectrumValue> (g_LrWpanSpectrumModel);
108
109 static const double BOLTZMANN = 1.3803e-23;
110 // Nt is the power of thermal noise in W
111 double Nt = BOLTZMANN * 290.0;
112 // noise Floor (W) which accounts for thermal noise and non-idealities of the receiver
113 double noisePowerDensity = m_noiseFactor * Nt;
114
115 NS_ASSERT_MSG ((channel >= 11 && channel <= 26), "Invalid channel numbers");
116
117 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity;
118 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 1] = noisePowerDensity;
119 (*noisePsd)[2405 + 5 * (channel - 11) - 2400] = noisePowerDensity;
120 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 1] = noisePowerDensity;
121 (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 2] = noisePowerDensity;
122
123 return noisePsd;
124}
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 ns3
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
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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.
channel
Definition: third.py:92
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband