A Discrete-Event Network Simulator
API
tv-spectrum-transmitter.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 University of Washington
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: Benjamin Cizdziel <ben.cizdziel@gmail.com>
19  */
20 
21 #include <ns3/log.h>
22 #include <ns3/simulator.h>
23 #include <ns3/enum.h>
24 #include <ns3/uinteger.h>
25 #include <ns3/double.h>
26 #include <ns3/integer.h>
27 #include <ns3/string.h>
28 #include <ns3/pointer.h>
29 #include <ns3/isotropic-antenna-model.h>
30 #include <ns3/antenna-model.h>
31 #include <cmath>
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("TvSpectrumTransmitter");
37 
38 NS_OBJECT_ENSURE_REGISTERED (TvSpectrumTransmitter);
39 
41  : m_mobility (0),
42  m_antenna (CreateObject<IsotropicAntennaModel> ()),
43  m_netDevice (0),
44  m_channel (0),
45  m_tvType (TVTYPE_8VSB),
46  m_startFrequency (500e6),
47  m_channelBandwidth (6e6),
48  m_basePsd (20),
49  m_txPsd (0),
50  m_startingTime (Seconds (0)),
51  m_transmitDuration (Seconds (0.2)),
52  m_active (false)
53 {
54  NS_LOG_FUNCTION (this);
55 }
56 
58 {
59  m_mobility = 0;
60  m_antenna = 0;
61  m_netDevice = 0;
62  m_channel = 0;
63  m_txPsd = 0;
64  NS_LOG_FUNCTION (this);
65 }
66 
67 TypeId
69 {
70  static TypeId tid = TypeId("ns3::TvSpectrumTransmitter")
72  .SetGroupName ("Spectrum")
73  .AddConstructor<TvSpectrumTransmitter> ()
74  .AddAttribute ("TvType",
75  "The type of TV transmitter/modulation to be used.",
81  .AddAttribute ("StartFrequency",
82  "The lower end frequency (in Hz) of the TV transmitter's "
83  "signal. Must be greater than or equal to 0.",
84  DoubleValue (500e6),
86  MakeDoubleChecker<double> (0, std::numeric_limits<double>::max ()))
87  .AddAttribute ("ChannelBandwidth",
88  "The bandwidth (in Hz) of the TV transmitter's signal. Must "
89  "be greater than or equal to 0.",
90  DoubleValue (6e6),
92  MakeDoubleChecker<double> (0, std::numeric_limits<double>::max ()))
93  .AddAttribute ("BasePsd",
94  "The base power spectral density (in dBm/Hz) of the TV "
95  "transmitter's transmitted spectrum. Base PSD is the "
96  "maximum PSD of the spectrum excluding pilots. For analog "
97  "and COFDM transmitters this is the maximum PSD, but for "
98  "8-VSB transmitters this is the maximum PSD of the main "
99  "signal spectrum (flat-top segment) since the pilot "
100  "actually has the maximum PSD overall.",
101  DoubleValue (20),
103  MakeDoubleChecker<double> ())
104  .AddAttribute ("Antenna",
105  "The AntennaModel to be used. Allows classes inherited "
106  "from ns3::AntennaModel. Defaults to ns3::IsotropicAntennaModel.",
107  StringValue ("ns3::IsotropicAntennaModel"),
109  MakePointerChecker<AntennaModel> ())
110  .AddAttribute ("StartingTime",
111  "The time point after the simulation begins in which the TV "
112  "transmitter will begin transmitting.",
113  TimeValue (Seconds (0)),
115  MakeTimeChecker ())
116  .AddAttribute ("TransmitDuration",
117  "The duration of time that the TV transmitter will transmit for.",
118  TimeValue (Seconds (0.2)),
120  MakeTimeChecker ())
121  ;
122  return tid;
123 }
124 
125 void
127 {
128  NS_LOG_FUNCTION (this << c);
129  m_channel = c;
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION (this << m);
136  m_mobility = m;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << d);
143  m_netDevice = d;
144 }
145 
148 {
149  NS_LOG_FUNCTION (this);
150  return m_mobility;
151 }
152 
155 {
156  NS_LOG_FUNCTION (this);
157  return m_netDevice;
158 }
159 
162 {
163  NS_LOG_FUNCTION (this);
164  return 0;
165 }
166 
169 {
170  NS_LOG_FUNCTION (this);
171  return m_antenna;
172 }
173 
174 void
176 {
177  NS_LOG_FUNCTION (this << params);
178 }
179 
180 
183 {
184  NS_LOG_FUNCTION (this);
185  return m_channel;
186 }
187 
188 // Used as key for map containing created spectrum models
190 {
191  TvSpectrumModelId (double stFreq, double bwidth);
193  double bandwidth;
194 };
195 
196 TvSpectrumModelId::TvSpectrumModelId (double stFreq, double bwidth)
197  : startFrequency (stFreq),
198  bandwidth (bwidth)
199 {
200 }
201 
202 bool
204 {
205  return ( (a.startFrequency < b.startFrequency) ||
206  ( (a.startFrequency == b.startFrequency) && (a.bandwidth < b.bandwidth) ) );
207 }
208 
209 // Stores created spectrum models
210 static std::map<TvSpectrumModelId, Ptr<SpectrumModel> > g_tvSpectrumModelMap;
211 
227 void
229 {
230  NS_LOG_FUNCTION (this);
232  Ptr<SpectrumModel> model;
234  std::map<TvSpectrumModelId, Ptr<SpectrumModel> >::iterator iter = g_tvSpectrumModelMap.find (key);
235  if (iter != g_tvSpectrumModelMap.end ())
236  {
237  model = iter->second; //set SpectrumModel to previously created one
238  }
239  else // no previously created SpectrumModel with same frequency and bandwidth
240  {
241  Bands bands;
242  double halfSubBand = 0.5 * (m_channelBandwidth / 100);
243  for (double fl = m_startFrequency - halfSubBand; fl <= (m_startFrequency -
244  halfSubBand) + m_channelBandwidth; fl += m_channelBandwidth / 100)
245  {
246  BandInfo bi;
247  bi.fl = fl;
248  bi.fc = fl + halfSubBand;
249  bi.fh = fl + (2 * halfSubBand);
250  bands.push_back (bi);
251  }
252  model = Create<SpectrumModel> (bands);
253  g_tvSpectrumModelMap.insert (std::pair<TvSpectrumModelId, Ptr<SpectrumModel> > (key, model));
254  }
255  Ptr<SpectrumValue> psd = Create<SpectrumValue> (model);
256  double basePsdWattsHz = pow (10.0, (m_basePsd - 30) / 10.0); //convert dBm to W/Hz
257  switch (m_tvType)
258  {
259  case TVTYPE_8VSB:
260  {
261  for (int i = 0; i <= 100; i++)
262  {
263  switch (i)
264  {
265  case 0:
266  case 100:
267  (*psd) [i] = 0.015 * basePsdWattsHz;
268  break;
269  case 1:
270  case 99:
271  (*psd) [i] = 0.019 * basePsdWattsHz;
272  break;
273  case 2:
274  case 98:
275  (*psd) [i] = 0.034 * basePsdWattsHz;
276  break;
277  case 3:
278  case 97:
279  (*psd) [i] = 0.116 * basePsdWattsHz;
280  break;
281  case 4:
282  case 96:
283  (*psd) [i] = 0.309 * basePsdWattsHz;
284  break;
285  case 5:
286  (*psd) [i] = (0.502 * basePsdWattsHz) + (21.577 * basePsdWattsHz); //pilot
287  break;
288  case 6:
289  case 94:
290  (*psd) [i] = 0.696 * basePsdWattsHz;
291  break;
292  case 7:
293  case 93:
294  (*psd) [i] = 0.913 * basePsdWattsHz;
295  break;
296  case 8:
297  case 92:
298  (*psd) [i] = 0.978 * basePsdWattsHz;
299  break;
300  case 9:
301  case 91:
302  (*psd) [i] = 0.990 * basePsdWattsHz;
303  break;
304  case 95:
305  (*psd) [i] = 0.502 * basePsdWattsHz;
306  break;
307  default:
308  (*psd) [i] = basePsdWattsHz;
309  break;
310  }
311  }
312  break;
313  }
314  case TVTYPE_COFDM:
315  {
316  for (int i = 0; i <= 100; i++)
317  {
318  switch (i)
319  {
320  case 0:
321  case 100:
322  (*psd) [i] = 1.52e-4 * basePsdWattsHz;
323  break;
324  case 1:
325  case 99:
326  (*psd) [i] = 2.93e-4 * basePsdWattsHz;
327  break;
328  case 2:
329  case 98:
330  (*psd) [i] = 8.26e-4 * basePsdWattsHz;
331  break;
332  case 3:
333  case 97:
334  (*psd) [i] = 0.0927 * basePsdWattsHz;
335  break;
336  default:
337  (*psd) [i] = basePsdWattsHz;
338  break;
339  }
340  }
341  break;
342  }
343  case TVTYPE_ANALOG:
344  {
345  for (int i = 0; i <= 100; i++)
346  {
347  switch (i)
348  {
349  case 0:
350  case 1:
351  case 2:
352  case 3:
353  (*psd) [i] = 27.07946e-08 * basePsdWattsHz;
354  break;
355  case 4:
356  case 5:
357  case 6:
358  (*psd) [i] = 2.51189e-07 * basePsdWattsHz;
359  break;
360  case 7:
361  case 8:
362  case 9:
363  (*psd) [i] = 1e-06 * basePsdWattsHz;
364  break;
365  case 10:
366  case 11:
367  case 12:
368  (*psd) [i] = 2.39883e-06 * basePsdWattsHz;
369  break;
370  case 13:
371  case 14:
372  case 15:
373  (*psd) [i] = 5.62341e-06 * basePsdWattsHz;
374  break;
375  case 16:
376  case 17:
377  case 18:
378  (*psd) [i] = 6.68344e-06 * basePsdWattsHz;
379  break;
380  case 19:
381  case 20:
382  case 21:
383  (*psd) [i] = 1.25893e-05 * basePsdWattsHz;
384  break;
385  case 22:
386  case 23:
387  case 24:
388  (*psd) [i] = 3.16228e-05 * basePsdWattsHz;
389  break;
390  case 25:
391  (*psd) [i] = 0.000158489 * basePsdWattsHz;
392  break;
393  case 26:
394  (*psd) [i] = basePsdWattsHz;
395  break;
396  case 27:
397  (*psd) [i] = 7.49894e-05 * basePsdWattsHz;
398  break;
399  case 28:
400  case 29:
401  case 30:
402  (*psd) [i] = 2.37137e-05 * basePsdWattsHz;
403  break;
404  case 31:
405  case 32:
406  case 33:
407  (*psd) [i] = 1.14815e-05 * basePsdWattsHz;
408  break;
409  case 34:
410  case 35:
411  case 36:
412  (*psd) [i] = 7.49894e-06 * basePsdWattsHz;
413  break;
414  case 37:
415  case 38:
416  case 39:
417  (*psd) [i] = 5.62341e-06 * basePsdWattsHz;
418  break;
419  case 40:
420  case 41:
421  case 42:
422  (*psd) [i] = 4.21697e-06 * basePsdWattsHz;
423  break;
424  case 43:
425  case 44:
426  case 45:
427  (*psd) [i] = 3.16228e-06 * basePsdWattsHz;
428  break;
429  case 46:
430  case 47:
431  case 48:
432  (*psd) [i] = 1.99526e-06 * basePsdWattsHz;
433  break;
434  case 49:
435  case 50:
436  case 51:
437  (*psd) [i] = 1.25893e-06 * basePsdWattsHz;
438  break;
439  case 52:
440  case 53:
441  case 54:
442  (*psd) [i] = 8.41395e-07 * basePsdWattsHz;
443  break;
444  case 55:
445  case 56:
446  case 57:
447  (*psd) [i] = 6.30957e-07 * basePsdWattsHz;
448  break;
449  case 58:
450  case 59:
451  case 60:
452  (*psd) [i] = 5.88844e-07 * basePsdWattsHz;
453  break;
454  case 61:
455  case 62:
456  case 63:
457  (*psd) [i] = 5.62341e-07 * basePsdWattsHz;
458  break;
459  case 64:
460  case 65:
461  case 66:
462  (*psd) [i] = 5.30884e-07 * basePsdWattsHz;
463  break;
464  case 67:
465  case 68:
466  case 69:
467  (*psd) [i] = 5.01187e-07 * basePsdWattsHz;
468  break;
469  case 70:
470  case 71:
471  case 72:
472  (*psd) [i] = 5.30884e-07 * basePsdWattsHz;
473  break;
474  case 73:
475  case 74:
476  case 75:
477  (*psd) [i] = 7.49894e-07 * basePsdWattsHz;
478  break;
479  case 76:
480  case 77:
481  case 78:
482  (*psd) [i] = 1.77828e-06 * basePsdWattsHz;
483  break;
484  case 79:
485  (*psd) [i] = 5.62341e-06 * basePsdWattsHz;
486  break;
487  case 80:
488  (*psd) [i] = 0.000177828 * basePsdWattsHz;
489  break;
490  case 81:
491  (*psd) [i] = 4.21697e-06 * basePsdWattsHz;
492  break;
493  case 82:
494  case 83:
495  case 84:
496  (*psd) [i] = 3.16228e-06 * basePsdWattsHz;
497  break;
498  case 85:
499  case 86:
500  case 87:
501  (*psd) [i] = 3.16228e-06 * basePsdWattsHz;
502  break;
503  case 88:
504  case 89:
505  case 90:
506  (*psd) [i] = 4.73151e-06 * basePsdWattsHz;
507  break;
508  case 91:
509  case 92:
510  case 93:
511  (*psd) [i] = 7.49894e-06 * basePsdWattsHz;
512  break;
513  case 94:
514  (*psd) [i] = 7.49894e-05 * basePsdWattsHz;
515  break;
516  case 95:
517  (*psd) [i] = 0.1 * basePsdWattsHz;
518  break;
519  case 96:
520  (*psd) [i] = 7.49894e-05 * basePsdWattsHz;
521  break;
522  case 97:
523  case 98:
524  case 99:
525  case 100:
526  (*psd) [i] = 1.77828e-06 * basePsdWattsHz;
527  break;
528  }
529  }
530  break;
531  }
532  default:
533  {
534  NS_LOG_ERROR ("no valid TvType selected");
535  break;
536  }
537  }
538  m_txPsd = psd;
539 }
540 
543 {
544  NS_LOG_FUNCTION (this);
545  return m_txPsd;
546 }
547 
548 void
550 {
551  NS_LOG_FUNCTION (this);
552  NS_ASSERT (m_txPsd);
553  Ptr<SpectrumSignalParameters> signal = Create<SpectrumSignalParameters> ();
554  signal->duration = m_transmitDuration;
555  signal->psd = m_txPsd;
556  signal->txPhy = GetObject<SpectrumPhy> ();
557  signal->txAntenna = m_antenna;
558  m_channel->StartTx (signal);
559 }
560 
561 void
563 {
564  NS_LOG_FUNCTION (this);
565  if (!m_active)
566  {
567  NS_LOG_LOGIC ("starting TV transmitter");
568  m_active = true;
570  }
571 }
572 
573 void
575 {
576  NS_LOG_FUNCTION (this);
577  m_active = false;
578 }
579 
580 } // namespace ns3
581 
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Ptr< SpectrumChannel > m_channel
Pointer to spectrum channel object.
Ptr< NetDevice > GetDevice() const
get the associated NetDevice instance
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 "...
Ptr< const SpectrumModel > GetRxSpectrumModel() const
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Hold variables of type string.
Definition: string.h:41
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
Ptr< AntennaModel > m_antenna
Pointer to antenna model object.
virtual void CreateTvPsd()
Creates power spectral density (PSD) spectrum of the TV transmitter and sets it for transmission...
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Ptr< NetDevice > m_netDevice
Pointer to net device object.
static std::map< TvSpectrumModelId, Ptr< SpectrumModel > > g_tvSpectrumModelMap
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
virtual void Stop()
Stops the TV Transmitter's transmission on the spectrum channel.
Ptr< AntennaModel > GetRxAntenna()
get the AntennaModel used by the NetDevice for reception
enum TvType m_tvType
Type of TV transmitter.
std::vector< BandInfo > Bands
bool m_active
True if TV transmitter is transmitting.
Ptr< SpectrumValue > GetTxPsd() const
Get the power spectral density of the TV transmitter's signal.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
Ptr< SpectrumValue > m_txPsd
Pointer to power spectral density of TV transmitter's signal.
double m_startFrequency
Start frequency (in Hz) of TV transmitter's signal.
virtual void Start()
Starts the TV Transmitter's transmission on the spectrum channel.
Ptr< MobilityModel > GetMobility()
get the associated MobilityModel instance
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:220
Hold variables of type enum.
Definition: enum.h:54
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1216
virtual ~TvSpectrumTransmitter()
Destructor.
AttributeValue implementation for Time.
Definition: nstime.h:957
Isotropic antenna model.
double fc
center frequency
double m_channelBandwidth
Bandwidth (in Hz) of TV transmitter's signal.
Time m_transmitDuration
Length of time that TV transmitter will transmit for.
Time m_startingTime
Timepoint after simulation begins that TV transmitter will begin transmitting.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Ptr< SpectrumChannel > GetChannel() const
Get the spectrum channel.
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
virtual void SetupTx()
Sets up signal to be transmitted.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double fl
lower limit of subband
SpectrumPhy implementation that creates a customizable TV transmitter which transmits a PSD spectrum ...
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:958
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< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
TvSpectrumModelId(double stFreq, double bwidth)
TvSpectrumTransmitter()
Default constructor.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
Ptr< MobilityModel > m_mobility
Pointer to mobility model object.
Ptr< T > CreateObject(void)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:524
double m_basePsd
Base power spectral density value (in dBm/Hz) of TV transmitter's signal.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
static TypeId GetTypeId(void)
Register this type.
double fh
upper limit of subband
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
void SetDevice(Ptr< NetDevice > d)
set the associated NetDevice instance
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
The building block of a SpectrumModel.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826