263    const std::vector<MHz_u>& centerFrequencies,
 
  266    MHz_u guardBandwidth,
 
  270    const std::vector<bool>& puncturedSubchannels)
 
  273                      (channelWidth == 
MHz_u{160} && centerFrequencies.size() <= 2),
 
  274                  "PSD for non-contiguous channels is only possible when the total width is 160 " 
  275                  "MHz and cannot be made of more than 2 segments");
 
  277                    << channelWidth << txPower << guardBandwidth << minInnerBand << minOuterBand
 
  279    const Hz_u carrierSpacing{312500};
 
  281        GetSpectrumModel(centerFrequencies, channelWidth, carrierSpacing, guardBandwidth));
 
  284    guardBandwidth /= centerFrequencies.size();
 
  285    const auto nGuardBands =
 
  286        static_cast<uint32_t>(((
MHzToHz(2 * guardBandwidth)) / carrierSpacing) + 0.5);
 
  287    const auto nAllocatedBands =
 
  289    const auto separationWidth = std::abs(centerFrequencies.back() - centerFrequencies.front());
 
  290    const auto unallocatedWidth =
 
  291        separationWidth > 
Hz_u{0} ? (separationWidth - (channelWidth / 2)) : 0;
 
  292    const auto nUnallocatedBands =
 
  293        static_cast<uint32_t>((
MHzToHz(unallocatedWidth) / carrierSpacing) + 0.5);
 
  295                      (nAllocatedBands + nGuardBands + nUnallocatedBands + 1),
 
  296                  "Unexpected number of bands " << c->GetSpectrumModel()->GetNumBands());
 
  298    std::size_t numAllocatedSubcarriersPer20MHz = 52;
 
  299    NS_ASSERT(puncturedSubchannels.empty() || (puncturedSubchannels.size() == num20MhzBands));
 
  300    const auto txPowerPerBand = (txPower / numAllocatedSubcarriersPer20MHz) / num20MhzBands;
 
  301    NS_LOG_DEBUG(
"Power per band " << txPowerPerBand << 
"W");
 
  303    std::size_t numSubcarriersPer20MHz = 
MHzToHz(
MHz_u{20}) / carrierSpacing;
 
  304    std::size_t numUnallocatedSubcarriersPer20MHz =
 
  305        numSubcarriersPer20MHz - numAllocatedSubcarriersPer20MHz;
 
  306    std::vector<std::vector<WifiSpectrumBandIndices>> subBandsPerSegment(
 
  307        centerFrequencies.size()); 
 
  308    for (std::size_t i = 0; i < centerFrequencies.size(); ++i)
 
  310        subBandsPerSegment.at(i).resize(
 
  311            num20MhzBands * 2 / centerFrequencies.size()); 
 
  314    std::vector<std::vector<WifiSpectrumBandIndices>> puncturedBandsPerSegment;
 
  315    uint32_t start = (nGuardBands / 2) + (numUnallocatedSubcarriersPer20MHz / 2);
 
  318    for (
auto& subBands : subBandsPerSegment)
 
  320        puncturedBandsPerSegment.emplace_back();
 
  321        for (
auto it = subBands.begin(); it != subBands.end();)
 
  323            stop = start + (numAllocatedSubcarriersPer20MHz / 2) - 1;
 
  324            *it = std::make_pair(start, stop);
 
  328            stop = start + (numAllocatedSubcarriersPer20MHz / 2) - 1;
 
  329            *it = std::make_pair(start, stop);
 
  331            start = stop + numUnallocatedSubcarriersPer20MHz;
 
  333            if (!puncturedSubchannels.empty() && puncturedSubchannels.at(index++))
 
  335                puncturedBandsPerSegment.back().emplace_back(puncturedStart, puncturedStop);
 
  338        start += nUnallocatedBands;
 
  342    auto innerSlopeWidth = 
static_cast<uint32_t>(
 
  343        (
Hz_u{2e6} / carrierSpacing) +
 
  346    const auto puncturedSlopeWidth =
 
  360                              puncturedBandsPerSegment,
 
  361                              puncturedSlopeWidth);
 
 
  480    const std::vector<MHz_u>& centerFrequencies,
 
  483    MHz_u guardBandwidth,
 
  487    const std::vector<bool>& puncturedSubchannels)
 
  490        centerFrequencies.size() == 1 || channelWidth == 
