A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
26 NS_LOG_COMPONENT_DEFINE ("LrWpanSpectrumValueHelper");
27 
28 namespace ns3 {
29 
31 
33 {
34 public:
36  {
37  NS_LOG_FUNCTION (this);
38 
39  Bands bands;
40  // 1 MHz resolution, with center frequency of 2400, 2401, ... 2483
41  // overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands)
42  for (int i = -1; i < 83; i++)
43  {
44  BandInfo bi;
45  bi.fl = 2400.5e6 + i * 1.0e6;
46  bi.fh = 2400.5e6 + (i + 1) * 1.0e6;
47  bi.fc = (bi.fl + bi.fh) / 2;
48  bands.push_back (bi);
49  }
50  g_LrWpanSpectrumModel = Create<SpectrumModel> (bands);
51  }
52 
54 
56 {
57  NS_LOG_FUNCTION (this);
58  m_noiseFactor = 1.0;
59 }
60 
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
68 {
69  NS_LOG_FUNCTION (this);
70  Ptr<SpectrumValue> txPsd = Create <SpectrumValue> (g_LrWpanSpectrumModel);
71 
72  // txPower is expressed in dBm. We must convert it into natural unit (W).
73  txPower = pow (10., (txPower - 30) / 10);
74 
75  // The effective occupied bandwidth of the signal is modelled to be 2 MHz.
76  // 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside.
77  // There are 5 bands containing signal power. The middle (center) band
78  // contains half of the power. The two inner side bands contain 49.5%.
79  // The two outer side bands contain roughly 0.5%.
80  double txPowerDensity = txPower / 2.0e6;
81 
82  NS_ASSERT_MSG ((channel >= 11 && channel <= 26), "Invalid channel numbers");
83 
84  // The channel assignment is in section 6.1.2.1
85  // Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz
86  (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] = txPowerDensity * 0.005;
87  (*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495;
88  (*txPsd)[2405 + 5 * (channel - 11) - 2400] = txPowerDensity; // center
89  (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1 ] = txPowerDensity * 0.495;
90  (*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2 ] = txPowerDensity * 0.005;
91 
92  // If more power is allocated to more subbands in future revisions of
93  // this model, make sure to renormalize so that the integral of the
94  // txPsd still equals txPower
95 
96  return txPsd;
97 }
98 
101 {
102  NS_LOG_FUNCTION (this);
103  Ptr<SpectrumValue> noisePsd = Create <SpectrumValue> (g_LrWpanSpectrumModel);
104 
105  static const double BOLTZMANN = 1.3803e-23;
106  // Nt is the power of thermal noise in W
107  double Nt = BOLTZMANN * 290.0;
108  // noise Floor (W) which accounts for thermal noise and non-idealities of the receiver
109  double noisePowerDensity = m_noiseFactor * Nt;
110 
111  NS_ASSERT_MSG ((channel >= 11 && channel <= 26), "Invalid channel numbers");
112 
113  (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity;
114  (*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 1] = noisePowerDensity;
115  (*noisePsd)[2405 + 5 * (channel - 11) - 2400] = noisePowerDensity;
116  (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 1] = noisePowerDensity;
117  (*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 2] = noisePowerDensity;
118 
119  return noisePsd;
120 }
121 
122 double
124 {
125  NS_LOG_FUNCTION (psd);
126  double totalAvgPower = 0.0;
127 
128  // numerically integrate to get area under psd using
129  // 1 MHz resolution from 2400 to 2483 MHz (center freq)
130 
131  totalAvgPower = Sum (*psd * 1.0e6);
132  return totalAvgPower;
133 }
134 
135 } // namespace ns3
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
double m_noiseFactor
A scaling factor for the noise power.
std::vector< BandInfo > Bands
Ptr< SpectrumModel > g_LrWpanSpectrumModel
double fc
center frequency
double fl
lower limit of subband
static double TotalAvgPower(Ptr< const SpectrumValue > psd)
total average power of the signal is the integral of the PSD
#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:84
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
double Sum(const SpectrumValue &x)
double fh
upper limit of subband
The building block of a SpectrumModel.