27 #include "ns3/fatal-error.h"
28 #include "ns3/assert.h"
48 : m_centerFrequency (f),
71 NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << bandBandwidth << (uint16_t)guardBandwidth);
74 std::map<WifiSpectrumModelId, Ptr<SpectrumModel> >::iterator it = g_wifiSpectrumModelMap.find (key);
75 if (it != g_wifiSpectrumModelMap.end ())
82 double centerFrequencyHz = centerFrequency * 1e6;
83 double bandwidth = (channelWidth + (2 * guardBandwidth)) * 1e6;
85 uint32_t numBands =
static_cast<uint32_t
> ((bandwidth / bandBandwidth) + 0.5);
87 if (numBands % 2 == 0)
91 NS_LOG_DEBUG (
"Total bandwidth evenly divided by 312.5 KHz");
94 NS_ASSERT_MSG (numBands % 2 == 1,
"Number of bands should be odd");
97 double startingFrequencyHz = centerFrequencyHz - (numBands/2 * bandBandwidth) - bandBandwidth/2;
98 for (
size_t i = 0; i < numBands; i++)
101 double f = startingFrequencyHz + (i * bandBandwidth);
103 f += bandBandwidth/2;
105 f += bandBandwidth/2;
107 NS_LOG_DEBUG (
"creating band " << i <<
" (" << info.
fl <<
":" << info.
fc <<
":" << info.
fh <<
")");
108 bands.push_back (info);
110 ret = Create<SpectrumModel> (bands);
121 NS_LOG_FUNCTION (centerFrequency << txPowerW << (uint16_t)guardBandwidth);
122 uint8_t channelWidth = 22;
123 double bandBandwidth = 312500;
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);
131 double txPowerPerBand = txPowerW / nAllocatedBands;
134 if ((i >= (nGuardBands / 2)) && (i <= ((nGuardBands / 2) + nAllocatedBands - 1)))
136 *vit = txPowerPerBand / (bit->fh - bit->fl);
145 NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW << (uint16_t)guardBandwidth);
146 double bandBandwidth = 312500;
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);
151 double txPowerPerBand = 0;
156 switch (channelWidth)
164 txPowerPerBand = txPowerW / 52;
165 start1 = (nGuardBands / 2) + 6;
166 stop1 = start1 + 26 - 1;
168 stop2 = start2 + 26 - 1;
175 txPowerPerBand = txPowerW / 28;
176 start1 = (nGuardBands / 2) + 2;
177 stop1 = start1 + 14 - 1;
179 stop2 = start2 + 14 - 1;
186 txPowerPerBand = txPowerW / 16;
187 start1 = (nGuardBands / 2) + 2;
188 stop1 = start1 + 8 - 1;
190 stop2 = start2 + 8 - 1;
198 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
200 *vit = txPowerPerBand / (bit->fh - bit->fl);
207 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
" and " << start2 <<
"-" << stop2);
216 NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW << (uint16_t)guardBandwidth);
217 double bandBandwidth = 312500;
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);
224 double txPowerPerBand;
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)
265 txPowerPerBand = txPowerW / 56;
267 start1 = (nGuardBands / 2) + 4;
268 stop1 = start1 + 28 - 1;
270 stop2 = start2 + 28 - 1;
273 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
275 *vit = txPowerPerBand / (bit->fh - bit->fl);
282 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
283 " and " << start2 <<
"-" << stop2);
288 txPowerPerBand = txPowerW / 112;
292 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2) ||
293 (i >= start3 && i <= stop3) || (i >= start4 && i <= stop4))
295 *vit = txPowerPerBand / (bit->fh - bit->fl);
302 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
303 ", " << start2 <<
"-" << stop2 <<
304 ", " << start3 <<
"-" << stop3 <<
305 ", " << start4 <<
"-" << stop4);
310 txPowerPerBand = txPowerW / 224;
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))
319 *vit = txPowerPerBand / (bit->fh - bit->fl);
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);
338 txPowerPerBand = txPowerW / 448;
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))
351 *vit = txPowerPerBand / (bit->fh - bit->fl);
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);
384 NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << txPowerW << (uint16_t)guardBandwidth);
385 double bandBandwidth = 78125;
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);
392 double txPowerPerBand;
401 switch (channelWidth)
405 txPowerPerBand = txPowerW / 242;
410 start1 = (nGuardBands / 2) + 12;
411 stop1 = start1 + 121 - 1;
413 stop2 = start2 + 121 - 1;
416 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
418 *vit = txPowerPerBand / (bit->fh - bit->fl);
425 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
426 " and " << start2 <<
"-" << stop2);
430 txPowerPerBand = txPowerW / 484;
435 start1 = (nGuardBands / 2) + 12;
436 stop1 = start1 + 242 - 1;
438 stop2 = start2 + 242 - 1;
441 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
443 *vit = txPowerPerBand / (bit->fh - bit->fl);
450 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
451 " and " << start2 <<
"-" << stop2);
455 txPowerPerBand = txPowerW / 996;
460 start1 = (nGuardBands / 2) + 12;
461 stop1 = start1 + 498 - 1;
463 stop2 = start2 + 498 - 1;
466 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2))
468 *vit = txPowerPerBand / (bit->fh - bit->fl);
475 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
476 " and " << start2 <<
"-" << stop2);
480 txPowerPerBand = txPowerW / (2 * 996);
482 start1 = (nGuardBands / 2) + 12;
483 stop1 = start1 + 498 - 1;
485 stop2 = start2 + 498 - 1;
486 start3 = stop2 + (2 * 12);
487 stop3 = start3 + 498 - 1;
489 stop4 = start4 + 498 - 1;
492 if ((i >= start1 && i <= stop1) || (i >= start2 && i <= stop2) ||
493 (i >= start3 && i <= stop3) || (i >= start4 && i <= stop4))
495 *vit = txPowerPerBand / (bit->fh - bit->fl);
502 NS_LOG_DEBUG (
"Added signal power to subbands " << start1 <<
"-" << stop1 <<
503 ", " << start2 <<
"-" << stop2 <<
504 ", " << start3 <<
"-" << stop3 <<
505 ", " << start4 <<
"-" << stop4);
508 NS_FATAL_ERROR (
"ChannelWidth " << channelWidth <<
" unsupported");
530 const double kT_dBm_Hz = -174.0;
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;
536 (*noisePsd) = noisePowerSpectralDensity;
544 NS_LOG_FUNCTION (centerFrequency << (uint16_t)channelWidth << bandGranularity << (uint16_t)guardBandwidth);
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)
553 numBandsInFilter += 1;
555 NS_LOG_DEBUG (
"Num bands in filter: " << numBandsInFilter);
557 NS_ASSERT_MSG ((numBandsInFilter % 2 == 1) && (numBands % 2 == 1),
"Should have odd number of bands");
558 size_t startIndex = (numBands - numBandsInFilter) / 2;
561 for (
size_t i = startIndex; i < startIndex + numBandsInFilter; i++, vit++, bit++)
565 NS_LOG_DEBUG (
"Added subbands " << startIndex <<
" to " << startIndex + numBandsInFilter <<
" to filter");
588 for (
int i = -4; i < 13 + 7; i++)
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);
596 g_WifiSpectrumModel5Mhz = Create<SpectrumModel> (bands);
623 double txPowerDensity = txPower / 20e6;
628 (*txPsd)[channel - 1] = txPowerDensity * 1e-4;
629 (*txPsd)[
channel] = txPowerDensity * 1e-4;
630 (*txPsd)[channel + 1] = txPowerDensity * 0.0015849;
631 (*txPsd)[channel + 2] = txPowerDensity * 0.0015849;
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;
637 (*txPsd)[channel + 8] = txPowerDensity * 0.0015849;
638 (*txPsd)[channel + 9] = txPowerDensity * 1e-4;
639 (*txPsd)[channel + 10] = txPowerDensity * 1e-4;
653 (*rf)[channel + 3] = 1;
654 (*rf)[channel + 4] = 1;
655 (*rf)[channel + 5] = 1;
656 (*rf)[channel + 6] = 1;
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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
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)
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)
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...
virtual ~WifiSpectrumValue5MhzFactory()
Destructor.
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...
WifiSpectrumModel5MhzInitializer()
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.
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.