A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
NS_LOG_COMPONENT_DEFINE
(
"SpectrumConverter"
);
29
30
namespace
ns3 {
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
for
(Bands::const_iterator toit = toSpectrumModel->
Begin
(); toit != toSpectrumModel->
End
(); ++toit)
43
{
44
std::vector<double> coeffs;
45
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
coeffs.push_back (c);
54
}
55
56
m_conversionMatrix
.push_back (coeffs);
57
}
58
59
}
60
61
62
double
SpectrumConverter::GetCoefficient
(
const
BandInfo
& from,
const
BandInfo
& to)
const
63
{
64
NS_LOG_FUNCTION
(
this
);
65
double
coeff = std::min (from.
fh
, to.
fh
) - std::max (from.
fl
, to.
fl
);
66
coeff = std::max (0.0, coeff);
67
coeff = std::min (1.0, coeff / (to.
fh
- to.
fl
));
68
return
coeff;
69
}
70
71
72
73
Ptr<SpectrumValue>
74
SpectrumConverter::Convert
(
Ptr<const SpectrumValue>
fvvf)
const
75
{
76
NS_ASSERT
( *(fvvf->
GetSpectrumModel
()) == *
m_fromSpectrumModel
);
77
78
Ptr<SpectrumValue>
tvvf = Create<SpectrumValue> (
m_toSpectrumModel
);
79
80
Values::iterator tvit = tvvf->
ValuesBegin
();
81
82
83
for
(std::vector<std::vector<double> >::const_iterator toit =
m_conversionMatrix
.begin ();
84
toit !=
m_conversionMatrix
.end ();
85
++toit)
86
{
87
NS_ASSERT
(tvit != tvvf->
ValuesEnd
());
88
Values::const_iterator fvit = fvvf->
ConstValuesBegin
();
89
90
double
sum = 0;
91
for
(std::vector<double>::const_iterator fromit = toit->begin ();
92
fromit != toit->end ();
93
++fromit)
94
{
95
NS_ASSERT
(fvit != fvvf->
ConstValuesEnd
());
96
sum += (*fvit) * (*fromit);
97
++fvit;
98
}
99
*tvit = sum;
100
++tvit;
101
}
102
103
return
tvvf;
104
}
105
106
107
108
109
110
}
// namespace ns3
src
spectrum
model
spectrum-converter.cc
Generated on Tue May 14 2013 11:08:32 for ns-3 by
1.8.1.2