A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
spectrum-converter.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
#include <ns3/spectrum-converter.h>
22
#include <ns3/assert.h>
23
#include <ns3/log.h>
24
#include <algorithm>
25
26
27
28
namespace
ns3
{
29
30
NS_LOG_COMPONENT_DEFINE
(
"SpectrumConverter"
);
31
32
SpectrumConverter::SpectrumConverter
()
33
{
34
}
35
36
SpectrumConverter::SpectrumConverter
(
Ptr<const SpectrumModel>
fromSpectrumModel,
Ptr<const SpectrumModel>
toSpectrumModel)
37
{
38
NS_LOG_FUNCTION
(
this
);
39
m_fromSpectrumModel
= fromSpectrumModel;
40
m_toSpectrumModel
= toSpectrumModel;
41
42
size_t
rowPtr = 0;
43
for
(Bands::const_iterator toit = toSpectrumModel->
Begin
(); toit != toSpectrumModel->
End
(); ++toit)
44
{
45
size_t
colInd = 0;
46
for
(Bands::const_iterator fromit = fromSpectrumModel->
Begin
(); fromit != fromSpectrumModel->
End
(); ++fromit)
47
{
48
double
c =
GetCoefficient
(*fromit, *toit);
49
NS_LOG_LOGIC
(
"("
<< fromit->fl <<
","
<< fromit->fh <<
")"
50
<<
" --> "
<<
51
"("
<< toit->fl <<
","
<< toit->fh <<
")"
52
<<
" = "
<< c);
53
if
(c > 0)
54
{
55
m_conversionMatrix
.push_back (c);
56
m_conversionColInd
.push_back (colInd);
57
rowPtr++;
58
}
59
colInd++;
60
}
61
m_conversionRowPtr
.push_back (rowPtr);
62
}
63
64
}
65
66
67
double
SpectrumConverter::GetCoefficient
(
const
BandInfo
& from,
const
BandInfo
& to)
const
68
{
69
NS_LOG_FUNCTION
(
this
);
70
double
coeff =
std::min
(from.
fh
, to.
fh
) -
std::max
(from.
fl
, to.
fl
);
71
coeff =
std::max
(0.0, coeff);
72
coeff =
std::min
(1.0, coeff / (to.
fh
- to.
fl
));
73
return
coeff;
74
}
75
76
77
78
Ptr<SpectrumValue>
79
SpectrumConverter::Convert
(
Ptr<const SpectrumValue>
fvvf)
const
80
{
81
NS_ASSERT
( *(fvvf->GetSpectrumModel ()) == *
m_fromSpectrumModel
);
82
83
Ptr<SpectrumValue>
tvvf = Create<SpectrumValue> (
m_toSpectrumModel
);
84
85
Values::iterator tvit = tvvf->
ValuesBegin
();
86
size_t
i = 0;
// Index of conversion coefficient
87
88
for
(std::vector<size_t>::const_iterator convIt =
m_conversionRowPtr
.begin ();
89
convIt !=
m_conversionRowPtr
.end ();
90
++convIt)
91
{
92
double
sum = 0;
93
while
(i < *convIt)
94
{
95
sum += (*fvvf)[
m_conversionColInd
.at (i)] *
m_conversionMatrix
.at (i);
96
i++;
97
}
98
*tvit = sum;
99
++tvit;
100
}
101
102
return
tvvf;
103
}
104
105
106
107
108
109
}
// namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
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::SpectrumConverter::m_conversionMatrix
std::vector< double > m_conversionMatrix
matrix of conversion coefficients stored in Compressed Row Storage format
Definition:
spectrum-converter.h:81
min
#define min(a, b)
Definition:
80211b.c:42
ns3::SpectrumValue::ValuesBegin
Values::iterator ValuesBegin()
Definition:
spectrum-value.cc:82
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::BandInfo
The building block of a SpectrumModel.
Definition:
spectrum-model.h:46
ns3::SpectrumConverter::GetCoefficient
double GetCoefficient(const BandInfo &from, const BandInfo &to) const
Calculate the coefficient for value conversion between elements.
Definition:
spectrum-converter.cc:67
ns3::BandInfo::fl
double fl
lower limit of subband
Definition:
spectrum-model.h:47
ns3::Ptr< const SpectrumModel >
ns3::SpectrumConverter::m_conversionColInd
std::vector< size_t > m_conversionColInd
column of each non-zero element in m_conversionMatrix
Definition:
spectrum-converter.h:83
ns3::SpectrumModel::End
Bands::const_iterator End() const
Const Iterator to the model Bands container end.
Definition:
spectrum-model.cc:94
max
#define max(a, b)
Definition:
80211b.c:43
ns3::SpectrumConverter::SpectrumConverter
SpectrumConverter()
Definition:
spectrum-converter.cc:32
ns3::SpectrumConverter::Convert
Ptr< SpectrumValue > Convert(Ptr< const SpectrumValue > vvf) const
Convert a particular ValueVsFreq instance to.
Definition:
spectrum-converter.cc:79
ns3::SpectrumConverter::m_toSpectrumModel
Ptr< const SpectrumModel > m_toSpectrumModel
the SpectrumModel this SpectrumConverter instance can convert to
Definition:
spectrum-converter.h:86
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition:
log.h:289
ns3::BandInfo::fh
double fh
upper limit of subband
Definition:
spectrum-model.h:49
ns3::SpectrumConverter::m_fromSpectrumModel
Ptr< const SpectrumModel > m_fromSpectrumModel
the SpectrumModel this SpectrumConverter instance can convert from
Definition:
spectrum-converter.h:85
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::SpectrumConverter::m_conversionRowPtr
std::vector< size_t > m_conversionRowPtr
offset of rows in m_conversionMatrix
Definition:
spectrum-converter.h:82
ns3::SpectrumModel::Begin
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
Definition:
spectrum-model.cc:88
src
spectrum
model
spectrum-converter.cc
Generated on Fri Oct 1 2021 17:03:35 for ns-3 by
1.8.20