MHz_u{160},
 
  491        "PSD for non-contiguous channels is only possible when the total width is 160 MHz");
 
  493        (channelWidth != 160) || (centerFrequencies.size() <= 2),
 
  494        "It is not possible to create a PSD made of more than 2 segments for a width of 160 MHz");
 
  496                    << channelWidth << txPower << guardBandwidth << minInnerBand << minOuterBand
 
  498    const Hz_u carrierSpacing{78125};
 
  500        GetSpectrumModel(centerFrequencies, channelWidth, carrierSpacing, guardBandwidth));
 
  503    guardBandwidth /= centerFrequencies.size();
 
  504    const auto nGuardBands =
 
  505        static_cast<uint32_t>(((
MHzToHz(2 * guardBandwidth)) / carrierSpacing) + 0.5);
 
  506    const auto separationWidth = std::abs(centerFrequencies.back() - centerFrequencies.front());
 
  507    const auto unallocatedWidth =
 
  508        separationWidth > 
Hz_u{0} ? (separationWidth - (channelWidth / 2)) : 0;
 
  509    const auto nUnallocatedBands =
 
  510        static_cast<uint32_t>((
MHzToHz(unallocatedWidth) / carrierSpacing) + 0.5);
 
  511    const auto nAllocatedBands =
 
  514                      (nAllocatedBands + nGuardBands + nUnallocatedBands + 1),
 
  515                  "Unexpected number of bands " << c->GetSpectrumModel()->GetNumBands());
 
  516    Watt_u txPowerPerBand{0.0};
 
  518    auto innerSlopeWidth =
 
  521    std::vector<std::vector<WifiSpectrumBandIndices>> subBandsPerSegment(
 
  522        centerFrequencies.size()); 
 
  524    std::size_t skippedSubbands{0};
 
  525    std::size_t numAllocatedSubbands{0};
 
  526    std::size_t numDc{0};
 
  527    switch (
static_cast<uint16_t
>(channelWidth))
 
  531        txPowerPerBand = txPower / 242;
 
  532        innerSlopeWidth = 
