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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
10
11#include <ns3/assert.h>
12#include <ns3/log.h>
13
14#include <algorithm>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("SpectrumConverter");
20
24
26 Ptr<const SpectrumModel> toSpectrumModel)
27{
28 NS_LOG_FUNCTION(this);
29 m_fromSpectrumModel = fromSpectrumModel;
30 m_toSpectrumModel = toSpectrumModel;
31
32 size_t rowPtr = 0;
33 for (auto toit = toSpectrumModel->Begin(); toit != toSpectrumModel->End(); ++toit)
34 {
35 size_t colInd = 0;
36 for (auto fromit = fromSpectrumModel->Begin(); fromit != fromSpectrumModel->End(); ++fromit)
37 {
38 double c = GetCoefficient(*fromit, *toit);
39 NS_LOG_LOGIC("(" << fromit->fl << "," << fromit->fh << ")"
40 << " --> "
41 << "(" << toit->fl << "," << toit->fh << ")"
42 << " = " << c);
43 if (c > 0)
44 {
45 m_conversionMatrix.push_back(c);
46 m_conversionColInd.push_back(colInd);
47 rowPtr++;
48 }
49 colInd++;
50 }
51 m_conversionRowPtr.push_back(rowPtr);
52 }
53}
54
55double
57{
58 NS_LOG_FUNCTION(this);
59 double coeff = std::min(from.fh, to.fh) - std::max(from.fl, to.fl);
60 coeff = std::max(0.0, coeff);
61 coeff = std::min(1.0, coeff / (to.fh - to.fl));
62 return coeff;
63}
64
67{
68 NS_ASSERT(*(fvvf->GetSpectrumModel()) == *m_fromSpectrumModel);
69
71
72 auto tvit = tvvf->ValuesBegin();
73 size_t i = 0; // Index of conversion coefficient
74
75 for (auto convIt = m_conversionRowPtr.begin(); convIt != m_conversionRowPtr.end(); ++convIt)
76 {
77 double sum = 0;
78 while (i < *convIt)
79 {
80 sum += (*fvvf)[m_conversionColInd.at(i)] * m_conversionMatrix.at(i);
81 i++;
82 }
83 *tvit = sum;
84 ++tvit;
85 }
86
87 return tvvf;
88}
89
90} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
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:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
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