A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
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
*/
20
#include "
lr-wpan-spectrum-value-helper.h
"
21
#include <ns3/log.h>
22
#include <ns3/spectrum-value.h>
23
24
#include <cmath>
25
26
namespace
ns3
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"LrWpanSpectrumValueHelper"
);
29
30
Ptr<SpectrumModel>
g_LrWpanSpectrumModel
;
31
36
class
LrWpanSpectrumModelInitializer
37
{
38
public
:
39
LrWpanSpectrumModelInitializer
(
void
)
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
57
}
g_LrWpanSpectrumModelInitializerInstance
;
58
59
LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper
(
void
)
60
{
61
NS_LOG_FUNCTION
(
this
);
62
m_noiseFactor
= 1.0;
63
}
64
65
LrWpanSpectrumValueHelper::~LrWpanSpectrumValueHelper
(
void
)
66
{
67
NS_LOG_FUNCTION
(
this
);
68
}
69
70
Ptr<SpectrumValue>
71
LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity
(
double
txPower, uint32_t
channel
)
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
103
Ptr<SpectrumValue>
104
LrWpanSpectrumValueHelper::CreateNoisePowerSpectralDensity
(uint32_t
channel
)
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
126
double
127
LrWpanSpectrumValueHelper::TotalAvgPower
(
Ptr<const SpectrumValue>
psd, uint32_t
channel
)
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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
Definition:
lr-wpan-spectrum-value-helper.cc:71
NS_ASSERT
#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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::LrWpanSpectrumValueHelper::~LrWpanSpectrumValueHelper
virtual ~LrWpanSpectrumValueHelper(void)
Definition:
lr-wpan-spectrum-value-helper.cc:65
ns3::LrWpanSpectrumValueHelper::TotalAvgPower
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
Definition:
lr-wpan-spectrum-value-helper.cc:127
third.channel
channel
Definition:
third.py:92
ns3::g_LrWpanSpectrumModel
Ptr< SpectrumModel > g_LrWpanSpectrumModel
Global object used to initialize the LrWpan Spectrum Model.
Definition:
lr-wpan-spectrum-value-helper.cc:28
ns3::BandInfo
The building block of a SpectrumModel.
Definition:
spectrum-model.h:46
ns3::BandInfo::fl
double fl
lower limit of subband
Definition:
spectrum-model.h:47
ns3::Ptr< SpectrumModel >
ns3::LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper
LrWpanSpectrumValueHelper(void)
Definition:
lr-wpan-spectrum-value-helper.cc:59
ns3::BandInfo::fc
double fc
center frequency
Definition:
spectrum-model.h:48
NS_ASSERT_MSG
#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
ns3::LrWpanSpectrumModelInitializer::LrWpanSpectrumModelInitializer
LrWpanSpectrumModelInitializer(void)
Definition:
lr-wpan-spectrum-value-helper.cc:39
ns3::BandInfo::fh
double fh
upper limit of subband
Definition:
spectrum-model.h:49
ns3::Bands
std::vector< BandInfo > Bands
Container of BandInfo.
Definition:
spectrum-model.h:54
ns3::LrWpanSpectrumValueHelper::CreateNoisePowerSpectralDensity
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
Definition:
lr-wpan-spectrum-value-helper.cc:104
ns3::g_LrWpanSpectrumModelInitializerInstance
class ns3::LrWpanSpectrumModelInitializer g_LrWpanSpectrumModelInitializerInstance
Global object used to initialize the LrWpan Spectrum Model.
lr-wpan-spectrum-value-helper.h
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition:
log-macros-enabled.h:244
ns3::LrWpanSpectrumModelInitializer
Helper class used to automatically initialize the LrWpan Spectrum Model objects.
Definition:
lr-wpan-spectrum-value-helper.cc:37
ns3::LrWpanSpectrumValueHelper::m_noiseFactor
double m_noiseFactor
A scaling factor for the noise power.
Definition:
lr-wpan-spectrum-value-helper.h:68
src
lr-wpan
model
lr-wpan-spectrum-value-helper.cc
Generated on Fri Oct 1 2021 17:03:14 for ns-3 by
1.8.20