A Discrete-Event Network Simulator
API
wifi-spectrum-value-helper.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  * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Nicola Baldo <nbaldo@cttc.es>
20  * Giuseppe Piro <g.piro@poliba.it>
21  */
22 
23 #include <map>
24 #include <cmath>
26 #include "ns3/log.h"
27 #include "ns3/fatal-error.h"
28 #include "ns3/assert.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("WifiSpectrumValueHelper");
33 
36 {
42  WifiSpectrumModelId (uint32_t f, uint8_t w);
43  uint32_t m_centerFrequency;
44  uint8_t m_channelWidth;
45 };
46 
48  : m_centerFrequency (f),
49  m_channelWidth (w)
50 {
51  NS_LOG_FUNCTION (this << f << (uint16_t)w);
52 }
53 
60 bool
62 {
64 }
65 
66 static std::map<WifiSpectrumModelId, Ptr<SpectrumModel> > g_wifiSpectrumModelMap;
67 
69 WifiSpectrumValueHelper::GetSpectrumModel (uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, uint8_t guardBandwidth)
70 {
71  NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << bandBandwidth << (uint16_t)guardBandwidth);
73  WifiSpectrumModelId key (centerFrequency, channelWidth);
74  std::map<WifiSpectrumModelId, Ptr<SpectrumModel> >::iterator it = g_wifiSpectrumModelMap.find (key);
75  if (it != g_wifiSpectrumModelMap.end ())
76  {
77  ret = it->second;
78  }
79  else
80  {
81  Bands bands;
82  double centerFrequencyHz = centerFrequency * 1e6;
83  double bandwidth = (channelWidth + (2 * guardBandwidth)) * 1e6;
84  // For OFDM, the center subcarrier is null (at center frequency)
85  uint32_t numBands = static_cast<uint32_t> ((bandwidth / bandBandwidth) + 0.5);
86  NS_ASSERT (numBands > 0);
87  if (numBands % 2 == 0)
88  {
89  // round up to the nearest odd number of subbands so that bands
90  // are symmetric around center frequency
91  NS_LOG_DEBUG ("Total bandwidth evenly divided by 312.5 KHz");
92  numBands += 1;
93  }
94  NS_ASSERT_MSG (numBands % 2 == 1, "Number of bands should be odd");
95  // lay down numBands/2 bands symmetrically around center frequency
96  // and place an additional band at center frequency
97  double startingFrequencyHz = centerFrequencyHz - (numBands/2 * bandBandwidth) - bandBandwidth/2;
98  for (size_t i = 0; i < numBands; i++)
99  {
100  BandInfo info;
101  double f = startingFrequencyHz + (i * bandBandwidth);
102  info.fl = f;
103  f += bandBandwidth/2;
104  info.fc = f;
105  f += bandBandwidth/2;
106  info.fh = f;
107  NS_LOG_DEBUG ("creating band " << i << " (" << info.fl << ":" << info.fc << ":" << info.fh << ")");
108  bands.push_back (info);
109  }
110  ret = Create<SpectrumModel> (bands);
111  g_wifiSpectrumModelMap.insert (std::pair<WifiSpectrumModelId, Ptr<SpectrumModel> > (key, ret));
112  }
113  NS_LOG_LOGIC ("returning SpectrumModel::GetUid () == " << ret->GetUid ());
114  return ret;
115 }
116 
117 // Power allocated to 71 center subbands out of 135 total subbands in the band
119 WifiSpectrumValueHelper::CreateDsssTxPowerSpectralDensity (uint32_t centerFrequency, double txPowerW, uint8_t guardBandwidth)
120 {
121  NS_LOG_FUNCTION (centerFrequency << txPowerW << (uint16_t)guardBandwidth);
122  uint8_t channelWidth = 22; // DSSS channels are 22 MHz wide
123  double bandBandwidth = 312500;
124  Ptr<SpectrumValue> c = Create<SpectrumValue> (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth));
125  Values::iterator vit = c->ValuesBegin ();
126  Bands::const_iterator bit = c->ConstBandsBegin ();
127  uint32_t nGuardBands = static_cast<uint32_t>(((2 * guardBandwidth * 1e6) / bandBandwidth) + 0.5);
128  uint32_t nAllocatedBands = static_cast<uint32_t>(((channelWidth * 1e6) / bandBandwidth) + 0.5);
129  NS_ASSERT (c->GetSpectrumModel ()->GetNumBands () == (nAllocatedBands + nGuardBands + 1));
130  // Evenly spread power across 22 MHz
131  double txPowerPerBand = txPowerW / nAllocatedBands;
132  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
133  {
134  if ((i >= (nGuardBands / 2)) && (i <= ((nGuardBands / 2) + nAllocatedBands - 1)))
135  {
136  *vit = txPowerPerBand / (bit->fh - bit->fl);
137  }
138  }
139  return c;
140 }
141 
143 WifiSpectrumValueHelper::CreateOfdmTxPowerSpectralDensity (uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
144 {
145  NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW << (uint16_t)guardBandwidth);
146  double bandBandwidth = 312500;
147  Ptr<SpectrumValue> c = Create<SpectrumValue> (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth));
148  uint32_t nGuardBands = static_cast<uint32_t>(((2 * guardBandwidth * 1e6) / bandBandwidth) + 0.5);
149  uint32_t nAllocatedBands = static_cast<uint32_t>(((channelWidth * 1e6) / bandBandwidth) + 0.5);
150  NS_ASSERT_MSG (c->GetSpectrumModel ()->GetNumBands () == (nAllocatedBands + nGuardBands + 1), "Unexpected number of bands " << c->GetSpectrumModel ()->GetNumBands ());
151  double txPowerPerBand = 0;
152  uint32_t start1 = 0;
153  uint32_t stop1 = 0;
154  uint32_t start2 = 0;
155  uint32_t stop2 = 0;
156  switch (channelWidth)
157  {
158  case 20:
159  default:
160  // 52 subcarriers (48 data + 4 pilot)
161  // skip guard band and 6 subbands, then place power in 26 subbands, then
162  // skip the center subband, then place power in 26 subbands, then skip
163  // the final 6 subbands and the guard band.
164  txPowerPerBand = txPowerW / 52;
165  start1 = (nGuardBands / 2) + 6;
166  stop1 = start1 + 26 - 1;
167  start2 = stop1 + 2;
168  stop2 = start2 + 26 - 1;
169  break;
170  case 10:
171  // 28 subcarriers (24 data + 4 pilot)
172  // skip guard band and 2 subbands, then place power in 14 subbands, then
173  // skip the center subband, then place power in 14 subbands, then skip
174  // the final 2 subbands and the guard band.
175  txPowerPerBand = txPowerW / 28;
176  start1 = (nGuardBands / 2) + 2;
177  stop1 = start1 + 14 - 1;
178  start2 = stop1 + 2;
179  stop2 = start2 + 14 - 1;
180  break;
181  case 5:
182  // 16 subcarriers (12 data + 4 pilot)
183  // skip guard band and 2 subbands, then place power in 8 subbands, then
184  // skip the center subband, then place power in 8 subbands, then skip
185  // the final 2 subbands and the guard.
186  txPowerPerBand = txPowerW / 16;
187  start1 = (nGuardBands / 2) + 2;
188  stop1 = start1 + 8 - 1;
189  start2 = stop1 + 2;
190  stop2 = start2 + 8 - 1;
191  break;
192  }
193  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
194  Values::iterator vit = c->ValuesBegin ();
195  Bands::const_iterator bit = c->ConstBandsBegin ();
196  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
197  {
198  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
199  {
200  *vit = txPowerPerBand / (bit->fh - bit->fl);
201  }
202  else
203  {
204  *vit = 0;
205  }
206  }
207  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 << " and " << start2 << "-" << stop2);
208  NS_LOG_DEBUG ("Integrated power " << Integral (*c));
209  NS_ASSERT_MSG (std::abs (txPowerW - Integral (*c)) < 1e-6, "Power allocation failed");
210  return c;
211 }
212 
214 WifiSpectrumValueHelper::CreateHtOfdmTxPowerSpectralDensity (uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
215 {
216  NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW << (uint16_t)guardBandwidth);
217  double bandBandwidth = 312500;
218  Ptr<SpectrumValue> c = Create<SpectrumValue> (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth));
219  Values::iterator vit = c->ValuesBegin ();
220  Bands::const_iterator bit = c->ConstBandsBegin ();
221  uint32_t nGuardBands = static_cast<uint32_t>(((2 * guardBandwidth * 1e6) / bandBandwidth) + 0.5);
222  uint32_t nAllocatedBands = static_cast<uint32_t>(((channelWidth * 1e6) / bandBandwidth) + 0.5);
223  NS_ASSERT_MSG (c->GetSpectrumModel ()->GetNumBands () == (nAllocatedBands + nGuardBands + 1), "Unexpected number of bands " << c->GetSpectrumModel ()->GetNumBands ());
224  double txPowerPerBand;
225  // skip the guard band and 4 subbands, then place power in 28 subbands, then
226  // skip the center subband, then place power in 28 subbands, then skip
227  // the final 4 subbands and the guard band.
228  // Repeat for each 20 MHz band.
229  uint32_t start1 = (nGuardBands / 2) + 4;
230  uint32_t stop1 = start1 + 28 - 1;
231  uint32_t start2 = stop1 + 2;
232  uint32_t stop2 = start2 + 28 - 1;
233  uint32_t start3 = stop2 + (2 * 4);
234  uint32_t stop3 = start3 + 28 - 1;
235  uint32_t start4 = stop3 + 2;
236  uint32_t stop4 = start4 + 28 - 1;
237  uint32_t start5 = stop4 + (2 * 4);
238  uint32_t stop5 = start5 + 28 - 1;
239  uint32_t start6 = stop5 + 2;
240  uint32_t stop6 = start6 + 28 - 1;
241  uint32_t start7 = stop6 + (2 * 4);
242  uint32_t stop7 = start7 + 28 - 1;
243  uint32_t start8 = stop7 + 2;
244  uint32_t stop8 = start8 + 28 - 1;
245  uint32_t start9 = stop8 + (2 * 4);
246  uint32_t stop9 = start9 + 28 - 1;
247  uint32_t start10 = stop9 + 2;
248  uint32_t stop10 = start10 + 28 - 1;
249  uint32_t start11 = stop10 + (2 * 4);
250  uint32_t stop11 = start11 + 28 - 1;
251  uint32_t start12 = stop11 + 2;
252  uint32_t stop12 = start12 + 28 - 1;
253  uint32_t start13 = stop12 + (2 * 4);
254  uint32_t stop13 = start13 + 28 - 1;
255  uint32_t start14 = stop13 + 2;
256  uint32_t stop14 = start14 + 28 - 1;
257  uint32_t start15 = stop14 + (2 * 4);
258  uint32_t stop15 = start15 + 28 - 1;
259  uint32_t start16 = stop15 + 2;
260  uint32_t stop16 = start16 + 28 - 1;
261  switch (channelWidth)
262  {
263  case 20:
264  // 56 subcarriers (52 data + 4 pilot)
265  txPowerPerBand = txPowerW / 56;
266  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
267  start1 = (nGuardBands / 2) + 4;
268  stop1 = start1 + 28 - 1;
269  start2 = stop1 + 2;
270  stop2 = start2 + 28 - 1;
271  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
272  {
273  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
274  {
275  *vit = txPowerPerBand / (bit->fh - bit->fl);
276  }
277  else
278  {
279  *vit = 0;
280  }
281  }
282  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
283  " and " << start2 << "-" << stop2);
284  break;
285  case 40:
286  // 112 subcarriers (104 data + 8 pilot)
287  // possible alternative: 114 subcarriers (108 data + 6 pilot)
288  txPowerPerBand = txPowerW / 112;
289  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
290  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
291  {
292  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2) ||
293  (i >= start3 && i <= stop3) || (i >= start4 && i <= stop4))
294  {
295  *vit = txPowerPerBand / (bit->fh - bit->fl);
296  }
297  else
298  {
299  *vit = 0;
300  }
301  }
302  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
303  ", " << start2 << "-" << stop2 <<
304  ", " << start3 << "-" << stop3 <<
305  ", " << start4 << "-" << stop4);
306  break;
307  case 80:
308  // 224 subcarriers (208 data + 16 pilot)
309  // possible alternative: 242 subcarriers (234 data + 8 pilot)
310  txPowerPerBand = txPowerW / 224;
311  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
312  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
313  {
314  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2) ||
315  (i >= start3 && i <= stop3) || (i >= start4 && i <= stop4) ||
316  (i >= start5 && i <= stop5) || (i >= start6 && i <= stop6) ||
317  (i >= start7 && i <= stop7) || (i >= start8 && i <= stop8))
318  {
319  *vit = txPowerPerBand / (bit->fh - bit->fl);
320  }
321  else
322  {
323  *vit = 0;
324  }
325  }
326  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
327  ", " << start2 << "-" << stop2 <<
328  ", " << start3 << "-" << stop3 <<
329  ", " << start4 << "-" << stop4 <<
330  ", " << start5 << "-" << stop5 <<
331  ", " << start6 << "-" << stop6 <<
332  ", " << start7 << "-" << stop7 <<
333  ", " << start8 << "-" << stop8);
334  break;
335  case 160:
336  // 448 subcarriers (416 data + 32 pilot)
337  // possible alternative: 484 subcarriers (468 data + 16 pilot)
338  txPowerPerBand = txPowerW / 448;
339  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
340  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
341  {
342  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2) ||
343  (i >= start3 && i <= stop3) || (i >= start4 && i <= stop4) ||
344  (i >= start5 && i <= stop5) || (i >= start6 && i <= stop6) ||
345  (i >= start7 && i <= stop7) || (i >= start8 && i <= stop8) ||
346  (i >= start9 && i <= stop9) || (i >= start10 && i <= stop10) ||
347  (i >= start11 && i <= stop11) || (i >= start12 && i <= stop12) ||
348  (i >= start13 && i <= stop13) || (i >= start14 && i <= stop14) ||
349  (i >= start15 && i <= stop15) || (i >= start16 && i <= stop16))
350  {
351  *vit = txPowerPerBand / (bit->fh - bit->fl);
352  }
353  else
354  {
355  *vit = 0;
356  }
357  }
358  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
359  ", " << start2 << "-" << stop2 <<
360  ", " << start3 << "-" << stop3 <<
361  ", " << start4 << "-" << stop4 <<
362  ", " << start5 << "-" << stop5 <<
363  ", " << start6 << "-" << stop6 <<
364  ", " << start7 << "-" << stop7 <<
365  ", " << start8 << "-" << stop8 <<
366  ", " << start9 << "-" << stop9 <<
367  ", " << start10 << "-" << stop10 <<
368  ", " << start11 << "-" << stop11 <<
369  ", " << start12 << "-" << stop12 <<
370  ", " << start13 << "-" << stop13 <<
371  ", " << start14 << "-" << stop14 <<
372  ", " << start15 << "-" << stop15 <<
373  ", " << start16 << "-" << stop16);
374  break;
375  }
376  NS_LOG_DEBUG ("Integrated power " << Integral (*c));
377  NS_ASSERT_MSG (std::abs (txPowerW - Integral (*c)) < 1e-6, "Power allocation failed");
378  return c;
379 }
380 
382 WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
383 {
384  NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW << (uint16_t)guardBandwidth);
385  double bandBandwidth = 78125;
386  Ptr<SpectrumValue> c = Create<SpectrumValue> (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth));
387  Values::iterator vit = c->ValuesBegin ();
388  Bands::const_iterator bit = c->ConstBandsBegin ();
389  uint32_t nGuardBands = static_cast<uint32_t>(((2 * guardBandwidth * 1e6) / bandBandwidth) + 0.5);
390  uint32_t nAllocatedBands = static_cast<uint32_t>(((channelWidth * 1e6) / bandBandwidth) + 0.5);
391  NS_ASSERT_MSG (c->GetSpectrumModel ()->GetNumBands () == (nAllocatedBands + nGuardBands + 1), "Unexpected number of bands " << c->GetSpectrumModel ()->GetNumBands ());
392  double txPowerPerBand;
393  uint32_t start1;
394  uint32_t stop1;
395  uint32_t start2;
396  uint32_t stop2;
397  uint32_t start3;
398  uint32_t stop3;
399  uint32_t start4;
400  uint32_t stop4;
401  switch (channelWidth)
402  {
403  case 20:
404  // 242 subcarriers (234 data + 8 pilot)
405  txPowerPerBand = txPowerW / 242;
406  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
407  // skip the guard band and 11 subbands, then place power in 121 subbands, then
408  // skip 3 DC, then place power in 121 subbands, then skip
409  // the final 11 subbands and the guard band.
410  start1 = (nGuardBands / 2) + 12;
411  stop1 = start1 + 121 - 1;
412  start2 = stop1 + 4;
413  stop2 = start2 + 121 - 1;
414  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
415  {
416  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
417  {
418  *vit = txPowerPerBand / (bit->fh - bit->fl);
419  }
420  else
421  {
422  *vit = 0;
423  }
424  }
425  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
426  " and " << start2 << "-" << stop2);
427  break;
428  case 40:
429  // 484 subcarriers (468 data + 16 pilot)
430  txPowerPerBand = txPowerW / 484;
431  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
432  // skip the guard band and 11 subbands, then place power in 242 subbands, then
433  // skip 5 DC, then place power in 242 subbands, then skip
434  // the final 11 subbands and the guard band.
435  start1 = (nGuardBands / 2) + 12;
436  stop1 = start1 + 242 - 1;
437  start2 = stop1 + 6;
438  stop2 = start2 + 242 - 1;
439  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
440  {
441  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
442  {
443  *vit = txPowerPerBand / (bit->fh - bit->fl);
444  }
445  else
446  {
447  *vit = 0;
448  }
449  }
450  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
451  " and " << start2 << "-" << stop2);
452  break;
453  case 80:
454  // 996 subcarriers (980 data + 16 pilot)
455  txPowerPerBand = txPowerW / 996;
456  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
457  // skip the guard band and 11 subbands, then place power in 498 subbands, then
458  // skip 5 DC, then place power in 498 subbands, then skip
459  // the final 11 subbands and the guard band.
460  start1 = (nGuardBands / 2) + 12;
461  stop1 = start1 + 498 - 1;
462  start2 = stop1 + 6;
463  stop2 = start2 + 498 - 1;
464  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
465  {
466  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
467  {
468  *vit = txPowerPerBand / (bit->fh - bit->fl);
469  }
470  else
471  {
472  *vit = 0;
473  }
474  }
475  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
476  " and " << start2 << "-" << stop2);
477  break;
478  case 160:
479  // 2 x 996 subcarriers (2 x 80 MHZ bands)
480  txPowerPerBand = txPowerW / (2 * 996);
481  NS_LOG_DEBUG ("Power per band " << txPowerPerBand);
482  start1 = (nGuardBands / 2) + 12;
483  stop1 = start1 + 498 - 1;
484  start2 = stop1 + 6;
485  stop2 = start2 + 498 - 1;
486  start3 = stop2 + (2 * 12);
487  stop3 = start3 + 498 - 1;
488  start4 = stop3 + 6;
489  stop4 = start4 + 498 - 1;
490  for (size_t i = 0; i < c->GetSpectrumModel ()->GetNumBands (); i++, vit++, bit++)
491  {
492  if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2) ||
493  (i >= start3 && i <= stop3) || (i >= start4 && i <= stop4))
494  {
495  *vit = txPowerPerBand / (bit->fh - bit->fl);
496  }
497  else
498  {
499  *vit = 0;
500  }
501  }
502  NS_LOG_DEBUG ("Added signal power to subbands " << start1 << "-" << stop1 <<
503  ", " << start2 << "-" << stop2 <<
504  ", " << start3 << "-" << stop3 <<
505  ", " << start4 << "-" << stop4);
506  break;
507  default:
508  NS_FATAL_ERROR ("ChannelWidth " << channelWidth << " unsupported");
509  break;
510  }
511  NS_LOG_DEBUG ("Integrated power " << Integral (*c));
512  NS_ASSERT_MSG (std::abs (txPowerW - Integral (*c)) < 1e-6, "Power allocation failed");
513  return c;
514 }
515 
517 WifiSpectrumValueHelper::CreateNoisePowerSpectralDensity (uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, double noiseFigure, uint8_t guardBandwidth)
518 {
519  Ptr<SpectrumModel> model = GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth);
520  return CreateNoisePowerSpectralDensity (noiseFigure, model);
521 }
522 
525 {
526  NS_LOG_FUNCTION (noiseFigureDb << spectrumModel);
527 
528  // see "LTE - From theory to practice"
529  // Section 22.4.4.2 Thermal Noise and Receiver Noise Figure
530  const double kT_dBm_Hz = -174.0; // dBm/Hz
531  double kT_W_Hz = std::pow (10.0, (kT_dBm_Hz - 30) / 10.0);
532  double noiseFigureLinear = std::pow (10.0, noiseFigureDb / 10.0);
533  double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
534 
535  Ptr<SpectrumValue> noisePsd = Create <SpectrumValue> (spectrumModel);
536  (*noisePsd) = noisePowerSpectralDensity;
537  NS_LOG_DEBUG ("NoisePowerSpectralDensity has integrated power of " << Integral (*noisePsd));
538  return noisePsd;
539 }
540 
542 WifiSpectrumValueHelper::CreateRfFilter (uint32_t centerFrequency, uint8_t channelWidth, double bandGranularity, uint8_t guardBandwidth)
543 {
544  NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << bandGranularity << (uint16_t)guardBandwidth);
545  Ptr<SpectrumValue> c = Create <SpectrumValue> (GetSpectrumModel (centerFrequency, channelWidth, bandGranularity, guardBandwidth));
546  size_t numBands = c->GetSpectrumModel ()->GetNumBands ();
547  Bands::const_iterator bit = c->ConstBandsBegin ();
548  Values::iterator vit = c->ValuesBegin ();
549  uint32_t bandBandwidth = static_cast<uint32_t> (bandGranularity);
550  size_t numBandsInFilter = static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
551  if (channelWidth % bandBandwidth != 0)
552  {
553  numBandsInFilter += 1;
554  }
555  NS_LOG_DEBUG ("Num bands in filter: " << numBandsInFilter);
556  // Set the value of the filter to 1 for the center-most numBandsInFilter
557  NS_ASSERT_MSG ((numBandsInFilter % 2 == 1) && (numBands % 2 == 1), "Should have odd number of bands");
558  size_t startIndex = (numBands - numBandsInFilter) / 2;
559  vit += startIndex;
560  bit += startIndex;
561  for (size_t i = startIndex; i < startIndex + numBandsInFilter; i++, vit++, bit++)
562  {
563  *vit = 1;
564  }
565  NS_LOG_DEBUG ("Added subbands " << startIndex << " to " << startIndex + numBandsInFilter << " to filter");
566  return c;
567 }
568 
570 
572 {
573 }
574 
576 {
577 }
578 
583 {
584 public:
586  {
587  Bands bands;
588  for (int i = -4; i < 13 + 7; i++)
589  {
590  BandInfo bi;
591  bi.fl = 2407.0e6 + i * 5.0e6;
592  bi.fh = 2407.0e6 + (i + 1) * 5.0e6;
593  bi.fc = (bi.fl + bi.fh) / 2;
594  bands.push_back (bi);
595  }
596  g_WifiSpectrumModel5Mhz = Create<SpectrumModel> (bands);
597  }
599 
600 
601 
602 Ptr<SpectrumValue>
604 {
605  Ptr<SpectrumValue> c = Create <SpectrumValue> (g_WifiSpectrumModel5Mhz);
606  (*c) = v;
607  return c;
608 }
609 
610 
613 {
614  Ptr<SpectrumValue> txPsd = Create <SpectrumValue> (g_WifiSpectrumModel5Mhz);
615 
616  // since the spectrum model has a resolution of 5 MHz, we model
617  // the transmitted signal with a constant density over a 20MHz
618  // bandwidth centered on the center frequency of the channel. The
619  // transmission power outside the transmission power density is
620  // calculated considering the transmit spectrum mask, see IEEE
621  // Std. 802.11-2007, Annex I
622 
623  double txPowerDensity = txPower / 20e6;
624 
625  NS_ASSERT (channel >= 1);
626  NS_ASSERT (channel <= 13);
627 
628  (*txPsd)[channel - 1] = txPowerDensity * 1e-4; // -40dB
629  (*txPsd)[channel] = txPowerDensity * 1e-4; // -40dB
630  (*txPsd)[channel + 1] = txPowerDensity * 0.0015849; // -28dB
631  (*txPsd)[channel + 2] = txPowerDensity * 0.0015849; // -28dB
632  (*txPsd)[channel + 3] = txPowerDensity;
633  (*txPsd)[channel + 4] = txPowerDensity;
634  (*txPsd)[channel + 5] = txPowerDensity;
635  (*txPsd)[channel + 6] = txPowerDensity;
636  (*txPsd)[channel + 7] = txPowerDensity * 0.0015849; // -28dB
637  (*txPsd)[channel + 8] = txPowerDensity * 0.0015849; // -28dB
638  (*txPsd)[channel + 9] = txPowerDensity * 1e-4; // -40dB
639  (*txPsd)[channel + 10] = txPowerDensity * 1e-4; // -40dB
640 
641  return txPsd;
642 }
643 
644 
647 {
648  Ptr<SpectrumValue> rf = Create <SpectrumValue> (g_WifiSpectrumModel5Mhz);
649 
650  NS_ASSERT (channel >= 1);
651  NS_ASSERT (channel <= 13);
652 
653  (*rf)[channel + 3] = 1;
654  (*rf)[channel + 4] = 1;
655  (*rf)[channel + 5] = 1;
656  (*rf)[channel + 6] = 1;
657 
658  return rf;
659 }
660 
661 
662 } // namespace ns3
tuple channel
Definition: third.py:85
static Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, double noiseFigure, uint8_t guardBandwidth)
Create a power spectral density corresponding to the noise.
static std::map< WifiSpectrumModelId, Ptr< SpectrumModel > > g_wifiSpectrumModelMap
static initializer for the class
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
size_t GetNumBands() const
static class ns3::WifiSpectrumModel5MhzInitializer g_WifiSpectrumModel5MhzInitializerInstance
initialization instance for WifiSpectrumModel5Mhz
double Integral(const SpectrumValue &arg)
static Ptr< SpectrumValue > CreateDsssTxPowerSpectralDensity(uint32_t centerFrequency, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to DSSS.
#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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
static Ptr< SpectrumValue > CreateRfFilter(uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, uint8_t guardBandwidth)
Create a spectral density corresponding to the RF filter.
std::vector< BandInfo > Bands
Container of BandInfo.
WifiSpectrumModelId(uint32_t f, uint8_t w)
Constructor.
static Ptr< SpectrumValue > CreateHeOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to OFDM High Efficiency (HE) (802...
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:153
uint32_t m_centerFrequency
center frequency
static Ptr< SpectrumValue > CreateHtOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to OFDM High Throughput (HT) (802...
SpectrumModelUid_t GetUid() const
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t centerFrequency, uint8_t channelWidth, double bandBandwidth, uint8_t guardBandwidth)
Return a SpectrumModel instance corresponding to the center frequency and channel width...
Ptr< const SpectrumModel > GetSpectrumModel() const
double fc
center frequency
Bands::const_iterator ConstBandsBegin() const
double f(double x, void *params)
Definition: 80211b.c:72
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint8_t channel)
Creates a SpectrumValue instance that represents the TX Power Spectral Density of a wifi device corre...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double fl
lower limit of subband
virtual Ptr< SpectrumValue > CreateConstant(double psd)
Creates a SpectrumValue instance with a constant value for all frequencies.
Wifi Spectrum Model structure.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
virtual ~WifiSpectrumValueHelper()
Destructor.
uint8_t m_channelWidth
channel width
Values::iterator ValuesBegin()
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Static class to initialize the values for the 2.4 GHz Wi-Fi spectrum model.
virtual Ptr< SpectrumValue > CreateRfFilter(uint8_t channel)
Creates a SpectrumValue instance which represents the frequency response of the RF filter which is us...
static Ptr< SpectrumValue > CreateOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint8_t channelWidth, double txPowerW, uint8_t guardBandwidth)
Create a transmit power spectral density corresponding to OFDM (802.11a/g).
double fh
upper limit of subband
static Ptr< SpectrumModel > g_WifiSpectrumModel5Mhz
static initializer for the class
The building block of a SpectrumModel.