diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 3fd0716ff..a2d052372 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -482,4 +482,33 @@ SpectrumWifiPhy::GetBand (uint16_t bandWidth, uint8_t bandIndex) return band; } +WifiSpectrumBand +SpectrumWifiPhy::ConvertHeRuIndices (uint16_t channelWidth, HeRu::SubcarrierRange range) const +{ + WifiSpectrumBand convertedIndices; + uint32_t nGuardBands = static_cast (((2 * GetGuardBandwidth (channelWidth) * 1e6) / GetBandBandwidth ()) + 0.5); + uint32_t centerFrequencyIndex = 0; + switch (channelWidth) + { + case 20: + centerFrequencyIndex = (nGuardBands / 2) + 6 + 122; + break; + case 40: + centerFrequencyIndex = (nGuardBands / 2) + 12 + 244; + break; + case 80: + centerFrequencyIndex = (nGuardBands / 2) + 12 + 500; + break; + case 160: + centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012; + break; + default: + NS_FATAL_ERROR ("ChannelWidth " << channelWidth << " unsupported"); + break; + } + convertedIndices.first = centerFrequencyIndex + range.first; + convertedIndices.second = centerFrequencyIndex + range.second; + return convertedIndices; +} + } //namespace ns3 diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index 219cb16d6..7ec9a2bd2 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -29,6 +29,7 @@ #include "ns3/antenna-model.h" #include "ns3/spectrum-channel.h" #include "ns3/spectrum-model.h" +#include "ns3/wifi-spectrum-value-helper.h" #include "wifi-phy.h" namespace ns3 { @@ -188,6 +189,15 @@ private: */ Ptr GetTxPowerSpectralDensity (uint16_t centerFrequency, uint16_t channelWidth, double txPowerW, WifiModulationClass modulationClass) const; + /** + * \param channelWidth the total channel width (MHz) used for the OFDMA transmission + * \param range the subcarrier range of the HE RU + * \return the converted indices + * + * This is a helper function to convert HE RU indices, which are relative to the center frequency subcarrier, to the indices used by the Spectrum model. + */ + WifiSpectrumBand ConvertHeRuIndices (uint16_t channelWidth, HeRu::SubcarrierRange range) const; + /** * Perform run-time spectrum model change */