author | Sascha Jopen <jopen@cs.uni-bonn.de> |
Thu, 12 Jun 2014 12:35:32 -0700 | |
changeset 10811 | 31dbab5c8a28 |
parent 10760 | d7d73e3ceb3c |
child 10875 | 632910874fa9 |
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 |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
26 |
NS_LOG_COMPONENT_DEFINE ("LrWpanSpectrumValueHelper"); |
10711 | 27 |
|
28 |
namespace ns3 { |
|
29 |
||
30 |
Ptr<SpectrumModel> g_LrWpanSpectrumModel; |
|
31 |
||
32 |
class LrWpanSpectrumModelInitializer |
|
33 |
{ |
|
34 |
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
|
35 |
LrWpanSpectrumModelInitializer (void) |
10711 | 36 |
{ |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
37 |
NS_LOG_FUNCTION (this); |
10711 | 38 |
|
39 |
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
|
40 |
// 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
|
41 |
// 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
|
42 |
for (int i = -1; i < 83; i++) |
10711 | 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 |
||
53 |
} g_LrWpanSpectrumModelInitializerInstance; |
|
54 |
||
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
|
55 |
LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper (void) |
10711 | 56 |
{ |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
57 |
NS_LOG_FUNCTION (this); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
58 |
m_noiseFactor = 1.0; |
10711 | 59 |
} |
60 |
||
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
|
61 |
LrWpanSpectrumValueHelper::~LrWpanSpectrumValueHelper (void) |
10711 | 62 |
{ |
10750
8a9e91fac9c0
First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents:
10728
diff
changeset
|
63 |
NS_LOG_FUNCTION (this); |
10711 | 64 |
} |
65 |
||
66 |
Ptr<SpectrumValue> |
|
67 |
LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity (double txPower, uint32_t channel) |
|
68 |
{ |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
69 |
NS_LOG_FUNCTION (this); |
10711 | 70 |
Ptr<SpectrumValue> txPsd = Create <SpectrumValue> (g_LrWpanSpectrumModel); |
71 |
||
10811
31dbab5c8a28
bug 1924 - sensing radius and CCA
Sascha Jopen <jopen@cs.uni-bonn.de>
parents:
10760
diff
changeset
|
72 |
// txPower is expressed in dBm. We must convert it into natural unit (W). |
10711 | 73 |
txPower = pow (10., (txPower - 30) / 10); |
74 |
||
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
|
75 |
// 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
|
76 |
// 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
|
77 |
// 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
|
78 |
// 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
|
79 |
// The two outer side bands contain roughly 0.5%. |
10711 | 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 |
|
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
|
85 |
// 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
|
86 |
(*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
|
87 |
(*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] = txPowerDensity * 0.495; |
10711 | 88 |
(*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
|
89 |
(*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
|
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 |
|
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
|
92 |
// 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
|
93 |
// 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
|
94 |
// txPsd still equals txPower |
10711 | 95 |
|
96 |
return txPsd; |
|
97 |
} |
|
98 |
||
99 |
Ptr<SpectrumValue> |
|
100 |
LrWpanSpectrumValueHelper::CreateNoisePowerSpectralDensity (uint32_t channel) |
|
101 |
{ |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
102 |
NS_LOG_FUNCTION (this); |
10711 | 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 |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
109 |
double noisePowerDensity = m_noiseFactor * Nt; |
10711 | 110 |
|
111 |
NS_ASSERT_MSG ((channel >= 11 && channel <= 26), "Invalid channel numbers"); |
|
112 |
||
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
|
113 |
(*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] = noisePowerDensity; |
10711 | 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 |
||
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
122 |
double |
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
|
123 |
LrWpanSpectrumValueHelper::TotalAvgPower (Ptr<const SpectrumValue> psd) |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
124 |
{ |
10728
62d4098c1c22
First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents:
10720
diff
changeset
|
125 |
NS_LOG_FUNCTION (psd); |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
126 |
double totalAvgPower = 0.0; |
10711 | 127 |
|
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
128 |
// numerically integrate to get area under psd using |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
129 |
// 1 MHz resolution from 2400 to 2483 MHz (center freq) |
10711 | 130 |
|
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
|
131 |
totalAvgPower = Sum (*psd * 1.0e6); |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
132 |
return totalAvgPower; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
10711
diff
changeset
|
133 |
} |
10711 | 134 |
|
135 |
} // namespace ns3 |