A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lr-wpan-spectrum-value-helper.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 The Boeing Company
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Gary Pei <guangyu.pei@boeing.com>
7
*/
8
#include "
lr-wpan-spectrum-value-helper.h
"
9
10
#include "ns3/log.h"
11
#include "ns3/spectrum-value.h"
12
13
#include <cmath>
14
15
namespace
ns3
16
{
17
namespace
lrwpan
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"LrWpanSpectrumValueHelper"
);
21
22
Ptr<SpectrumModel>
23
g_LrWpanSpectrumModel
;
//!< Global object used to initialize the LrWpan Spectrum Model
24
25
/**
26
* @ingroup lr-wpan
27
* @brief Helper class used to automatically initialize the LrWpan Spectrum Model objects
28
*/
29
class
LrWpanSpectrumModelInitializer
30
{
31
public
:
32
LrWpanSpectrumModelInitializer
()
33
{
34
NS_LOG_FUNCTION
(
this
);
35
36
Bands
bands
;
37
// 1 MHz resolution, with center frequency of 2400, 2401, ... 2483
38
// overall frequency span of 2399.5 MHz through 2483.5 MHz (83 bands)
39
for
(
int
i
= -1;
i
< 83;
i
++)
40
{
41
BandInfo
bi
;
42
bi
.
fl
= 2400.5e6 +
i
* 1.0e6;
43
bi
.fh = 2400.5e6 + (
i
+ 1) * 1.0e6;
44
bi
.fc = (
bi
.fl +
bi
.fh) / 2;
45
bands
.push_back(
bi
);
46
}
47
g_LrWpanSpectrumModel
=
Create<SpectrumModel>
(
bands
);
48
}
49
50
}
g_LrWpanSpectrumModelInitializerInstance
;
//!< Global object used to initialize the LrWpan
51
//!< Spectrum Model
52
53
LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper
()
54
{
55
NS_LOG_FUNCTION
(
this
);
56
m_noiseFactor
= 1.0;
57
}
58
59
LrWpanSpectrumValueHelper::~LrWpanSpectrumValueHelper
()
60
{
61
NS_LOG_FUNCTION
(
this
);
62
}
63
64
Ptr<SpectrumValue>
65
LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity
(
double
txPower
,
uint32_t
channel)
66
{
67
NS_LOG_FUNCTION
(
this
);
68
Ptr<SpectrumValue>
txPsd
=
Create<SpectrumValue>
(
g_LrWpanSpectrumModel
);
69
70
// txPower is expressed in dBm. We must convert it into natural unit (W).
71
txPower
=
pow
(10., (
txPower
- 30) / 10);
72
73
// The effective occupied bandwidth of the signal is modelled to be 2 MHz.
74
// 99.5% of power is within +/- 1MHz of center frequency, and 0.5% is outside.
75
// There are 5 bands containing signal power. The middle (center) band
76
// contains half of the power. The two inner side bands contain 49.5%.
77
// The two outer side bands contain roughly 0.5%.
78
double
txPowerDensity
=
txPower
/ 2.0e6;
79
80
NS_ASSERT_MSG
((channel >= 11 && channel <= 26),
"Invalid channel numbers"
);
81
82
// The channel assignment is in section 6.1.2.1
83
// Channel 11 centered at 2.405 GHz, 12 at 2.410 GHz, ... 26 at 2.480 GHz
84
(*txPsd)[2405 + 5 * (channel - 11) - 2400 - 2] =
txPowerDensity
* 0.005;
85
(*txPsd)[2405 + 5 * (channel - 11) - 2400 - 1] =
txPowerDensity
* 0.495;
86
(*txPsd)[2405 + 5 * (channel - 11) - 2400] =
txPowerDensity
;
// center
87
(*txPsd)[2405 + 5 * (channel - 11) - 2400 + 1] =
txPowerDensity
* 0.495;
88
(*txPsd)[2405 + 5 * (channel - 11) - 2400 + 2] =
txPowerDensity
* 0.005;
89
90
// If more power is allocated to more subbands in future revisions of
91
// this model, make sure to renormalize so that the integral of the
92
// txPsd still equals txPower
93
94
return
txPsd
;
95
}
96
97
Ptr<SpectrumValue>
98
LrWpanSpectrumValueHelper::CreateNoisePowerSpectralDensity
(
uint32_t
channel)
99
{
100
NS_LOG_FUNCTION
(
this
);
101
Ptr<SpectrumValue>
noisePsd
=
Create<SpectrumValue>
(
g_LrWpanSpectrumModel
);
102
103
static
const
double
BOLTZMANN
= 1.3803e-23;
104
// Nt is the power of thermal noise in W
105
double
Nt
=
BOLTZMANN
* 290.0;
106
// noise Floor (W) which accounts for thermal noise and non-idealities of the receiver
107
double
noisePowerDensity
=
m_noiseFactor
*
Nt
;
108
109
NS_ASSERT_MSG
((channel >= 11 && channel <= 26),
"Invalid channel numbers"
);
110
111
(*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 2] =
noisePowerDensity
;
112
(*noisePsd)[2405 + 5 * (channel - 11) - 2400 - 1] =
noisePowerDensity
;
113
(*noisePsd)[2405 + 5 * (channel - 11) - 2400] =
noisePowerDensity
;
114
(*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 1] =
noisePowerDensity
;
115
(*noisePsd)[2405 + 5 * (channel - 11) - 2400 + 2] =
noisePowerDensity
;
116
117
return
noisePsd
;
118
}
119
120
void
121
LrWpanSpectrumValueHelper::SetNoiseFactor
(
double
f)
122
{
123
m_noiseFactor
= f;
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 lrwpan
147
}
// namespace ns3
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::lrwpan::LrWpanSpectrumModelInitializer
Helper class used to automatically initialize the LrWpan Spectrum Model objects.
Definition
lr-wpan-spectrum-value-helper.cc:30
ns3::lrwpan::LrWpanSpectrumModelInitializer::LrWpanSpectrumModelInitializer
LrWpanSpectrumModelInitializer()
Definition
lr-wpan-spectrum-value-helper.cc:32
ns3::lrwpan::LrWpanSpectrumValueHelper::CreateNoisePowerSpectralDensity
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
Definition
lr-wpan-spectrum-value-helper.cc:98
ns3::lrwpan::LrWpanSpectrumValueHelper::~LrWpanSpectrumValueHelper
virtual ~LrWpanSpectrumValueHelper()
Definition
lr-wpan-spectrum-value-helper.cc:59
ns3::lrwpan::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
ns3::lrwpan::LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper
LrWpanSpectrumValueHelper()
Definition
lr-wpan-spectrum-value-helper.cc:53
ns3::lrwpan::LrWpanSpectrumValueHelper::m_noiseFactor
double m_noiseFactor
A scaling factor for the noise power.
Definition
lr-wpan-spectrum-value-helper.h:68
ns3::lrwpan::LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
Definition
lr-wpan-spectrum-value-helper.cc:65
ns3::lrwpan::LrWpanSpectrumValueHelper::SetNoiseFactor
void SetNoiseFactor(double f)
Set the noise factor added to the thermal noise.
Definition
lr-wpan-spectrum-value-helper.cc:121
uint32_t
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:55
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:75
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
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:229
ns3::lrwpan::g_LrWpanSpectrumModelInitializerInstance
class ns3::lrwpan::LrWpanSpectrumModelInitializer g_LrWpanSpectrumModelInitializerInstance
Global object used to initialize the LrWpan Spectrum Model.
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
lr-wpan-spectrum-value-helper.h
ns3::lrwpan::g_LrWpanSpectrumModel
Ptr< SpectrumModel > g_LrWpanSpectrumModel
Global object used to initialize the LrWpan Spectrum Model.
Definition
lr-wpan-spectrum-value-helper.cc:23
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Bands
std::vector< BandInfo > Bands
Container of BandInfo.
Definition
spectrum-model.h:49
ns3::BandInfo
The building block of a SpectrumModel.
Definition
spectrum-model.h:42
ns3::BandInfo::fl
double fl
lower limit of subband
Definition
spectrum-model.h:43
src
lr-wpan
model
lr-wpan-spectrum-value-helper.cc
Generated on Mon Dec 15 2025 15:21:55 for ns-3 by
1.9.8