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