From 21af571db5406529cfd20791ddc208d08c2a6d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Tue, 21 Feb 2023 07:51:29 +0100 Subject: [PATCH] wifi: Simplify RX power per band calculations in SpectrumWifiPhy::StartRx --- src/wifi/model/spectrum-wifi-phy.cc | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 0b972cdf6..6b88de2e3 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -331,7 +331,7 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, double totalRxPowerW = 0; RxPowerWattPerChannelBand rxPowerW; - if ((channelWidth == 5) || (channelWidth == 10)) + if (channelWidth < 20) { const auto filteredBand = GetBandForInterface(channelWidth, 0, freqRange, channelWidth); double rxPowerPerBandW = @@ -345,18 +345,20 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, << WToDbm(rxPowerPerBandW) << " dBm)"); } - // 20 MHz is handled apart since the totalRxPowerW is computed through it - for (uint16_t bw = 160; bw > 20; bw = bw / 2) + for (uint16_t bw = 160; bw >= 20; bw = bw / 2) { for (uint32_t i = 0; i < (channelWidth / bw); i++) { - NS_ASSERT(channelWidth >= bw); const auto filteredBand = GetBandForInterface(bw, i, freqRange, channelWidth); double rxPowerPerBandW = WifiSpectrumValueHelper::GetBandPowerW(receivedSignalPsd, filteredBand.indices); NS_LOG_DEBUG("Signal power received (watts) before antenna gain for " << bw << " MHz channel band " << +i << ": " << rxPowerPerBandW); rxPowerPerBandW *= DbToRatio(GetRxGain()); + if (bw == 20) + { + totalRxPowerW += rxPowerPerBandW; + } rxPowerW.insert({filteredBand.indices, rxPowerPerBandW}); NS_LOG_DEBUG("Signal power received after antenna gain for " << bw << " MHz channel band " << +i << ": " << rxPowerPerBandW << " W (" @@ -364,21 +366,6 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, } } - for (uint32_t i = 0; i < (channelWidth / 20); i++) - { - const auto filteredBand = GetBandForInterface(20, i, freqRange, channelWidth); - double rxPowerPerBandW = - WifiSpectrumValueHelper::GetBandPowerW(receivedSignalPsd, filteredBand.indices); - NS_LOG_DEBUG("Signal power received (watts) before antenna gain for 20 MHz channel band " - << +i << ": " << rxPowerPerBandW); - rxPowerPerBandW *= DbToRatio(GetRxGain()); - totalRxPowerW += rxPowerPerBandW; - rxPowerW.insert({filteredBand.indices, rxPowerPerBandW}); - NS_LOG_DEBUG("Signal power received after antenna gain for 20 MHz channel band " - << +i << ": " << rxPowerPerBandW << " W (" << WToDbm(rxPowerPerBandW) - << " dBm)"); - } - if (GetStandard() >= WIFI_STANDARD_80211ax) { const auto ruBands =