62NrSpectrumValueHelper::GetSpectrumModel(uint32_t numRbs,
63 double centerFrequency,
64 double subcarrierSpacing)
66 NS_LOG_FUNCTION(centerFrequency << numRbs << subcarrierSpacing);
68 NS_ABORT_MSG_IF(numRbs == 0,
"Total bandwidth cannot be 0 RBs");
69 NS_ABORT_MSG_IF(centerFrequency < 0.5e9 || centerFrequency > 100e9,
70 "Central frequency should be in range from 0.5GHz to 100GHz");
71 NS_ABORT_MSG_IF(subcarrierSpacing != 15000 && subcarrierSpacing != 30000 &&
72 subcarrierSpacing != 60000 && subcarrierSpacing != 120000 &&
73 subcarrierSpacing != 240000 && subcarrierSpacing != 480000,
74 "Supported subcarrier spacing values are: 15000, 30000, 60000, 120000, 240000 "
77 NrSpectrumModelId modelId = NrSpectrumModelId(centerFrequency, numRbs, subcarrierSpacing);
78 if (g_nrSpectrumModelMap.find(modelId) == g_nrSpectrumModelMap.end())
80 NS_ASSERT_MSG(centerFrequency != 0,
"The carrier frequency cannot be set to 0");
81 double f = centerFrequency - (numRbs * subcarrierSpacing * SUBCARRIERS_PER_RB / 2.0);
83 for (uint32_t numrb = 0; numrb < numRbs; ++numrb)
87 f += subcarrierSpacing * SUBCARRIERS_PER_RB / 2;
89 f += subcarrierSpacing * SUBCARRIERS_PER_RB / 2;
94 Ptr<SpectrumModel> model = Create<SpectrumModel>(rbs);
96 g_nrSpectrumModelMap.insert(
97 std::pair<NrSpectrumModelId, Ptr<SpectrumModel>>(modelId, model));
98 Simulator::ScheduleDestroy(&NrSpectrumValueHelper::DeleteSpectrumValues);
99 NS_LOG_INFO(
"Created SpectrumModel with frequency: "
100 << f <<
" NumRB: " << rbs.size() <<
" subcarrier spacing: " << subcarrierSpacing
101 <<
", and global UID: " << model->GetUid());
103 return g_nrSpectrumModelMap.find(modelId)->second;
107NrSpectrumValueHelper::CreateTxPsdOverActiveRbs(
double powerTx,
108 const std::vector<int>& activeRbs,
109 const Ptr<const SpectrumModel>& spectrumModel)
111 NS_LOG_FUNCTION(powerTx << activeRbs << spectrumModel);
112 Ptr<SpectrumValue> txPsd = Create<SpectrumValue>(spectrumModel);
113 double powerTxW = std::pow(10., (powerTx - 30) / 10);
114 double txPowerDensity = 0;
115 double subbandWidth = (spectrumModel->Begin()->fh - spectrumModel->Begin()->fl);
116 NS_ABORT_MSG_IF(subbandWidth < 180000,
117 "Erroneous spectrum model. RB width should be equal or greater than 180KHz");
118 txPowerDensity = powerTxW / (subbandWidth * activeRbs.size());
119 for (
int rbId : activeRbs)
121 (*txPsd)[rbId] = txPowerDensity;
123 NS_LOG_LOGIC(*txPsd);
128NrSpectrumValueHelper::CreateTxPsdOverAllRbs(
double powerTx,
129 const std::vector<int>& activeRbs,
130 const Ptr<const SpectrumModel>& spectrumModel)
132 NS_LOG_FUNCTION(powerTx << activeRbs << spectrumModel);
133 Ptr<SpectrumValue> txPsd = Create<SpectrumValue>(spectrumModel);
134 double powerTxW = std::pow(10., (powerTx - 30) / 10);
135 double txPowerDensity = 0;
136 double subbandWidth = (spectrumModel->Begin()->fh - spectrumModel->Begin()->fl);
137 NS_ABORT_MSG_IF(subbandWidth < 180000,
138 "Erroneous spectrum model. RB width should be equal or greater than 180KHz");
139 txPowerDensity = powerTxW / (subbandWidth * spectrumModel->GetNumBands());
140 for (
int rbId : activeRbs)
142 (*txPsd)[rbId] = txPowerDensity;
144 NS_LOG_LOGIC(*txPsd);
149NrSpectrumValueHelper::CreateTxPowerSpectralDensity(
double powerTx,
150 const std::vector<int>& rbIndexVector,
151 const Ptr<const SpectrumModel>& txSm,
152 enum PowerAllocationType allocationType)
154 switch (allocationType)
156 case UNIFORM_POWER_ALLOCATION_BW: {
157 return CreateTxPsdOverAllRbs(powerTx, rbIndexVector, txSm);
159 case UNIFORM_POWER_ALLOCATION_USED: {
160 return CreateTxPsdOverActiveRbs(powerTx, rbIndexVector, txSm);
163 NS_FATAL_ERROR(
"Unknown power allocation type.");
169NrSpectrumValueHelper::CreateNoisePowerSpectralDensity(
170 double noiseFigureDb,
171 const Ptr<const SpectrumModel>& spectrumModel)
173 NS_LOG_FUNCTION(noiseFigureDb << spectrumModel);
174 const double kT_dBm_Hz = -174.0;
175 double kT_W_Hz = std::pow(10.0, (kT_dBm_Hz - 30) / 10.0);
176 double noiseFigureLinear = std::pow(10.0, noiseFigureDb / 10.0);
177 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
179 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(spectrumModel);
180 (*noisePsd) = noisePowerSpectralDensity;
185NrSpectrumValueHelper::GetEffectiveBandwidth(
double bandwidth, uint8_t numerology)
187 NS_LOG_FUNCTION(bandwidth << numerology);
188 uint32_t scSpacing = 15000 *
static_cast<uint32_t
>(std::pow(2, numerology));
189 uint32_t numRbs =
static_cast<uint32_t
>(bandwidth / (scSpacing * SUBCARRIERS_PER_RB));
190 NS_LOG_DEBUG(
"Total bandwidth: " << bandwidth <<
" effective bandwidth:"
191 << numRbs * (scSpacing * SUBCARRIERS_PER_RB));
192 return numRbs * (scSpacing * SUBCARRIERS_PER_RB);