A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-converter.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#include <ns3/assert.h>
21#include <ns3/log.h>
22#include <ns3/spectrum-converter.h>
23
24#include <algorithm>
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("SpectrumConverter");
30
32{
33}
34
36 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();
44 ++toit)
45 {
46 size_t colInd = 0;
47 for (Bands::const_iterator fromit = fromSpectrumModel->Begin();
48 fromit != fromSpectrumModel->End();
49 ++fromit)
50 {
51 double c = GetCoefficient(*fromit, *toit);
52 NS_LOG_LOGIC("(" << fromit->fl << "," << fromit->fh << ")"
53 << " --> "
54 << "(" << toit->fl << "," << toit->fh << ")"
55 << " = " << c);
56 if (c > 0)
57 {
58 m_conversionMatrix.push_back(c);
59 m_conversionColInd.push_back(colInd);
60 rowPtr++;
61 }
62 colInd++;
63 }
64 m_conversionRowPtr.push_back(rowPtr);
65 }
66}
67
68double
70{
71 NS_LOG_FUNCTION(this);
72 double coeff = std::min(from.fh, to.fh) - std::max(from.fl, to.fl);
73 coeff = std::max(0.0, coeff);
74 coeff = std::min(1.0, coeff / (to.fh - to.fl));
75 return coeff;
76}
77
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} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
std::vector< double > m_conversionMatrix
matrix of conversion coefficients stored in Compressed Row Storage format
Ptr< const SpectrumModel > m_fromSpectrumModel
the SpectrumModel this SpectrumConverter instance can convert from
double GetCoefficient(const BandInfo &from, const BandInfo &to) const
Calculate the coefficient for value conversion between elements.
Ptr< const SpectrumModel > m_toSpectrumModel
the SpectrumModel this SpectrumConverter instance can convert to
Ptr< SpectrumValue > Convert(Ptr< const SpectrumValue > vvf) const
Convert a particular ValueVsFreq instance to.
std::vector< size_t > m_conversionRowPtr
offset of rows in m_conversionMatrix
std::vector< size_t > m_conversionColInd
column of each non-zero element in m_conversionMatrix
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
The building block of a SpectrumModel.
double fl
lower limit of subband
double fh
upper limit of subband