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 
190 {
196  TvSpectrumModelId (double stFreq, double bwidth);
197  double startFrequency;
198  double bandwidth;
199 };
200 
201 TvSpectrumModelId::TvSpectrumModelId (double stFreq, double bwidth)
202  : startFrequency (stFreq),
203  bandwidth (bwidth)
204 {
205 }
206 
214 bool
216 {
217  return ( (a.startFrequency < b.startFrequency) ||
218  ( (a.startFrequency == b.startFrequency) && (a.bandwidth < b.bandwidth) ) );
219 }
220 
222 static std::map<TvSpectrumModelId, Ptr<SpectrumModel> > g_tvSpectrumModelMap;
223 
239 void
241 {
242  NS_LOG_FUNCTION (this);
244  Ptr<SpectrumModel> model;
246  std::map<TvSpectrumModelId, Ptr<SpectrumModel> >::iterator iter = g_tvSpectrumModelMap.find (key);
247  if (iter != g_tvSpectrumModelMap.end ())
248  {
249  model = iter->second; //set SpectrumModel to previously created one
250  }
251  else // no previously created SpectrumModel with same frequency and bandwidth
252  {
253  Bands bands;
254  double halfSubBand = 0.5 * (m_channelBandwidth / 100);
255  for (double fl = m_startFrequency - halfSubBand; fl <= (m_startFrequency -
256  halfSubBand) + m_channelBandwidth; fl += m_channelBandwidth / 100)
257  {
258  BandInfo bi;
259  bi.fl = fl;
260  bi.fc = fl + halfSubBand;
261  bi.fh = fl + (2 * halfSubBand);
262  bands.push_back (bi);
263  }
264  model = Create<SpectrumModel> (bands);
265  g_tvSpectrumModelMap.insert (std::pair<TvSpectrumModelId, Ptr<SpectrumModel> > (key, model));
266  }
267  Ptr<SpectrumValue> psd = Create<SpectrumValue> (model);
268  double basePsdWattsHz = pow (10.0, (m_basePsd - 30) / 10.0); //convert dBm to W/Hz
269  switch (m_tvType)
270  {
271  case TVTYPE_8VSB:
272  {
273  for (int i = 0; i <= 100; i++)
274  {
275  switch (i)
276  {
277  case 0:
278  case 100:
279  (*psd) [i] = 0.015 * basePsdWattsHz;
280  break;
281  case 1:
282  case 99:
283  (*psd) [i] = 0.019 * basePsdWattsHz;
284  break;
285  case 2:
286  case 98:
287  (*psd) [i] = 0.034 * basePsdWattsHz;
288  break;
289  case 3:
290  case 97:
291  (*psd) [i] = 0.116 * basePsdWattsHz;
292  break;
293  case 4:
294  case 96:
295  (*psd) [i] = 0.309 * basePsdWattsHz;
296  break;
297  case 5:
298  (*psd) [i] = (0.502 * basePsdWattsHz) + (21.577 * basePsdWattsHz); //pilot
299  break;
300  case 6:
301  case 94:
302  (*psd) [i] = 0.696 * basePsdWattsHz;
303  break;
304  case 7:
305  case 93:
306  (*psd) [i] = 0.913 * basePsdWattsHz;
307  break;
308  case 8:
309  case 92:
310  (*psd) [i] = 0.978 * basePsdWattsHz;
311  break;
312  case 9:
313  case 91:
314  (*psd) [i] = 0.990 * basePsdWattsHz;
315  break;
316  case 95:
317  (*psd) [i] = 0.502 * basePsdWattsHz;
318  break;
319  default:
320  (*psd) [i] = basePsdWattsHz;
321  break;
322  }
323  }
324  break;
325  }
326  case TVTYPE_COFDM:
327  {
328  for (int i = 0; i <= 100; i++)
329  {
330  switch (i)
331  {
332  case 0:
333  case 100:
334  (*psd) [i] = 1.52e-4 * basePsdWattsHz;
335  break;
336  case 1:
337  case 99:
338  (*psd) [i] = 2.93e-4 * basePsdWattsHz;
339  break;
340  case 2:
341  case 98:
342  (*psd) [i] = 8.26e-4 * basePsdWattsHz;
343  break;
344  case 3:
345  case 97:
346  (*psd) [i] = 0.0927 * basePsdWattsHz;
347  break;
348  default:
349  (*psd) [i] = basePsdWattsHz;
350  break;
351  }
352  }
353  break;
354  }
355  case TVTYPE_ANALOG:
356  {
357  for (int i = 0; i <= 100; i++)
358  {
359  switch (i)
360  {
361  case 0:
362  case 1:
363  case 2:
364  case 3:
365  (*psd) [i] = 27.07946e-08 * basePsdWattsHz;
366  break;
367  case 4:
368  case 5:
369  case 6:
370  (*psd) [i] = 2.51189e-07 * basePsdWattsHz;
371  break;
372  case 7:
373  case 8:
374  case 9:
375  (*psd) [i] = 1e-06 * basePsdWattsHz;
376  break;
377  case 10:
378  case 11:
379  case 12:
380  (*psd) [i] = 2.39883e-06 * basePsdWattsHz;
381  break;
382  case 13:
383  case 14:
384  case 15:
385  (*psd) [i] = 5.62341e-06 * basePsdWattsHz;
386  break;
387  case 16:
388  case 17:
389  case 18:
390  (*psd) [i] = 6.68344e-06 * basePsdWattsHz;
391  break;
392  case 19:
393  case 20:
394  case 21:
395  (*psd) [i] = 1.25893e-05 * basePsdWattsHz;
396  break;
397  case 22:
398  case 23:
399  case 24:
400  (*psd) [i] = 3.16228e-05 * basePsdWattsHz;
401  break;
402  case 25:
403  (*psd) [i] = 0.000158489 * basePsdWattsHz;
404  break;
405  case 26:
406  (*psd) [i] = basePsdWattsHz;
407  break;
408  case 27:
409  (*psd) [i] = 7.49894e-05 * basePsdWattsHz;
410  break;
411  case 28:
412  case 29:
413  case 30:
414  (*psd) [i] = 2.37137e-05 * basePsdWattsHz;
415  break;
416  case 31:
417  case 32:
418  case 33:
419  (*psd) [i] = 1.14815e-05 * basePsdWattsHz;
420  break;
421  case 34:
422  case 35:
423  case 36:
424  (*psd) [i] = 7.49894e-06 * basePsdWattsHz;
425  break;
426  case 37:
427  case 38:
428  case 39:
429  (*psd) [i] = 5.62341e-06 * basePsdWattsHz;
430  break;
431  case 40:
432  case 41:
433  case 42:
434  (*psd) [i] = 4.21697e-06 * basePsdWattsHz;
435  break;
436  case 43:
437  case 44:
438  case 45:
439  (*psd) [i] = 3.16228e-06 * basePsdWattsHz;
440  break;
441  case 46:
442  case 47:
443  case 48:
444  (*psd) [i] = 1.99526e-06 * basePsdWattsHz;
445  break;
446  case 49:
447  case 50:
448  case 51:
449  (*psd) [i] = 1.25893e-06 * basePsdWattsHz;
450  break;
451  case 52:
452  case 53:
453  case 54:
454  (*psd) [i] = 8.41395e-07 * basePsdWattsHz;
455  break;
456  case 55:
457  case 56:
458  case 57:
459  (*psd) [i] = 6.30957e-07 * basePsdWattsHz;
460  break;
461  case 58:
462  case 59:
463  case 60:
464  (*psd) [i] = 5.88844e-07 * basePsdWattsHz;
465  break;
466  case 61:
467  case 62:
468  case 63:
469  (*psd) [i] = 5.62341e-07 * basePsdWattsHz;
470  break;
471  case 64:
472  case 65:
473  case 66:
474  (*psd) [i] = 5.30884e-07 * basePsdWattsHz;
475  break;
476  case 67:
477  case 68:
478  case 69:
479  (*psd) [i] = 5.01187e-07 * basePsdWattsHz;
480  break;
481  case 70:
482  case 71:
483  case 72:
484  (*psd) [i] = 5.30884e-07 * basePsdWattsHz;
485  break;
486  case 73:
487  case 74:
488  case 75:
489  (*psd) [i] = 7.49894e-07 * basePsdWattsHz;
490  break;
491  case 76:
492  case 77:
493  case 78:
494  (*psd) [i] = 1.77828e-06 * basePsdWattsHz;
495  break;
496  case 79:
497  (*psd) [i] = 5.62341e-06 * basePsdWattsHz;
498  break;
499  case 80:
500  (*psd) [i] = 0.000177828 * basePsdWattsHz;
501  break;
502  case 81:
503  (*psd) [i] = 4.21697e-06 * basePsdWattsHz;
504  break;
505  case 82:
506  case 83:
507  case 84:
508  (*psd) [i] = 3.16228e-06 * basePsdWattsHz;
509  break;
510  case 85:
511  case 86:
512  case 87:
513  (*psd) [i] = 3.16228e-06 * basePsdWattsHz;
514  break;
515  case 88:
516  case 89:
517  case 90:
518  (*psd) [i] = 4.73151e-06 * basePsdWattsHz;
519  break;
520  case 91:
521  case 92:
522  case 93:
523  (*psd) [i] = 7.49894e-06 * basePsdWattsHz;
524  break;
525  case 94:
526  (*psd) [i] = 7.49894e-05 * basePsdWattsHz;
527  break;
528  case 95:
529  (*psd) [i] = 0.1 * basePsdWattsHz;
530  break;
531  case 96:
532  (*psd) [i] = 7.49894e-05 * basePsdWattsHz;
533  break;
534  case 97:
535  case 98:
536  case 99:
537  case 100:
538  (*psd) [i] = 1.77828e-06 * basePsdWattsHz;
539  break;
540  }
541  }
542  break;
543  }
544  default:
545  {
546  NS_LOG_ERROR ("no valid TvType selected");
547  break;
548  }
549  }
550  m_txPsd = psd;
551 }
552 
555 {
556  NS_LOG_FUNCTION (this);
557  return m_txPsd;
558 }
559 
560 void
562 {
563  NS_LOG_FUNCTION (this);
564  NS_ASSERT (m_txPsd);
565  Ptr<SpectrumSignalParameters> signal = Create<SpectrumSignalParameters> ();
566  signal->duration = m_transmitDuration;
567  signal->psd = m_txPsd;
568  signal->txPhy = GetObject<SpectrumPhy> ();
569  signal->txAntenna = m_antenna;
570  m_channel->StartTx (signal);
571 }
572 
573 void
575 {
576  NS_LOG_FUNCTION (this);
577  if (!m_active)
578  {
579  NS_LOG_LOGIC ("starting TV transmitter");
580  m_active = true;
582  }
583 }
584 
585 void
587 {
588  NS_LOG_FUNCTION (this);
589  m_active = false;
590 }
591 
592 } // namespace ns3
593 
#define max(a, b)
Definition: 80211b.c:43
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Hold variables of type enum.
Definition: enum.h:55
Isotropic antenna model.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:47
Hold variables of type string.
Definition: string.h:41
AttributeValue implementation for Time.
Definition: nstime.h:1308
SpectrumPhy implementation that creates a customizable TV transmitter which transmits a PSD spectrum ...
Ptr< AntennaModel > m_antenna
Pointer to antenna model object.
Ptr< MobilityModel > GetMobility() const
Get the associated MobilityModel instance.
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
virtual void CreateTvPsd()
Creates power spectral density (PSD) spectrum of the TV transmitter and sets it for transmission.
double m_basePsd
Base power spectral density value (in dBm/Hz) of TV transmitter's signal.
Time m_transmitDuration
Length of time that TV transmitter will transmit for.
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
bool m_active
True if TV transmitter is transmitting.
Ptr< NetDevice > m_netDevice
Pointer to net device object.
virtual void Start()
Starts the TV Transmitter's transmission on the spectrum channel.
Ptr< const SpectrumModel > GetRxSpectrumModel() const
double m_channelBandwidth
Bandwidth (in Hz) of TV transmitter's signal.
double m_startFrequency
Start frequency (in Hz) of TV transmitter's signal.
enum TvType m_tvType
Type of TV transmitter.
Time m_startingTime
Timepoint after simulation begins that TV transmitter will begin transmitting.
virtual void Stop()
Stops the TV Transmitter's transmission on the spectrum channel.
virtual void SetupTx()
Sets up signal to be transmitted.
static TypeId GetTypeId(void)
Register this type.
Ptr< SpectrumValue > GetTxPsd() const
Get the power spectral density of the TV transmitter's signal.
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
Ptr< SpectrumChannel > GetChannel() const
Get the spectrum channel.
Ptr< SpectrumChannel > m_channel
Pointer to spectrum channel object.
Ptr< NetDevice > GetDevice() const
Get the associated NetDevice instance.
Ptr< SpectrumValue > m_txPsd
Pointer to power spectral density of TV transmitter's signal.
Ptr< Object > GetAntenna() const
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
Ptr< MobilityModel > m_mobility
Pointer to mobility model object.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#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
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 AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:205
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:227
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:1309
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:576
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< BandInfo > Bands
Container of BandInfo.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:162
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:176
static std::map< TvSpectrumModelId, Ptr< SpectrumModel > > g_tvSpectrumModelMap
Stores created spectrum models.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband
Used as key for map containing created spectrum models.
TvSpectrumModelId(double stFreq, double bwidth)
Constructor.
double startFrequency
Start frequency [Hz].
double bandwidth
Bandwidth [Hz].