author | Tommaso Pecorella <tommaso.pecorella@unifi.it> |
Sun, 01 Feb 2015 21:08:32 -0800 | |
changeset 11205 | 29b708f01eb1 |
parent 10968 | 2d29fee2b7b8 |
permissions | -rw-r--r-- |
10711 | 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 |
*/ |
|
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
20 |
#include "lr-wpan-spectrum-value-helper.h" |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
21 |
#include <ns3/log.h> |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
22 |
#include <ns3/spectrum-value.h> |
10711 | 23 |
|
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
24 |
#include <cmath> |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
25 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10875
diff
changeset
|
26 |
namespace ns3 { |
10711 | 27 |
|
10968
2d29fee2b7b8
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10875
diff
changeset
|
28 |
NS_LOG_COMPONENT_DEFINE ("LrWpanSpectrumValueHelper"); |
10711 | 29 |
|
10875
632910874fa9
lr-wpan: remove dead code and add Doxygen
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10811
diff
changeset
|
30 |
Ptr<SpectrumModel> g_LrWpanSpectrumModel; //!< Global object used to initialize the LrWpan Spectrum Model |
10711 | 31 |
|
10875
632910874fa9
lr-wpan: remove dead code and add Doxygen
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10811
diff
changeset
|
32 |
/** |
632910874fa9
lr-wpan: remove dead code and add Doxygen
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10811
diff
changeset
|
33 |
* \ingroup lr-wpan |
632910874fa9
lr-wpan: remove dead code and add Doxygen
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10811
diff
changeset
|
34 |
* \brief Helper class used to automatically initialize the LrWpan Spectrum Model objects |
632910874fa9
lr-wpan: remove dead code and add Doxygen
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10811
diff
changeset
|
35 |
*/ |
10711 | 36 |
class LrWpanSpectrumModelInitializer |
37 |
{ |
|
38 |
public: |
|
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
39 |
LrWpanSpectrumModelInitializer (void) |
10711 | 40 |
{ |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
41 |
NS_LOG_FUNCTION (this); |
10711 | 42 |
|
43 |
Bands bands; |
|
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
44 |
// 1 MHz resolution, with center frequency of 2400, 2401, ... 2483 |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
45 |
// overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands) |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
46 |
for (int i = -1; i < 83; i++) |
10711 | 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 |
||
11205
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
57 |
} g_LrWpanSpectrumModelInitializerInstance; //!< Global object used to initialize the LrWpan Spectrum Model |
10711 | 58 |
|
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
59 |
LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper (void) |
10711 | 60 |
{ |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
61 |
NS_LOG_FUNCTION (this); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
62 |
m_noiseFactor = 1.0; |
10711 | 63 |
} |
64 |
||
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
65 |
LrWpanSpectrumValueHelper::~LrWpanSpectrumValueHelper (void) |
10711 | 66 |
{ |
10750
8a9e91fac9c0
First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents:
10728
diff
changeset
|
67 |
NS_LOG_FUNCTION (this); |
10711 | 68 |
} |
69 |
||
70 |
Ptr<SpectrumValue> |
|
71 |
LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity (double txPower, uint32_t channel) |
|
72 |
{ |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
73 |
NS_LOG_FUNCTION (this); |
10711 | 74 |
Ptr<SpectrumValue> txPsd = Create <SpectrumValue> (g_LrWpanSpectrumModel); |
75 |
||
10811
31dbab5c8a28
bug 1924 - sensing radius and CCA
Sascha Jopen <jopen@cs.uni-bonn.de>
parents:
10760
diff
changeset
|
76 |
// txPower is expressed in dBm. We must convert it into natural unit (W). |
10711 | 77 |
txPower = pow (10., (txPower - 30) / 10); |
78 |
||
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
79 |
// The effective occupied bandwidth of the signal is modelled to be 2 MHz. |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
80 |
// 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside. |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
81 |
// There are 5 bands containing signal power. The middle (center) band |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
82 |
// contains half of the power. The two inner side bands contain 49.5%. |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
83 |
// The two outer side bands contain roughly 0.5%. |
10711 | 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 |
|
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
89 |
// Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
90 |
(*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] = txPowerDensity * 0.005; |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
91 |
(*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495; |
10711 | 92 |
(*txPsd)[2405 + 5 * (channel - 11) - 2400] = txPowerDensity; // center |
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
93 |
(*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1 ] = txPowerDensity * 0.495; |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
94 |
(*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2 ] = txPowerDensity * 0.005; |
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
95 |
|
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
96 |
// If more power is allocated to more subbands in future revisions of |
10760
d7d73e3ceb3c
Apply utils/check-style.py script on lr-wpan source code again
Tom Henderson <tomh@tomh.org>
parents:
10750
diff
changeset
|
97 |
// this model, make sure to renormalize so that the integral of the |
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
98 |
// txPsd still equals txPower |
10711 | 99 |
|
100 |
return txPsd; |
|
101 |
} |
|
102 |
||
103 |
Ptr<SpectrumValue> |
|
104 |
LrWpanSpectrumValueHelper::CreateNoisePowerSpectralDensity (uint32_t channel) |
|
105 |
{ |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
106 |
NS_LOG_FUNCTION (this); |
10711 | 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 |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
113 |
double noisePowerDensity = m_noiseFactor * Nt; |
10711 | 114 |
|
115 |
NS_ASSERT_MSG ((channel >= 11 && channel <= 26), "Invalid channel numbers"); |
|
116 |
||
10720
4e4a0de88982
ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10712
diff
changeset
|
117 |
(*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity; |
10711 | 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 |
||
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
126 |
double |
11205
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
127 |
LrWpanSpectrumValueHelper::TotalAvgPower (Ptr<const SpectrumValue> psd, uint32_t channel) |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
128 |
{ |
10728
62d4098c1c22
First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents:
10720
diff
changeset
|
129 |
NS_LOG_FUNCTION (psd); |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
130 |
double totalAvgPower = 0.0; |
10711 | 131 |
|
11205
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
132 |
NS_ASSERT (psd->GetSpectrumModel () == g_LrWpanSpectrumModel); |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
133 |
|
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
134 |
// numerically integrate to get area under psd using 1 MHz resolution |
10711 | 135 |
|
11205
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
136 |
totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 2]; |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
137 |
totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 1]; |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
138 |
totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400]; |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
139 |
totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 1]; |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
140 |
totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 2]; |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
141 |
totalAvgPower *= 1.0e6; |
29b708f01eb1
bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10968
diff
changeset
|
142 |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
143 |
return totalAvgPower; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
144 |
} |
10711 | 145 |
|
146 |
} // namespace ns3 |