27 #include "ns3/fatal-error.h"
28 #include "ns3/assert.h"
42 : m_centerFrequency (f),
62 std::map<WifiSpectrumModelId, Ptr<SpectrumModel> >::iterator it = g_wifiSpectrumModelMap.find (key);
63 if (it != g_wifiSpectrumModelMap.end ())
70 double centerFrequencyHz = centerFrequency * 1e6;
72 double bandwidth = (channelWidth + 20) * 1e6;
74 double bandBandwidth = 312500;
76 uint32_t numBands =
static_cast<uint32_t
> (bandwidth / bandBandwidth + 0.5);
78 if (numBands % 2 == 0)
82 NS_LOG_DEBUG (
"Total bandwidth evenly divided by 312.5 KHz");
85 NS_ASSERT_MSG (numBands % 2 == 1,
"Number of bands should be odd");
88 double startingFrequencyHz = centerFrequencyHz - (numBands/2 * bandBandwidth) - bandBandwidth/2;
89 for (
size_t i = 0; i < numBands; i++)
92 double f = startingFrequencyHz + (i * bandBandwidth);
98 NS_LOG_DEBUG (
"creating band " << i <<
" (" << info.
fl <<
":" << info.
fc <<
":" << info.
fh <<
")");
99 bands.push_back (info);
101 ret = Create<SpectrumModel> (bands);
115 double txPowerPerBand;
116 switch (channelWidth)
124 txPowerPerBand = txPowerW / 56;
127 if ((i >=36 && i <=63) || (i >=65 && i <=92))
129 *vit = txPowerPerBand / (bit->fh - bit->fl);
132 NS_LOG_DEBUG (
"Added signal power to subbands 36-63 and 65-92");
140 txPowerPerBand = txPowerW / 112;
143 if ((i >=36 && i <=63) || (i >=65 && i <=92) || (i >=100 && i<=127) || (i >=129 && i<= 156))
145 *vit = txPowerPerBand / (bit->fh - bit->fl);
148 NS_LOG_DEBUG (
"Added signal power to subbands 36-63, 65-92, 100-127, and 129-156");
156 txPowerPerBand = txPowerW / 224;
159 if ((i >= 36 && i <= 63) || (i >= 65 && i <= 92) ||
160 (i >= 100 && i <= 127) || (i >= 129 && i <= 156) ||
161 (i >= 164 && i <= 191) || (i >= 193 && i <= 220) ||
162 (i >= 228 && i <= 255) || (i >= 257 && i <= 284))
164 *vit = txPowerPerBand / (bit->fh - bit->fl);
167 NS_LOG_DEBUG (
"Added signal power to subbands 36-63, 65-92, 100-127, 129-156, 164-191, 193-220, 228-255, 257-284");
175 txPowerPerBand = txPowerW / 448;
178 if ((i >= 36 && i <= 63) || (i >= 65 && i <= 92) ||
179 (i >= 100 && i <= 127) || (i >= 129 && i <= 156) ||
180 (i >= 164 && i <= 191) || (i >= 193 && i <= 220) ||
181 (i >= 228 && i <= 255) || (i >= 257 && i <= 284) ||
182 (i >= 292 && i <= 319) || (i >= 321 && i <= 348) ||
183 (i >= 356 && i <= 383) || (i >= 385 && i <= 412) ||
184 (i >= 420 && i <= 447) || (i >= 449 && i <= 476) ||
185 (i >= 484 && i <= 511) || (i >= 513 && i <= 540))
187 *vit = txPowerPerBand / (bit->fh - bit->fl);
190 NS_LOG_DEBUG (
"Added signal power to subbands 36-63, 65-92, 100-127, 129-156, 164-191, 193-220, 228-255, 257-284, 292-319, 321-348, 356-383, 385-412, 420-447, 449-476, 484-511, and 513-540");
195 NS_FATAL_ERROR (
"ChannelWidth " << channelWidth <<
" unsupported");
208 double txPowerPerBand;
209 switch (channelWidth)
217 txPowerPerBand = txPowerW / 52;
220 if ((i >=38 && i <=63) || (i >=65 && i <=90))
222 *vit = txPowerPerBand / (bit->fh - bit->fl);
229 NS_LOG_DEBUG (
"Added signal power to subbands 38-63 and 65-90");
239 txPowerPerBand = txPowerW / 28;
242 if ((i >=34 && i <=47) || (i >=49 && i <=62))
244 *vit = txPowerPerBand / (bit->fh - bit->fl);
251 NS_LOG_DEBUG (
"Added signal power to subbands 34-47 and 49-62");
261 txPowerPerBand = txPowerW / 16;
264 if ((i >=32 && i <=39) || (i >=41 && i <=48))
266 *vit = txPowerPerBand / (bit->fh - bit->fl);
273 NS_LOG_DEBUG (
"Added signal power to subbands 32-39 and 41-48");
278 NS_FATAL_ERROR (
"ChannelWidth " << channelWidth <<
" unsupported");
289 uint32_t channelWidth = 22;
293 double txPowerPerBand;
296 txPowerPerBand = txPowerW / 71;
299 if (i >=32 && i <=102)
301 *vit = txPowerPerBand / (bit->fh - bit->fl);
321 const double kT_dBm_Hz = -174.0;
322 double kT_W_Hz = std::pow (10.0, (kT_dBm_Hz - 30) / 10.0);
323 double noiseFigureLinear = std::pow (10.0, noiseFigureDb / 10.0);
324 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
327 (*noisePsd) = noisePowerSpectralDensity;
340 uint32_t bandBandwidth =
static_cast<uint32_t
> (((bit->fh - bit->fl) + 0.5));
342 size_t numBandsInFilter =
static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
343 if (channelWidth % bandBandwidth != 0)
345 numBandsInFilter += 1;
347 NS_LOG_DEBUG (
"Num bands in filter: " << numBandsInFilter);
349 NS_ASSERT_MSG ((numBandsInFilter % 2 == 1) && (numBands % 2 == 1),
"Should have odd number of bands");
350 size_t startIndex = (numBands - numBandsInFilter) / 2;
353 for (
size_t i = startIndex; i < startIndex + numBandsInFilter; i++, vit++, bit++)
357 NS_LOG_DEBUG (
"Added subbands " << startIndex <<
" to " << startIndex + numBandsInFilter <<
" to filter");
380 for (
int i = -4; i < 13 + 7; i++)
383 bi.
fl = 2407.0e6 + i * 5.0e6;
384 bi.
fh = 2407.0e6 + (i + 1) * 5.0e6;
385 bi.
fc = (bi.
fl + bi.
fh) / 2;
386 bands.push_back (bi);
388 g_WifiSpectrumModel5Mhz = Create<SpectrumModel> (bands);
415 double txPowerDensity = txPower / 20e6;
420 (*txPsd)[channel - 1] = txPowerDensity * 1e-4;
421 (*txPsd)[
channel] = txPowerDensity * 1e-4;
422 (*txPsd)[channel + 1] = txPowerDensity * 0.0015849;
423 (*txPsd)[channel + 2] = txPowerDensity * 0.0015849;
424 (*txPsd)[channel + 3] = txPowerDensity;
425 (*txPsd)[channel + 4] = txPowerDensity;
426 (*txPsd)[channel + 5] = txPowerDensity;
427 (*txPsd)[channel + 6] = txPowerDensity;
428 (*txPsd)[channel + 7] = txPowerDensity * 0.0015849;
429 (*txPsd)[channel + 8] = txPowerDensity * 0.0015849;
430 (*txPsd)[channel + 9] = txPowerDensity * 1e-4;
431 (*txPsd)[channel + 10] = txPowerDensity * 1e-4;
445 (*rf)[channel + 3] = 1;
446 (*rf)[channel + 4] = 1;
447 (*rf)[channel + 5] = 1;
448 (*rf)[channel + 6] = 1;
static std::map< WifiSpectrumModelId, Ptr< SpectrumModel > > g_wifiSpectrumModelMap
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t centerFrequency, uint32_t channelWidth)
Return a SpectrumModel instance corresponding to the center frequency and channel width...
#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)
#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 > CreateHtOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint32_t channelWidth, double txPowerW)
Create a transmit power spectral density corresponding to OFDM High Throughput (HT) (802...
std::vector< BandInfo > Bands
Container of BandInfo.
static Ptr< SpectrumValue > CreateDsssTxPowerSpectralDensity(uint32_t centerFrequency, double txPowerW)
Create a transmit power spectral density corresponding to DSSS.
uint32_t m_centerFrequency
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
Creates a SpectrumValue instance that represents the TX Power Spectral Density of a wifi device corre...
SpectrumModelUid_t GetUid() const
Ptr< const SpectrumModel > GetSpectrumModel() const
double fc
center frequency
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
static Ptr< SpectrumValue > CreateRfFilter(uint32_t centerFrequency, uint32_t channelWidth)
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Bands::const_iterator ConstBandsBegin() const
double f(double x, void *params)
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.
static Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t centerFrequency, uint32_t channelWidth, double noiseFigure)
virtual Ptr< SpectrumValue > CreateRfFilter(uint32_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, uint32_t channelWidth, double txPowerW)
Create a transmit power spectral density corresponding to OFDM (802.11a/g).
#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.
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.
double fh
upper limit of subband
static Ptr< SpectrumModel > g_WifiSpectrumModel5Mhz
The building block of a SpectrumModel.
WifiSpectrumModelId(uint32_t f, uint32_t w)