A Discrete-Event Network Simulator
API
spectrum-analyzer.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 
22 #include <ns3/object-factory.h>
23 #include <ns3/log.h>
24 #include <ns3/double.h>
25 #include <ns3/simulator.h>
26 #include <ns3/trace-source-accessor.h>
27 #include <ns3/antenna-model.h>
28 
29 #include "spectrum-analyzer.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("SpectrumAnalyzer");
34 
35 NS_OBJECT_ENSURE_REGISTERED (SpectrumAnalyzer);
36 
38  : m_mobility (0),
39  m_netDevice (0),
40  m_channel (0),
41  m_spectrumModel (0),
42  m_sumPowerSpectralDensity (0),
43  m_resolution (MilliSeconds (50)),
44  m_active (false)
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
49 
50 
52 {
53  NS_LOG_FUNCTION (this);
54 }
55 
56 void
58 {
59  NS_LOG_FUNCTION (this);
60  m_mobility = 0;
61  m_netDevice = 0;
62  m_channel = 0;
63  m_spectrumModel = 0;
67 }
68 
69 TypeId
71 {
72  static TypeId tid = TypeId ("ns3::SpectrumAnalyzer")
74  .SetGroupName ("Spectrum")
75  .AddConstructor<SpectrumAnalyzer> ()
76  .AddAttribute ("Resolution",
77  "The length of the time interval over which the "
78  "power spectral density of incoming signals is averaged",
79  TimeValue (MilliSeconds (1)),
81  MakeTimeChecker ())
82  .AddAttribute ("NoisePowerSpectralDensity",
83  "The power spectral density of the measuring instrument "
84  "noise, in Watt/Hz. Mostly useful to make spectrograms "
85  "look more similar to those obtained by real devices. "
86  "Defaults to the value for thermal noise at 300K.",
87  DoubleValue (1.38e-23 * 300),
89  MakeDoubleChecker<double> ())
90  .AddTraceSource ("AveragePowerSpectralDensityReport",
91  "Trace fired whenever a new value for the average "
92  "Power Spectral Density is calculated",
94  "ns3::SpectrumValue::TracedCallback")
95  ;
96  return tid;
97 }
98 
99 
100 
103 {
104  return m_netDevice;
105 }
106 
107 
110 {
111  return m_mobility;
112 }
113 
114 
117 {
118  return m_spectrumModel;
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION (this << d);
125  m_netDevice = d;
126 }
127 
128 
129 void
131 {
132  NS_LOG_FUNCTION (this << m);
133  m_mobility = m;
134 }
135 
136 
137 void
139 {
140  NS_LOG_FUNCTION (this << c);
141  m_channel = c;
142 }
143 
144 
147 {
148  return m_antenna;
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION (this << a);
155  m_antenna = a;
156 }
157 
158 
159 
160 void
162 {
163  NS_LOG_FUNCTION ( this << params);
164  AddSignal (params->psd);
165  Simulator::Schedule (params->duration, &SpectrumAnalyzer::SubtractSignal, this, params->psd);
166 }
167 
168 
169 void
171 {
172  NS_LOG_FUNCTION (this << *psd);
174  (*m_sumPowerSpectralDensity) += (*psd);
175 }
176 
177 void
179 {
180  NS_LOG_FUNCTION (this << *psd);
182  (*m_sumPowerSpectralDensity) -= (*psd);
183 }
184 
185 void
187 {
188  NS_LOG_FUNCTION (this);
189  if (m_lastChangeTime < Now ())
190  {
191  (*m_energySpectralDensity) += (*m_sumPowerSpectralDensity) * ((Now () - m_lastChangeTime).GetSeconds ());
192  m_lastChangeTime = Now ();
193  }
194  else
195  {
197  }
198 }
199 
200 void
202 {
203  NS_LOG_FUNCTION (this);
204 
206  Ptr<SpectrumValue> avgPowerSpectralDensity = Create<SpectrumValue> (m_sumPowerSpectralDensity->GetSpectrumModel ());
207  (*avgPowerSpectralDensity) = (*m_energySpectralDensity) / m_resolution.GetSeconds ();
208  (*avgPowerSpectralDensity) += m_noisePowerSpectralDensity;
209  (*m_energySpectralDensity) = 0;
210 
211  NS_LOG_INFO ("generating report");
212  m_averagePowerSpectralDensityReportTrace (avgPowerSpectralDensity);
213 
214  *avgPowerSpectralDensity = 0;
215 
216  if (m_active)
217  {
219  }
220 }
221 
222 
223 
224 void
226 {
227  NS_LOG_FUNCTION (this << f);
228  m_spectrumModel = f;
230  m_sumPowerSpectralDensity = Create<SpectrumValue> (f);
231  m_energySpectralDensity = Create<SpectrumValue> (f);
233 }
234 
235 
236 
237 
238 void
240 {
241  NS_LOG_FUNCTION (this);
242  if (!m_active)
243  {
244  NS_LOG_LOGIC ("activating");
245  m_active = true;
247  }
248 }
249 
250 
251 void
253 {
254  m_active = false;
255 }
256 
257 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::SpectrumAnalyzer::GetRxSpectrumModel
Ptr< const SpectrumModel > GetRxSpectrumModel() const
Definition: spectrum-analyzer.cc:116
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
ns3::SpectrumAnalyzer::SetMobility
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Definition: spectrum-analyzer.cc:130
ns3::SpectrumAnalyzer::m_antenna
Ptr< AntennaModel > m_antenna
Pointer to the Antenna model.
Definition: spectrum-analyzer.h:104
ns3::SpectrumAnalyzer::m_channel
Ptr< SpectrumChannel > m_channel
Pointer to the channel to be analyzed.
Definition: spectrum-analyzer.h:106
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SpectrumAnalyzer::m_netDevice
Ptr< NetDevice > m_netDevice
Pointer to the NetDevice using this object.
Definition: spectrum-analyzer.h:105
ns3::SpectrumAnalyzer::StartRx
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
Definition: spectrum-analyzer.cc:161
ns3::SpectrumAnalyzer::SetChannel
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: spectrum-analyzer.cc:138
ns3::SpectrumAnalyzer::SetAntenna
void SetAntenna(Ptr< AntennaModel > a)
Set the AntennaModel to be used.
Definition: spectrum-analyzer.cc:152
ns3::SpectrumAnalyzer::m_active
bool m_active
True if the analyzer is active.
Definition: spectrum-analyzer.h:134
ns3::SpectrumAnalyzer::GetDevice
Ptr< NetDevice > GetDevice() const
Get the associated NetDevice instance.
Definition: spectrum-analyzer.cc:102
spectrum-analyzer.h
ns3::SpectrumValue::GetSpectrumModel
Ptr< const SpectrumModel > GetSpectrumModel() const
Definition: spectrum-value.cc:62
ns3::SpectrumAnalyzer::DoDispose
void DoDispose()
Destructor implementation.
Definition: spectrum-analyzer.cc:57
ns3::SpectrumAnalyzer::GetMobility
Ptr< MobilityModel > GetMobility() const
Get the associated MobilityModel instance.
Definition: spectrum-analyzer.cc:109
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::SpectrumAnalyzer::AddSignal
void AddSignal(Ptr< const SpectrumValue > psd)
Adds a signal to the data collected.
Definition: spectrum-analyzer.cc:170
ns3::Ptr< NetDevice >
ns3::SpectrumAnalyzer::SetRxSpectrumModel
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the SpectrumAnalyzer to represent incoming signals.
Definition: spectrum-analyzer.cc:225
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
ns3::SpectrumAnalyzer::SetDevice
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
Definition: spectrum-analyzer.cc:122
ns3::SpectrumAnalyzer::m_sumPowerSpectralDensity
Ptr< SpectrumValue > m_sumPowerSpectralDensity
Sum of the received PSD.
Definition: spectrum-analyzer.h:129
ns3::SpectrumAnalyzer::Stop
virtual void Stop()
Stop the spectrum analyzer.
Definition: spectrum-analyzer.cc:252
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1297
ns3::SpectrumPhy
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:46
ns3::SpectrumAnalyzer::m_averagePowerSpectralDensityReportTrace
TracedCallback< Ptr< const SpectrumValue > > m_averagePowerSpectralDensityReportTrace
TracedCallback - average power spectral density report.
Definition: spectrum-analyzer.h:137
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::MakeDoubleAccessor
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
ns3::SpectrumAnalyzer::SubtractSignal
void SubtractSignal(Ptr< const SpectrumValue > psd)
Removes a signal to the data collected.
Definition: spectrum-analyzer.cc:178
ns3::SpectrumAnalyzer::~SpectrumAnalyzer
virtual ~SpectrumAnalyzer()
Definition: spectrum-analyzer.cc:51
ns3::SpectrumAnalyzer::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: spectrum-analyzer.cc:70
ns3::SpectrumAnalyzer::UpdateEnergyReceivedSoFar
void UpdateEnergyReceivedSoFar()
Updates the data about the received Energy.
Definition: spectrum-analyzer.cc:186
ns3::SpectrumAnalyzer::GetRxAntenna
Ptr< AntennaModel > GetRxAntenna() const
Get the AntennaModel used by the NetDevice for reception.
Definition: spectrum-analyzer.cc:146
ns3::SpectrumAnalyzer::GenerateReport
virtual void GenerateReport()
Generates a report of the data collected so far.
Definition: spectrum-analyzer.cc:201
f
double f(double x, void *params)
Definition: 80211b.c:70
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::SpectrumAnalyzer::SpectrumAnalyzer
SpectrumAnalyzer()
Definition: spectrum-analyzer.cc:37
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::SpectrumAnalyzer::m_spectrumModel
Ptr< SpectrumModel > m_spectrumModel
Spectrum model.
Definition: spectrum-analyzer.h:128
ns3::SpectrumAnalyzer::m_energySpectralDensity
Ptr< SpectrumValue > m_energySpectralDensity
Energy spectral density.
Definition: spectrum-analyzer.h:130
ns3::SpectrumAnalyzer::m_noisePowerSpectralDensity
double m_noisePowerSpectralDensity
Noise power spectral density.
Definition: spectrum-analyzer.h:131
ns3::SpectrumAnalyzer::m_lastChangeTime
Time m_lastChangeTime
When the last update happened.
Definition: spectrum-analyzer.h:133
ns3::SpectrumAnalyzer::m_mobility
Ptr< MobilityModel > m_mobility
Pointer to the mobility model.
Definition: spectrum-analyzer.h:103
ns3::SpectrumAnalyzer
Simple SpectrumPhy implementation that averages the spectrum power density of incoming transmissions ...
Definition: spectrum-analyzer.h:49
ns3::SpectrumAnalyzer::m_resolution
Time m_resolution
Time resolution.
Definition: spectrum-analyzer.h:132
ns3::SpectrumAnalyzer::Start
virtual void Start()
Start the spectrum analyzer.
Definition: spectrum-analyzer.cc:239
ns3::Object::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1354