static_cast<uint32_t>((
Hz_u{5e5} / carrierSpacing) +
 
  535        numAllocatedSubbands = 121;
 
  540        txPowerPerBand = txPower / 484;
 
  541        skippedSubbands = 12;
 
  542        numAllocatedSubbands = 242;
 
  549        txPowerPerBand = txPower / (996 * (channelWidth / 80));
 
  550        skippedSubbands = 12;
 
  551        numAllocatedSubbands = 498;
 
  555        NS_FATAL_ERROR(
"ChannelWidth " << channelWidth << 
" unsupported");
 
  562    auto start = (nGuardBands / 2) + skippedSubbands;
 
  563    auto stop = start + numAllocatedSubbands - 1;
 
  564    subBandsPerSegment.at(0).emplace_back(start, stop);
 
  565    start = stop + numDc + 1;
 
  566    stop = start + numAllocatedSubbands - 1;
 
  567    subBandsPerSegment.at(0).emplace_back(start, stop);
 
  568    if (channelWidth >= 160)
 
  570        for (std::size_t i = 1; i < (channelWidth / 80); ++i)
 
  572            start = subBandsPerSegment.front().back().second + (2 * skippedSubbands) +
 
  574            auto stop = start + numAllocatedSubbands - 1;
 
  575            subBandsPerSegment.back().emplace_back(start, stop);
 
  576            start = stop + numDc + 1;
 
  577            stop = start + numAllocatedSubbands - 1;
 
  578            subBandsPerSegment.back().emplace_back(start, stop);
 
  583    auto puncturedSlopeWidth =
 
  586    std::vector<std::vector<WifiSpectrumBandIndices>> puncturedBandsPerSegment;
 
  587    std::size_t subcarriersPerSuband = (
MHzToHz(
MHz_u{20}) / carrierSpacing);
 
  588    start = (nGuardBands / 2);
 
  589    stop = start + subcarriersPerSuband - 1;
 
  590    if (!puncturedSubchannels.empty())
 
  592        for (std::size_t i = 0; i < subBandsPerSegment.size(); ++i)
 
  594            puncturedBandsPerSegment.emplace_back();
 
  597    std::size_t prevPsdIndex = 0;
 
  598    for (std::size_t i = 0; i < puncturedSubchannels.size(); ++i)
 
  600        std::size_t psdIndex = (puncturedBandsPerSegment.size() == 1)
 
  602                                   : ((i < (puncturedSubchannels.size() / 2)) ? 0 : 1);
 
  603        if (psdIndex != prevPsdIndex)
 
  605            start += nUnallocatedBands;
 
  606            stop += nUnallocatedBands;
 
  608        if (puncturedSubchannels.at(i))
 
  610            puncturedBandsPerSegment.at(psdIndex).emplace_back(start, stop);
 
  613        stop = start + subcarriersPerSuband - 1;
 
  614        prevPsdIndex = psdIndex;
 
  627                              puncturedBandsPerSegment,
 
  628                              puncturedSlopeWidth);
 
 
  680    const std::vector<std::vector<WifiSpectrumBandIndices>>& allocatedSubBandsPerSegment,
 
  688    const std::vector<std::vector<WifiSpectrumBandIndices>>& puncturedBandsPerSegment,
 
  692                  "Only PSDs for up to 2 frequency segments are supported");
 
  693    NS_ASSERT(puncturedBandsPerSegment.empty() ||
 
  694              (puncturedBandsPerSegment.size() == allocatedSubBandsPerSegment.size()));
 
  696                      << allocatedSubBandsPerSegment.front().back().second << maskBand.first
 
  697                      << maskBand.second << txPowerPerBand << nGuardBands << innerSlopeWidth
 
  698                      << minInnerBand << minOuterBand << lowestPoint << puncturedSlopeWidth);
 
  699    uint32_t numSubBands = allocatedSubBandsPerSegment.front().size();
 
  700    uint32_t numBands = c->GetSpectrumModel()->GetNumBands();
 
  701    uint32_t numMaskBands = maskBand.second - maskBand.first + 1;
 
  702    NS_ASSERT(numSubBands && numBands && numMaskBands);
 
  703    NS_LOG_LOGIC(
"Power per band " << txPowerPerBand << 
"W");
 
  706    dBm_u txPowerRef{10.0 * std::log10(txPowerPerBand * 1000.0)};
 
  707    dBm_u txPowerInnerBandMin{txPowerRef + minInnerBand};
 
  708    dBm_u txPowerMiddleBandMin{txPowerRef + minOuterBand};
 
  709    dBm_u txPowerOuterBandMin{txPowerRef +
 
  716    uint32_t middleSlopeWidth = outerSlopeWidth - (innerSlopeWidth / 2);
 
  718    std::vector<WifiSpectrumBandIndices> outerBandsLeft;
 
  719    std::vector<WifiSpectrumBandIndices> middleBandsLeft;
 
  720    std::vector<WifiSpectrumBandIndices> flatJunctionsLeft;
 
  721    std::vector<WifiSpectrumBandIndices> innerBandsLeft;
 
  722    std::vector<WifiSpectrumBandIndices> allocatedSubBands;
 
  723    std::vector<WifiSpectrumBandIndices> innerBandsRight;
 
  724    std::vector<WifiSpectrumBandIndices> flatJunctionsRight;
 
  725    std::vector<WifiSpectrumBandIndices> middleBandsRight;
 
  726    std::vector<WifiSpectrumBandIndices> outerBandsRight;
 
  727    std::optional<WifiSpectrumBandIndices> betweenPsdsBand;
 
  729    allocatedSubBands.emplace_back(allocatedSubBandsPerSegment.front().front().first,
 
  730                                   allocatedSubBandsPerSegment.front().back().second);
 
  731    outerBandsLeft.emplace_back(maskBand.first, 
 
  733                                maskBand.first + outerSlopeWidth - 1);
 
  734    middleBandsLeft.emplace_back(outerBandsLeft.front().second + 1,
 
  735                                 outerBandsLeft.front().second + middleSlopeWidth);
 
  736    innerBandsLeft.emplace_back(allocatedSubBands.front().first - innerSlopeWidth,
 
  737                                allocatedSubBands.front().first -
 
  739    flatJunctionsLeft.emplace_back(middleBandsLeft.front().second + 1,
 
  740                                   innerBandsLeft.front().first -
 
  743        flatJunctionsLeft.front().second - flatJunctionsLeft.front().first + 1;
 
  744    innerBandsRight.emplace_back(allocatedSubBands.front().second + 1,
 
  745                                 allocatedSubBands.front().second + innerSlopeWidth);
 
  746    flatJunctionsRight.emplace_back(innerBandsRight.front().second + 1,
 
  747                                    innerBandsRight.front().second + flatJunctionWidth);
 
  748    middleBandsRight.emplace_back(flatJunctionsRight.front().second + 1,
 
  749                                  flatJunctionsRight.front().second + middleSlopeWidth);
 
  750    outerBandsRight.emplace_back(middleBandsRight.front().second + 1,
 
  751                                 middleBandsRight.front().second + outerSlopeWidth);
 
  753    if (allocatedSubBandsPerSegment.size() > 1)
 
  755        const auto offset = (((allocatedSubBandsPerSegment.front().back().
second -
 
  756                               allocatedSubBandsPerSegment.front().front().first) /
 
  758                             (allocatedSubBandsPerSegment.back().front().first -
 
  759                              allocatedSubBandsPerSegment.front().back().second) +
 
  760                             ((allocatedSubBandsPerSegment.back().back().second -
 
  761                               allocatedSubBandsPerSegment.back().front().first) /
 
  763        outerBandsLeft.emplace_back(outerBandsLeft.front().first + offset,
 
  764                                    outerBandsLeft.front().second + offset);
 
  765        middleBandsLeft.emplace_back(middleBandsLeft.front().first + offset,
 
  766                                     middleBandsLeft.front().second + offset);
 
  767        flatJunctionsLeft.emplace_back(flatJunctionsLeft.front().first + offset,
 
  768                                       flatJunctionsLeft.front().second + offset);
 
  769        innerBandsLeft.emplace_back(innerBandsLeft.front().first + offset,
 
  770                                    innerBandsLeft.front().second + offset);
 
  771        allocatedSubBands.emplace_back(allocatedSubBands.front().first + offset,
 
  772                                       allocatedSubBands.front().second + offset);
 
  773        innerBandsRight.emplace_back(innerBandsRight.front().first + offset,
 
  774                                     innerBandsRight.front().second + offset);
 
  775        flatJunctionsRight.emplace_back(flatJunctionsRight.front().first + offset,
 
  776                                        flatJunctionsRight.front().second + offset);
 
  777        middleBandsRight.emplace_back(middleBandsRight.front().first + offset,
 
  778                                      middleBandsRight.front().second + offset);
 
  779        outerBandsRight.emplace_back(outerBandsRight.front().first + offset,
 
  780                                     outerBandsRight.front().second + offset);
 
  781        betweenPsdsBand.emplace(middleBandsRight.front().first, middleBandsLeft.back().second);
 
  784    std::ostringstream ss;
 
  785    for (std::size_t i = 0; i < allocatedSubBandsPerSegment.size(); ++i)
 
  787        if (allocatedSubBandsPerSegment.size() > 1)
 
  789            ss << 
"PSD" << i + 1 << 
": ";
 
  791        ss << 
"outerBandLeft=[" << outerBandsLeft.at(i).first << 
";" << outerBandsLeft.at(i).second
 
  793           << 
"middleBandLeft=[" << middleBandsLeft.at(i).first << 
";" 
  794           << middleBandsLeft.at(i).second << 
"] " 
  795           << 
"flatJunctionLeft=[" << flatJunctionsLeft.at(i).first << 
";" 
  796           << flatJunctionsLeft.at(i).second << 
"] " 
  797           << 
"innerBandLeft=[" << innerBandsLeft.at(i).first << 
";" << innerBandsLeft.at(i).second
 
  799           << 
"allocatedBand=[" << allocatedSubBands.at(i).first << 
";" 
  800           << allocatedSubBands.at(i).second << 
"] ";
 
  801        if (!puncturedBandsPerSegment.empty() && !puncturedBandsPerSegment.at(i).empty())
 
  803            ss << 
"puncturedBands=[" << puncturedBandsPerSegment.at(i).front().first << 
";" 
  804               << puncturedBandsPerSegment.at(i).back().second << 
"] ";
 
  806        ss << 
"innerBandRight=[" << innerBandsRight.at(i).first << 
";" 
  807           << innerBandsRight.at(i).second << 
"] " 
  808           << 
"flatJunctionRight=[" << flatJunctionsRight.at(i).first << 
";" 
  809           << flatJunctionsRight.at(i).second << 
"] " 
  810           << 
"middleBandRight=[" << middleBandsRight.at(i).first << 
";" 
  811           << middleBandsRight.at(i).second << 
"] " 
  812           << 
"outerBandRight=[" << outerBandsRight.at(i).first << 
";" 
  813           << outerBandsRight.at(i).second << 
"] ";
 
  815    if (allocatedSubBandsPerSegment.size() > 1)
 
  818           << 
"outerBandLeft=[" << outerBandsLeft.front().first << 
";" 
  819           << outerBandsLeft.front().second << 
"] " 
  820           << 
"middleBandLeft=[" << middleBandsLeft.front().first << 
";" 
  821           << middleBandsLeft.front().second << 
"] " 
  822           << 
"flatJunctionLeft=[" << flatJunctionsLeft.front().first << 
";" 
  823           << flatJunctionsLeft.front().second << 
"] " 
  824           << 
"innerBandLeft=[" << innerBandsLeft.front().first << 
";" 
  825           << innerBandsLeft.front().second << 
"] " 
  826           << 
"allocatedBandInPsd1=[" << allocatedSubBands.front().first << 
";" 
  827           << allocatedSubBands.front().second << 
"] ";
 
  828        if (!puncturedBandsPerSegment.empty() && !puncturedBandsPerSegment.front().empty())
 
  830            ss << 
"puncturedBandsInPsd1=[" << puncturedBandsPerSegment.front().front().first << 
";" 
  831               << puncturedBandsPerSegment.front().back().second << 
"] ";
 
  833        ss << 
"flatJunctionRightPsd1=[" << flatJunctionsRight.front().first << 
";" 
  834           << flatJunctionsRight.front().second << 
"] " 
  835           << 
"linearSum=[" << betweenPsdsBand->first << 
";" << betweenPsdsBand->second << 
"] " 
  836           << 
"flatJunctionLeftPsd2=[" << flatJunctionsLeft.back().first << 
";" 
  837           << flatJunctionsLeft.back().second << 
"] " 
  838           << 
"innerBandLeftPsd2=[" << innerBandsLeft.back().first << 
";" 
  839           << innerBandsLeft.back().second << 
"] " 
  840           << 
"allocatedBandInPsd2=[" << allocatedSubBands.back().first << 
";" 
  841           << allocatedSubBands.back().second << 
"] ";
 
  842        if (!puncturedBandsPerSegment.empty() && !puncturedBandsPerSegment.back().empty())
 
  844            ss << 
"puncturedBandsInPsd2=[" << puncturedBandsPerSegment.back().front().first << 
";" 
  845               << puncturedBandsPerSegment.back().back().second << 
"] ";
 
  847        ss << 
"innerBandRight=[" << innerBandsRight.back().first << 
";" 
  848           << innerBandsRight.back().second << 
"] " 
  849           << 
"flatJunctionRight=[" << flatJunctionsRight.back().first << 
";" 
  850           << flatJunctionsRight.back().second << 
"] " 
  851           << 
"middleBandRight=[" << middleBandsRight.back().first << 
";" 
  852           << middleBandsRight.back().second << 
"] " 
  853           << 
"outerBandRight=[" << outerBandsRight.back().first << 
";" 
  854           << outerBandsRight.back().second << 
"] ";
 
  857    NS_ASSERT(maskBand.second == outerBandsRight.back().second);
 
  859              ((allocatedSubBandsPerSegment.back().back().second -
 
  860                allocatedSubBandsPerSegment.front().front().first +
 
  862               + 2 * (innerSlopeWidth + middleSlopeWidth + outerSlopeWidth + flatJunctionWidth)));
 
  865    double innerSlope = (-1.0 * minInnerBand) / innerSlopeWidth;
 
  866    double middleSlope = (-1.0 * (minOuterBand - minInnerBand)) / middleSlopeWidth;
 
  867    double outerSlope = (txPowerMiddleBandMin - txPowerOuterBandMin) / outerSlopeWidth;
 
  868    double puncturedSlope = (-1.0 * minInnerBand) / puncturedSlopeWidth;
 
  871    Watt_u previousTxPower{0.0};
 
  872    std::vector<Watt_u> txPowerValues(numBands);
 
  873    NS_ASSERT(txPowerValues.size() == numBands);
 
  874    for (
size_t i = 0; i < numBands; ++i)
 
  877            (allocatedSubBandsPerSegment.size() == 1) ? 0 : ((i < (numBands / 2)) ? 0 : 1);
 
  879        if (i < maskBand.first || i > maskBand.second) 
 
  883        else if (betweenPsdsBand.has_value() &&
 
  884                 (i <= betweenPsdsBand->
second && i >= betweenPsdsBand->first))
 
  887            std::vector<Watt_u> txPowerWPsds(2);
 
  888            if (i <= middleBandsRight.at(0).second && i >= middleBandsRight.at(0).first)
 
  891                    DbmToW(txPowerInnerBandMin -
 
  892                           ((i - middleBandsRight.at(0).first + 1) *
 
  895            else if (i <= outerBandsRight.at(0).second && i >= outerBandsRight.at(0).first)
 
  898                    DbmToW(txPowerMiddleBandMin -
 
  899                           ((i - outerBandsRight.at(0).first + 1) *
 
  902            else if (i > outerBandsRight.at(0).second)
 
  904                txPower = 
DbmToW(txPowerOuterBandMin);
 
  912            if (i < outerBandsLeft.at(1).first)
 
  914                txPower = 
DbmToW(txPowerOuterBandMin);
 
  916            else if (i <= outerBandsLeft.at(1).second && i >= outerBandsLeft.at(1).first)
 
  919                    DbmToW(txPowerOuterBandMin + ((i - outerBandsLeft.at(1).first) * outerSlope));
 
  921            else if (i <= middleBandsLeft.at(1).second && i >= middleBandsLeft.at(1).first)
 
  923                txPowerWPsds.at(1) = 
DbmToW(txPowerMiddleBandMin +
 
  924                                            ((i - middleBandsLeft.at(1).first) * middleSlope));
 
  931            txPower = std::accumulate(txPowerWPsds.cbegin(), txPowerWPsds.cend(), 
Watt_u{0.0});
 
  932            txPower = std::max(
DbmToW(txPowerRef - 25.0), txPower);
 
  933            txPower = std::min(
DbmToW(txPowerRef - 20.0), txPower);
 
  935        else if (i <= outerBandsLeft.at(psdIndex).second &&
 
  936                 i >= outerBandsLeft.at(psdIndex)
 
  939            txPower = 
DbmToW(txPowerOuterBandMin +
 
  940                             ((i - outerBandsLeft.at(psdIndex).first) * outerSlope));
 
  942        else if (i <= middleBandsLeft.at(psdIndex).second &&
 
  943                 i >= middleBandsLeft.at(psdIndex).first)
 
  945            txPower = 
DbmToW(txPowerMiddleBandMin +
 
  946                             ((i - middleBandsLeft.at(psdIndex).first) * middleSlope));
 
  948        else if ((i <= flatJunctionsLeft.at(psdIndex).second &&
 
  949                  i >= flatJunctionsLeft.at(psdIndex).first) ||
 
  950                 (i <= flatJunctionsRight.at(psdIndex).second &&
 
  951                  i >= flatJunctionsRight.at(psdIndex).first))
 
  953            txPower = 
DbmToW(txPowerInnerBandMin);
 
  955        else if (i <= innerBandsLeft.at(psdIndex).second && i >= innerBandsLeft.at(psdIndex).first)
 
  957            txPower = (!puncturedBandsPerSegment.empty() &&
 
  958                       !puncturedBandsPerSegment.at(psdIndex).empty() &&
 
  959                       (puncturedBandsPerSegment.at(psdIndex).front().first <=
 
  960                        allocatedSubBandsPerSegment.at(psdIndex).front().first))
 
  961                          ? 
DbmToW(txPowerInnerBandMin)
 
  963                          DbmToW(txPowerInnerBandMin +
 
  964                                 ((i - innerBandsLeft.at(psdIndex).first) * innerSlope));
 
  966        else if ((i <= allocatedSubBandsPerSegment.at(psdIndex).back().second &&
 
  967                  i >= allocatedSubBandsPerSegment.at(psdIndex).front().first)) 
 
  970            bool insideSubBand = 
false;
 
  971            for (
uint32_t j = 0; !insideSubBand && j < numSubBands;
 
  974                insideSubBand = (i <= allocatedSubBandsPerSegment.at(psdIndex)[j].
second) &&
 
  975                                (i >= allocatedSubBandsPerSegment.at(psdIndex)[j].
first);
 
  979                bool insidePuncturedSubBand = 
false;
 
  981                std::size_t puncturedBandSize = !puncturedBandsPerSegment.empty()
 
  982                                                    ? puncturedBandsPerSegment.at(psdIndex).size()
 
  984                for (; !insidePuncturedSubBand && j < puncturedBandSize;
 
  987                    insidePuncturedSubBand =
 
  988                        (i <= puncturedBandsPerSegment.at(psdIndex).at(j).
second) &&
 
  989                        (i >= puncturedBandsPerSegment.at(psdIndex).at(j).
first);
 
  991                if (insidePuncturedSubBand)
 
  994                        (puncturedBandsPerSegment.at(psdIndex)
 
  995                             .at(puncturedBandsPerSegment.at(psdIndex).size() - 1)
 
  997                         puncturedSlopeWidth); 
 
  998                    if (i >= startPuncturedSlope)
 
 1000                        txPower = 
DbmToW(txPowerInnerBandMin +
 
 1001                                         ((i - startPuncturedSlope) * puncturedSlope));
 
 1006                            DbmToW(txPowerInnerBandMin),
 
 1008                                   ((i - puncturedBandsPerSegment.at(psdIndex).at(0).first) *
 
 1014                    txPower = txPowerPerBand;
 
 1019                txPower = 
DbmToW(txPowerInnerBandMin);
 
 1022        else if (i <= innerBandsRight.at(psdIndex).second &&
 
 1023                 i >= innerBandsRight.at(psdIndex).first)
 
 1028                DbmToW(txPowerRef - ((i - innerBandsRight.at(psdIndex).first + 1) *
 
 1031        else if (i <= middleBandsRight.at(psdIndex).second &&
 
 1032                 i >= middleBandsRight.at(psdIndex).first)
 
 1034            txPower = 
DbmToW(txPowerInnerBandMin -
 
 1035                             ((i - middleBandsRight.at(psdIndex).first + 1) *
 
 1038        else if (i <= outerBandsRight.at(psdIndex).second &&
 
 1039                 i >= outerBandsRight.at(psdIndex).first)
 
 1041            txPower = 
DbmToW(txPowerMiddleBandMin -
 
 1042                             ((i - outerBandsRight.at(psdIndex).first + 1) *
 
 1049        NS_LOG_LOGIC(i << 
" -> " << (10 * std::log10(txPower / txPowerPerBand)));
 
 1050        previousTxPower = txPower;
 
 1051        txPowerValues.at(i) = txPower;
 
 1055    auto vit = c->ValuesBegin();
 
 1056    auto bit = c->ConstBandsBegin();
 
 1057    const auto invBandwidth = 1 / (bit->fh - bit->fl);
 
 1058    for (
auto txPowerValue : txPowerValues)
 
 1060        *vit = txPowerValue * invBandwidth;
 
 1065    for (
const auto& allocatedSubBands : allocatedSubBandsPerSegment)
 
 1067        NS_LOG_INFO(
"Added signal power to subbands " << allocatedSubBands.front().first << 
"-" 
 1068                                                      << allocatedSubBands.back().second);