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  .AddConstructor<SpectrumAnalyzer> ()
75  .AddAttribute ("Resolution",
76  "The lengh of the time interval over which the "
77  "power spectral density of incoming signals is averaged",
78  TimeValue (MilliSeconds (1)),
80  MakeTimeChecker ())
81  .AddAttribute ("NoisePowerSpectralDensity",
82  "The power spectral density of the measuring instrument "
83  "noise, in Watt/Hz. Mostly useful to make spectrograms "
84  "look more similar to those obtained by real devices. "
85  "Defaults to the value for thermal noise at 300K.",
86  DoubleValue (1.38e-23 * 300),
88  MakeDoubleChecker<double> ())
89  .AddTraceSource ("AveragePowerSpectralDensityReport",
90  "Trace fired whenever a new value for the average "
91  "Power Spectral Density is calculated",
93  "ns3::SpectrumValue::TracedCallback")
94  ;
95  return tid;
96 }
97 
98 
99 
102 {
103  return m_netDevice;
104 }
105 
106 
109 {
110  return m_mobility;
111 }
112 
113 
116 {
117  return m_spectrumModel;
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION (this << d);
124  m_netDevice = d;
125 }
126 
127 
128 void
130 {
131  NS_LOG_FUNCTION (this << m);
132  m_mobility = m;
133 }
134 
135 
136 void
138 {
139  NS_LOG_FUNCTION (this << c);
140  m_channel = c;
141 }
142 
143 
146 {
147  return m_antenna;
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION (this << a);
154  m_antenna = a;
155 }
156 
157 
158 
159 void
161 {
162  NS_LOG_FUNCTION ( this << params);
163  AddSignal (params->psd);
164  Simulator::Schedule (params->duration, &SpectrumAnalyzer::SubtractSignal, this, params->psd);
165 }
166 
167 
168 void
170 {
171  NS_LOG_FUNCTION (this << *psd);
173  (*m_sumPowerSpectralDensity) += (*psd);
174 }
175 
176 void
178 {
179  NS_LOG_FUNCTION (this << *psd);
181  (*m_sumPowerSpectralDensity) -= (*psd);
182 }
183 
184 void
186 {
187  NS_LOG_FUNCTION (this);
188  if (m_lastChangeTime < Now ())
189  {
190  (*m_energySpectralDensity) += (*m_sumPowerSpectralDensity) * ((Now () - m_lastChangeTime).GetSeconds ());
191  m_lastChangeTime = Now ();
192  }
193  else
194  {
196  }
197 }
198 
199 void
201 {
202  NS_LOG_FUNCTION (this);
203 
205  Ptr<SpectrumValue> avgPowerSpectralDensity = Create<SpectrumValue> (m_sumPowerSpectralDensity->GetSpectrumModel ());
206  (*avgPowerSpectralDensity) = (*m_energySpectralDensity) / m_resolution.GetSeconds ();
207  (*avgPowerSpectralDensity) += m_noisePowerSpectralDensity;
208  (*m_energySpectralDensity) = 0;
209 
210  NS_LOG_INFO ("generating report");
211  m_averagePowerSpectralDensityReportTrace (avgPowerSpectralDensity);
212 
213  *avgPowerSpectralDensity = 0;
214 
215  if (m_active)
216  {
218  }
219 }
220 
221 
222 
223 void
225 {
226  NS_LOG_FUNCTION (this << f);
227  m_spectrumModel = f;
229  m_sumPowerSpectralDensity = Create<SpectrumValue> (f);
230  m_energySpectralDensity = Create<SpectrumValue> (f);
232 }
233 
234 
235 
236 
237 void
239 {
240  NS_LOG_FUNCTION (this);
241  if (!m_active)
242  {
243  NS_LOG_LOGIC ("activating");
244  m_active = true;
246  }
247 }
248 
249 
250 void
252 {
253  m_active = false;
254 }
255 
256 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
Ptr< NetDevice > m_netDevice
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
Ptr< NetDevice > GetDevice()
get the associated NetDevice instance
Ptr< AntennaModel > m_antenna
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:867
virtual void Start()
Start the spectrum analyzer.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:439
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:327
Ptr< SpectrumChannel > m_channel
AttributeValue implementation for Time.
Definition: nstime.h:921
Ptr< const SpectrumModel > GetSpectrumModel() const
static TypeId GetTypeId(void)
virtual void Stop()
Stop the spectrum analyzer.
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the SpectrumAnalyzer to represent incoming signals.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
void DoDispose()
Destructor implementation.
void SetDevice(Ptr< NetDevice > d)
set the associated NetDevice instance
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddSignal(Ptr< const SpectrumValue > psd)
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:922
TracedCallback< Ptr< const SpectrumValue > > m_averagePowerSpectralDensityReportTrace
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
Ptr< SpectrumValue > m_sumPowerSpectralDensity
Ptr< SpectrumModel > m_spectrumModel
Ptr< MobilityModel > GetMobility()
get the associated MobilityModel instance
virtual void GenerateReport()
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:330
Ptr< const SpectrumModel > GetRxSpectrumModel() const
Ptr< AntennaModel > GetRxAntenna()
get the AntennaModel used by the NetDevice for reception
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SubtractSignal(Ptr< const SpectrumValue > psd)
a unique identifier for an interface.
Definition: type-id.h:51
Ptr< MobilityModel > m_mobility
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
Ptr< SpectrumValue > m_energySpectralDensity
void SetAntenna(Ptr< AntennaModel > a)
set the AntennaModel to be used