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
spectrum-model.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 CTTC
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Nicola Baldo <nbaldo@cttc.es>
7
*/
8
9
#include "
spectrum-model.h
"
10
11
#include "ns3/assert.h"
12
#include "ns3/log.h"
13
14
#include <cmath>
15
#include <cstddef>
16
17
namespace
ns3
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"SpectrumModel"
);
21
22
bool
23
operator==
(
const
SpectrumModel
& lhs,
const
SpectrumModel
& rhs)
24
{
25
return
(lhs.
m_uid
== rhs.
m_uid
);
26
}
27
28
SpectrumModelUid_t
SpectrumModel::m_uidCount
= 0;
29
30
SpectrumModel::SpectrumModel
(
const
std::vector<double>& centerFreqs)
31
{
32
NS_ASSERT
(centerFreqs.size() > 1);
33
m_uid
= ++
m_uidCount
;
34
35
for
(
auto
it = centerFreqs.begin(); it != centerFreqs.end(); ++it)
36
{
37
BandInfo
e;
38
e.
fc
= *it;
39
if
(it == centerFreqs.begin())
40
{
41
double
delta = ((*(it + 1)) - (*it)) / 2;
42
e.
fl
= *it - delta;
43
e.
fh
= *it + delta;
44
}
45
else
if
(it == centerFreqs.end() - 1)
46
{
47
double
delta = ((*it) - (*(it - 1))) / 2;
48
e.
fl
= *it - delta;
49
e.
fh
= *it + delta;
50
}
51
else
52
{
53
e.
fl
= ((*it) + (*(it - 1))) / 2;
54
e.
fh
= ((*(it + 1)) + (*it)) / 2;
55
}
56
m_bands
.push_back(e);
57
}
58
}
59
60
SpectrumModel::SpectrumModel
(
const
Bands
& bands)
61
{
62
m_uid
= ++
m_uidCount
;
63
NS_LOG_INFO
(
"creating new SpectrumModel, m_uid="
<<
m_uid
);
64
m_bands
= bands;
65
}
66
67
SpectrumModel::SpectrumModel
(
Bands
&& bands)
68
:
m_bands
(
std
::move(bands))
69
{
70
m_uid
= ++
m_uidCount
;
71
NS_LOG_INFO
(
"creating new SpectrumModel, m_uid="
<<
m_uid
);
72
}
73
74
Bands::const_iterator
75
SpectrumModel::Begin
()
const
76
{
77
return
m_bands
.begin();
78
}
79
80
Bands::const_iterator
81
SpectrumModel::End
()
const
82
{
83
return
m_bands
.end();
84
}
85
86
size_t
87
SpectrumModel::GetNumBands
()
const
88
{
89
return
m_bands
.size();
90
}
91
92
SpectrumModelUid_t
93
SpectrumModel::GetUid
()
const
94
{
95
return
m_uid
;
96
}
97
98
bool
99
SpectrumModel::IsOrthogonal
(
const
SpectrumModel
& other)
const
100
{
101
for
(
auto
myIt =
Begin
(); myIt !=
End
(); ++myIt)
102
{
103
for
(
auto
otherIt = other.
Begin
(); otherIt != other.
End
(); ++otherIt)
104
{
105
if
(std::max(myIt->fl, otherIt->fl) < std::min(myIt->fh, otherIt->fh))
106
{
107
return
false
;
108
}
109
}
110
}
111
return
true
;
112
}
113
114
}
// namespace ns3
ns3::SpectrumModel::IsOrthogonal
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
Definition
spectrum-model.cc:99
ns3::SpectrumModel::m_uidCount
static SpectrumModelUid_t m_uidCount
counter to assign m_uids
Definition
spectrum-model.h:136
ns3::SpectrumModel::m_uid
SpectrumModelUid_t m_uid
unique id for a given set of frequencies
Definition
spectrum-model.h:135
ns3::SpectrumModel::SpectrumModel
SpectrumModel(const std::vector< double > ¢erFreqs)
This constructs a SpectrumModel based on a given set of frequencies, which is assumed to be sorted by...
Definition
spectrum-model.cc:30
ns3::SpectrumModel::End
Bands::const_iterator End() const
Const Iterator to the model Bands container end.
Definition
spectrum-model.cc:81
ns3::SpectrumModel::GetNumBands
size_t GetNumBands() const
Definition
spectrum-model.cc:87
ns3::SpectrumModel::Begin
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
Definition
spectrum-model.cc:75
ns3::SpectrumModel::GetUid
SpectrumModelUid_t GetUid() const
Definition
spectrum-model.cc:93
ns3::SpectrumModel::m_bands
Bands m_bands
Actual definition of frequency bands within this SpectrumModel.
Definition
spectrum-model.h:134
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_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition
event-id.h:146
ns3::Bands
std::vector< BandInfo > Bands
Container of BandInfo.
Definition
spectrum-model.h:49
ns3::SpectrumModelUid_t
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
Definition
spectrum-model.h:52
std
STL namespace.
spectrum-model.h
ns3::BandInfo
The building block of a SpectrumModel.
Definition
spectrum-model.h:42
ns3::BandInfo::fc
double fc
center frequency
Definition
spectrum-model.h:44
ns3::BandInfo::fl
double fl
lower limit of subband
Definition
spectrum-model.h:43
ns3::BandInfo::fh
double fh
upper limit of subband
Definition
spectrum-model.h:45
src
spectrum
model
spectrum-model.cc
Generated on Wed Oct 1 2025 18:22:28 for ns-3 by
1.13.2