diff --git a/lib/include/srsran/phy/ch_estimation/csi_rs.h b/lib/include/srsran/phy/ch_estimation/csi_rs.h index 7f7e659c9..1dae8fb52 100644 --- a/lib/include/srsran/phy/ch_estimation/csi_rs.h +++ b/lib/include/srsran/phy/ch_estimation/csi_rs.h @@ -40,18 +40,24 @@ #define SRSRAN_CSI_RS_NOF_FREQ_DOMAIN_ALLOC_OTHER 6 /** - * @brief Measurement structure + * @brief Describes a measurement for NZP-CSI-RS + * @note Used for fine tracking RSRP, SNR, CFO, SFO, and so on + * @note srsran_csi_measurements_t is used for CSI report generation */ typedef struct SRSRAN_API { - float rsrp; - float rsrp_dB; - float epre; - float epre_dB; - float n0; - float n0_dB; - float snr_dB; - uint32_t nof_re; -} srsran_csi_rs_measure_t; + float rsrp; ///< Linear scale RSRP + float rsrp_dB; ///< Logarithm scale RSRP relative to full-scale + float epre; ///< Linear scale EPRE + float epre_dB; ///< Logarithm scale EPRE relative to full-scale + float n0; ///< Linear noise level + float n0_dB; ///< Logarithm scale noise level relative to full-scale + float snr_dB; ///< Signal to noise ratio in decibels + float cfo_hz; ///< Carrier frequency offset in Hz. Only set if more than 2 symbols are available in a TRS set + float cfo_hz_max; ///< Maximum CFO in Hz that can be measured. It is set to 0 if CFO cannot be estimated + float delay_us; ///< Average measured delay in microseconds + uint32_t nof_re; ///< Number of available RE for the measurement, it can be used for weighting among different + ///< measurements +} srsran_csi_rs_nzp_measure_t; /** * @brief Calculates if the given periodicity implies a CSI-RS transmission in the given slot @@ -67,7 +73,7 @@ SRSRAN_API bool srsran_csi_rs_send(const srsran_csi_rs_period_and_offset_t* peri * @brief Adds to a RE pattern list the RE used in a CSI-RS resource for all CDM grops. This is intended for generating * reserved RE pattern for PDSCH transmission. * @param carrier Provides carrier configuration - * @param resource Provides a CSI-RS resource + * @param resource Provides any CSI-RS resource mapping * @param nof_resources Provides the number of ZP-CSI-RS resources * @param l Symbol index in the slot * @param[out] rvd_mask Provides the reserved mask @@ -77,17 +83,121 @@ SRSRAN_API int srsran_csi_rs_append_resource_to_pattern(const srsran_carrier_nr_ const srsran_csi_rs_resource_mapping_t* resource, srsran_re_pattern_list_t* re_pattern_list); -SRSRAN_API int srsran_csi_rs_nzp_put(const srsran_carrier_nr_t* carrier, - const srsran_slot_cfg_t* slot_cfg, - const srsran_csi_rs_nzp_resource_t* resource, - cf_t* grid); +/** + * @brief Puts in the provided resource grid NZP-CSI-RS signals given by a NZP-CSI-RS resource + * + * @note it does not check if the provided slot matches with the periodicity of the provided NZP-CSI-RS resource + * + * @param carrier Provides carrier configuration + * @param slot_cfg Provides current slot configuration + * @param resource Provides a NZP-CSI-RS resource + * @param[out] grid Resource grid + * @return SRSLTE_SUCCESS if the arguments and the resource are valid. SRSLTE_ERROR code otherwise. + */ +SRSRAN_API int srsran_csi_rs_nzp_put_resource(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_resource_t* resource, + cf_t* grid); +/** + * @brief Puts in the provided resource grid NZP-CSI-RS signals given by a NZP-CSI-RS resource set if their periodicity + * configuration matches with the provided slot + * + * @param carrier Provides carrier configuration + * @param slot_cfg Provides current slot configuration + * @param set Provides a NZP-CSI-RS resource set + * @param[out] grid Resource grid + * @return The number of NZP-CSI-RS resources that have been scheduled for this slot if the arguments and the resource + * are valid. SRSLTE_ERROR code otherwise. + */ +SRSRAN_API int srsran_csi_rs_nzp_put_set(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + cf_t* grid); SRSRAN_API int srsran_csi_rs_nzp_measure(const srsran_carrier_nr_t* carrier, const srsran_slot_cfg_t* slot_cfg, const srsran_csi_rs_nzp_resource_t* resource, const cf_t* grid, - srsran_csi_rs_measure_t* measure); + srsran_csi_rs_nzp_measure_t* measure); -SRSRAN_API uint32_t srsran_csi_rs_measure_info(const srsran_csi_rs_measure_t* measure, char* str, uint32_t str_len); +/** + * @brief Performs measurements of NZP-CSI-RS resource set flagged as TRS + * + * @attention It expects: + * - The NZP-CSI-RS resource set shall be flagged as TRS; and + * - at least a pair of active NZP-CSR-RS per measurement opportunity with their first transmission symbol in ascending + * order. + * + * @note It performs the following wideband measurements: + * - RSRP (linear and dB), + * - EPRE (linear and dB), + * - Noise (linear and dB), + * - SNR (dB), + * - average delay (microseconds), and + * - CFO (Hz) + * + * @note It is intended for fine tracking of synchronization error (average delay) and carrier frequency error + * + * @param carrier Provides carrier configuration + * @param slot_cfg Provides current slot + * @param set Provides NZP-CSI-RS resource + * @param grid Resource grid + * @param measure Provides measurement + * @return The number of NZP-CSI-RS resources scheduled for this TTI if the configuration is right, SRSLTE_ERROR code if + * the configuration is invalid + */ +SRSRAN_API int srsran_csi_rs_nzp_measure_trs(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + const cf_t* grid, + srsran_csi_rs_nzp_measure_t* measure); + +SRSRAN_API uint32_t srsran_csi_rs_measure_info(const srsran_csi_rs_nzp_measure_t* measure, char* str, uint32_t str_len); + +/** + * @brief Performs channel measurements of NZP-CSI-RS resource set for CSI reports + * + * @note It performs the following wideband measurements: + * - RSRP (dB), + * - EPRE (dB), + * - SNR (dB), + * + * @note It is intended for generating CSI wideband measurements that are used for generating CSI reporting + * + * @param carrier Provides carrier configuration + * @param slot_cfg Provides current slot + * @param set Provides NZP-CSI-RS resource + * @param grid Resource grid + * @param measure Provides CSI measurement + * @return The number of NZP-CSI-RS resources scheduled for this slot if the configuration is right, SRSLTE_ERROR code + * if the configuration is invalid + */ +SRSRAN_API int srsran_csi_rs_nzp_measure_channel(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + const cf_t* grid, + srsran_csi_measurements_t* measure); + +/** + * @brief Performs measurements of ZP-CSI-RS resource set for CSI reports + * + * @note It performs the following wideband measurememnts: + * - EPRE (dB) + * + * @note It is intended for measuring interference + * + * @param carrier Provides carrier configuration + * @param slot_cfg Provides current slot + * @param set Provides ZP-CSI-RS resource + * @param grid Resource grid + * @param measure Provides CSI measurement + * @return The number of ZP-CSI-RS resources scheduled for this slot if the configuration is right, SRSLTE_ERROR code if + * the configuration is invalid + */ +SRSRAN_API int srsran_csi_rs_zp_measure_channel(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_zp_set_t* set, + const cf_t* grid, + srsran_csi_measurements_t* measure); #endif // SRSRAN_CSI_RS_H_ diff --git a/lib/src/phy/ch_estimation/csi_rs.c b/lib/src/phy/ch_estimation/csi_rs.c index 767c6a799..df6cdc166 100644 --- a/lib/src/phy/ch_estimation/csi_rs.c +++ b/lib/src/phy/ch_estimation/csi_rs.c @@ -56,7 +56,7 @@ static int csi_rs_location_f(const srsran_csi_rs_resource_mapping_t* resource, u } if (count == i) { - return j * mul; + return (int)(j * mul); } } @@ -177,7 +177,7 @@ static uint32_t csi_rs_cinit(const srsran_carrier_nr_t* carrier, uint32_t n = SRSRAN_SLOT_NR_MOD(carrier->scs, slot_cfg->idx); uint32_t n_id = resource->scrambling_id; - return ((SRSRAN_NSYMB_PER_SLOT_NR * n + l + 1UL) * (2UL * n_id) << 10UL) + n_id; + return SRSRAN_SEQUENCE_MOD(((SRSRAN_NSYMB_PER_SLOT_NR * n + l + 1UL) * (2UL * n_id) << 10UL) + n_id); } bool srsran_csi_rs_send(const srsran_csi_rs_period_and_offset_t* periodicity, const srsran_slot_cfg_t* slot_cfg) @@ -238,7 +238,6 @@ uint32_t csi_rs_count(srsran_csi_rs_density_t density, uint32_t nprb) case srsran_csi_rs_resource_mapping_density_three: return nprb * 3; case srsran_csi_rs_resource_mapping_density_dot5_even: - return nprb / 2; case srsran_csi_rs_resource_mapping_density_dot5_odd: return nprb / 2; case srsran_csi_rs_resource_mapping_density_one: @@ -339,12 +338,13 @@ int srsran_csi_rs_append_resource_to_pattern(const srsran_carrier_nr_t* return SRSRAN_SUCCESS; } -int srsran_csi_rs_nzp_put(const srsran_carrier_nr_t* carrier, - const srsran_slot_cfg_t* slot_cfg, - const srsran_csi_rs_nzp_resource_t* resource, - cf_t* grid) +int srsran_csi_rs_nzp_put_resource(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_resource_t* resource, + cf_t* grid) { - if (carrier == NULL || resource == NULL || grid == NULL) { + // Verify inputs + if (carrier == NULL || slot_cfg == NULL || resource == NULL || grid == NULL) { return SRSRAN_ERROR; } @@ -412,25 +412,76 @@ int srsran_csi_rs_nzp_put(const srsran_carrier_nr_t* carrier, return SRSRAN_SUCCESS; } -int srsran_csi_rs_nzp_measure(const srsran_carrier_nr_t* carrier, - const srsran_slot_cfg_t* slot_cfg, - const srsran_csi_rs_nzp_resource_t* resource, - const cf_t* grid, - srsran_csi_rs_measure_t* measure) +int srsran_csi_rs_nzp_put_set(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + cf_t* grid) { - if (carrier == NULL || resource == NULL || grid == NULL) { + // Verify inputs + if (carrier == NULL || slot_cfg == NULL || set == NULL || grid == NULL) { return SRSRAN_ERROR; } + uint32_t count = 0; + + // Iterate all resources in set + for (uint32_t i = 0; i < set->count; i++) { + // Skip resource + if (!srsran_csi_rs_send(&set->data[i].periodicity, slot_cfg)) { + continue; + } + + // Put resource + if (srsran_csi_rs_nzp_put_resource(carrier, slot_cfg, &set->data[i], grid) < SRSRAN_SUCCESS) { + ERROR("Error putting NZP-CSI-RS resource"); + return SRSRAN_ERROR; + } + count++; + } + + return (int)count; +} + +/** + * @brief Internal NZP-CSI-RS measurement structure + */ +typedef struct { + uint32_t cri; ///< CSI-RS resource identifier + uint32_t l0; ///< First OFDM symbol carrying CSI-RS + float epre; ///< Linear EPRE + cf_t corr; ///< Correlation + float delay_us; ///< Estimated average delay + uint32_t nof_re; ///< Total number of resource elements +} csi_rs_nzp_resource_measure_t; + +static int csi_rs_nzp_measure_resource(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_resource_t* resource, + const cf_t* grid, + csi_rs_nzp_resource_measure_t* measure) +{ // Force CDM group to 0 uint32_t j = 0; + // Get subcarrier indexes uint32_t k_list[CSI_RS_MAX_SUBC_PRB]; int nof_k = csi_rs_location_get_k_list(&resource->resource_mapping, j, k_list); if (nof_k <= 0) { return SRSRAN_ERROR; } + // Calculate average CSI-RS RE stride + float avg_k_stride = (float)((k_list[0] + SRSRAN_NRE) - k_list[nof_k - 1]); + for (uint32_t i = 1; i < (uint32_t)nof_k; i++) { + avg_k_stride += (float)(k_list[i] - k_list[i - 1]); + } + avg_k_stride /= (float)nof_k; + if (!isnormal(avg_k_stride)) { + ERROR("Invalid avg_k_stride"); + return SRSRAN_ERROR; + } + + // Get symbol indexes uint32_t l_list[CSI_RS_MAX_SYMBOLS_SLOT]; int nof_l = csi_rs_location_get_l_list(&resource->resource_mapping, j, l_list); if (nof_l <= 0) { @@ -442,11 +493,18 @@ int srsran_csi_rs_nzp_measure(const srsran_carrier_nr_t* carrier, uint32_t rb_end = csi_rs_rb_end(carrier, &resource->resource_mapping); uint32_t rb_stride = csi_rs_rb_stride(&resource->resource_mapping); - // Accumulators - float epre_acc = 0.0f; - cf_t rsrp_acc = 0.0f; - uint32_t count = 0; + // Calculate ideal number of RE per symbol + uint32_t nof_re = csi_rs_count(resource->resource_mapping.density, rb_end - rb_begin); + // Accumulators + float epre_acc = 0.0f; + cf_t corr_acc = 0.0f; + float delay_acc = 0.0f; + + // Initialise measurement + SRSRAN_MEM_ZERO(measure, csi_rs_nzp_resource_measure_t, 1); + + // Iterate time symbols for (int l_idx = 0; l_idx < nof_l; l_idx++) { // Get symbol index uint32_t l = l_list[l_idx]; @@ -459,61 +517,459 @@ int srsran_csi_rs_nzp_measure(const srsran_carrier_nr_t* carrier, // Skip unallocated RB srsran_sequence_state_advance(&sequence_state, 2 * csi_rs_count(resource->resource_mapping.density, rb_begin)); - // Temporal R sequence - cf_t r[64]; - uint32_t r_idx = 64; + // Temporal Least Square Estimates + cf_t lse[CSI_RS_MAX_SUBC_PRB * SRSRAN_MAX_PRB_NR]; + uint32_t count_re = 0; - // Iterate over frequency domain + // Extract RE for (uint32_t n = rb_begin; n < rb_end; n += rb_stride) { for (uint32_t k_idx = 0; k_idx < nof_k; k_idx++) { // Calculate sub-carrier index k uint32_t k = SRSRAN_NRE * n + k_list[k_idx]; - // Do we need more r? - if (r_idx >= 64) { - // ... Generate a bunch of it! - srsran_sequence_state_gen_f(&sequence_state, M_SQRT1_2, (float*)r, 64 * 2); - r_idx = 0; - } - - // Take CSI-RS from grid and measure - cf_t tmp = grid[l * SRSRAN_NRE * carrier->nof_prb + k] * conjf(r[r_idx++]); - rsrp_acc += tmp; - epre_acc += __real__ tmp * __real__ tmp + __imag__ tmp * __imag__ tmp; - count++; + lse[count_re++] = grid[l * SRSRAN_NRE * carrier->nof_prb + k]; } } - } - if (count) { - measure->epre = epre_acc / (float)count; - rsrp_acc /= (float)count; - measure->rsrp = (__real__ rsrp_acc * __real__ rsrp_acc + __imag__ rsrp_acc * __imag__ rsrp_acc); - if (measure->epre > measure->rsrp) { - measure->n0 = measure->epre - measure->rsrp; - } else { - measure->n0 = 0.0f; + // Verify RE count matches the expected number of RE + if (count_re == 0 || count_re != nof_re) { + ERROR("Unmatched number of RE (%d != %d)", count_re, nof_re); + return SRSRAN_ERROR; } + + // Compute LSE + srsran_sequence_state_apply_f(&sequence_state, (float*)lse, (float*)lse, 2 * count_re); + + // Compute EPRE + epre_acc += srsran_vec_avg_power_cf(lse, count_re); + + // Compute correlation + corr_acc += srsran_vec_acc_cc(lse, count_re) / (float)count_re; + + // Compute average delay + delay_acc += srsran_vec_estimate_frequency(lse, count_re); } - measure->rsrp_dB = srsran_convert_power_to_dB(measure->rsrp); - measure->epre_dB = srsran_convert_power_to_dB(measure->epre); - measure->n0_dB = srsran_convert_power_to_dB(measure->n0); - measure->snr_dB = measure->rsrp_dB - measure->n0_dB; - measure->nof_re = count; + // Set measure fields + measure->cri = resource->id; + measure->l0 = l_list[0]; + measure->epre = epre_acc / (float)nof_l; + measure->corr = corr_acc / (float)nof_l; + measure->delay_us = 1e6f * delay_acc / ((float)nof_l * SRSRAN_SUBC_SPACING_NR(carrier->scs)); + measure->nof_re = nof_l * nof_re; return SRSRAN_SUCCESS; } -uint32_t srsran_csi_rs_measure_info(const srsran_csi_rs_measure_t* measure, char* str, uint32_t str_len) +static int csi_rs_nzp_measure_set(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + const cf_t* grid, + csi_rs_nzp_resource_measure_t measurements[SRSRAN_PHCH_CFG_MAX_NOF_CSI_RS_PER_SET]) { - return srsran_print_check(str, - str_len, - 0, - "rsrp=%+.1f, epre=%+.1f, n0=%+.1f, snr=%+.1f, nof_re=%d", - measure->rsrp_dB, - measure->epre_dB, - measure->n0_dB, - measure->snr_dB, - measure->nof_re); + uint32_t count = 0; + + // Iterate all resources in set + for (uint32_t i = 0; i < set->count; i++) { + // Skip resource + if (!srsran_csi_rs_send(&set->data[i].periodicity, slot_cfg)) { + continue; + } + + // Perform measurement + if (csi_rs_nzp_measure_resource(carrier, slot_cfg, &set->data[i], grid, &measurements[count]) < SRSRAN_SUCCESS) { + ERROR("Error measuring NZP-CSI-RS resource"); + return SRSRAN_ERROR; + } + count++; + } + + return count; +} + +int srsran_csi_rs_nzp_measure(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_resource_t* resource, + const cf_t* grid, + srsran_csi_rs_nzp_measure_t* measure) +{ + if (carrier == NULL || slot_cfg == NULL || resource == NULL || grid == NULL || measure == NULL) { + return SRSRAN_ERROR; + } + + csi_rs_nzp_resource_measure_t m = {}; + if (csi_rs_nzp_measure_resource(carrier, slot_cfg, resource, grid, &m) < SRSRAN_SUCCESS) { + ERROR("Error measuring NZP-CSI-RS resource"); + return SRSRAN_ERROR; + } + + // Copy measurements + measure->epre = m.epre; + measure->rsrp = (__real__ m.corr * __real__ m.corr + __imag__ m.corr * __imag__ m.corr); + measure->delay_us = m.delay_us; + measure->nof_re = m.nof_re; + + // Estimate noise from EPRE and RSPR + if (measure->epre > measure->rsrp) { + measure->n0 = measure->epre - measure->rsrp; + } else { + measure->n0 = 0.0f; + } + + // CFo cannot be estimated with a single resource + measure->cfo_hz = 0.0f; + measure->cfo_hz_max = 0.0f; + + // Calculate logarithmic measurements + measure->rsrp_dB = srsran_convert_power_to_dB(measure->rsrp); + measure->epre_dB = srsran_convert_power_to_dB(measure->epre); + measure->n0_dB = srsran_convert_power_to_dB(measure->n0); + measure->snr_dB = measure->rsrp_dB - measure->n0_dB; + + return SRSRAN_SUCCESS; +} + +int srsran_csi_rs_nzp_measure_trs(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + const cf_t* grid, + srsran_csi_rs_nzp_measure_t* measure) +{ + // Verify inputs + if (carrier == NULL || slot_cfg == NULL || set == NULL || grid == NULL || measure == NULL) { + return SRSRAN_ERROR; + } + + // Verify it is a TRS set + if (!set->trs_info) { + ERROR("The set is not configured as TRS"); + return SRSRAN_ERROR; + } + + // Perform Measurements + csi_rs_nzp_resource_measure_t measurements[SRSRAN_PHCH_CFG_MAX_NOF_CSI_RS_PER_SET]; + int ret = csi_rs_nzp_measure_set(carrier, slot_cfg, set, grid, measurements); + if (ret < SRSRAN_SUCCESS) { + ERROR("Error performing measurements"); + } + uint32_t count = (uint32_t)ret; + + // No NZP-CSI-RS has been scheduled for this slot + if (count == 0) { + return 0; + } + + // Make sure at least 2 measurements are scheduled + if (count < 2) { + ERROR("Not enough NZP-CSI-RS (%d) have been scheduled for this slot", count); + return SRSRAN_ERROR; + } + + // Make sure initial simbols are in ascending order + for (uint32_t i = 1; i < count; i++) { + if (measurements[i].l0 <= measurements[i - 1].l0) { + ERROR("NZP-CSI-RS are not in ascending order (%d <= %d)", measurements[i].l0, measurements[i - 1].l0); + return SRSRAN_ERROR; + } + } + + // Average measurements + float epre_sum = 0.0f; + float rsrp_sum = 0.0f; + float delay_sum = 0.0f; + uint32_t nof_re = 0; + for (uint32_t i = 0; i < count; i++) { + epre_sum += measurements[i].epre / (float)count; + rsrp_sum += (__real__ measurements[i].corr * __real__ measurements[i].corr + + __imag__ measurements[i].corr * __imag__ measurements[i].corr) / + (float)count; + delay_sum += measurements[i].delay_us / (float)count; + nof_re += measurements[i].nof_re; + } + + // Compute CFO + float cfo_sum = 0.0f; + float cfo_max = 0.0f; + for (uint32_t i = 1; i < count; i++) { + float time_diff = srsran_symbol_distance_s(measurements[i - 1].l0, measurements[i].l0, carrier->scs); + float phase_diff = cargf(measurements[i].corr * conjf(measurements[i - 1].corr)); + float cfo_max_temp = 0.0f; + + // Avoid zero division + if (isnormal(time_diff)) { + // Calculate maximum CFO from this pair of symbols + cfo_max_temp = 1.0f / time_diff; + + // Calculate the actual CFO of this pair of symbols + cfo_sum += phase_diff / (2.0f * M_PI * time_diff * (count - 1)); + } + + // Select the lowest CFO + cfo_max = SRSRAN_MIN(cfo_max_temp, cfo_max); + } + + // Copy measurements + measure->epre = epre_sum; + measure->rsrp = rsrp_sum; + measure->delay_us = delay_sum; + measure->cfo_hz = cfo_sum; + measure->cfo_hz_max = cfo_max; + measure->nof_re = nof_re; + + // Estimate noise from EPRE and RSPR + if (measure->epre > measure->rsrp) { + measure->n0 = measure->epre - measure->rsrp; + } else { + measure->n0 = 0.0f; + } + + // Calculate logarithmic measurements + measure->rsrp_dB = srsran_convert_power_to_dB(measure->rsrp); + measure->epre_dB = srsran_convert_power_to_dB(measure->epre); + measure->n0_dB = srsran_convert_power_to_dB(measure->n0); + measure->snr_dB = measure->rsrp_dB - measure->n0_dB; + + return count; +} + +int srsran_csi_rs_nzp_measure_channel(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_set_t* set, + const cf_t* grid, + srsran_csi_measurements_t* measure) +{ + // Verify inputs + if (carrier == NULL || slot_cfg == NULL || set == NULL || grid == NULL || measure == NULL) { + return SRSRAN_ERROR; + } + + // Perform Measurements + csi_rs_nzp_resource_measure_t measurements[SRSRAN_PHCH_CFG_MAX_NOF_CSI_RS_PER_SET]; + int ret = csi_rs_nzp_measure_set(carrier, slot_cfg, set, grid, measurements); + if (ret < SRSRAN_SUCCESS) { + ERROR("Error performing measurements"); + } + uint32_t count = (uint32_t)ret; + + // No NZP-CSI-RS has been scheduled for this slot + if (count == 0) { + return 0; + } + + // Average measurements + float epre_sum = 0.0f; + float rsrp_sum = 0.0f; + for (uint32_t i = 0; i < count; i++) { + epre_sum += measurements[i].epre / (float)count; + rsrp_sum += (__real__ measurements[i].corr * __real__ measurements[i].corr + + __imag__ measurements[i].corr * __imag__ measurements[i].corr) / + (float)count; + } + + // Estimate noise from EPRE and RSPR + float n0 = 0.0f; + if (epre_sum > rsrp_sum) { + n0 = epre_sum - rsrp_sum; + } + float n0_db = srsran_convert_power_to_dB(n0); + + // Set measurements + measure->cri = measurements[0].cri; + measure->wideband_rsrp_dBm = srsran_convert_power_to_dB(rsrp_sum); + measure->wideband_epre_dBm = srsran_convert_power_to_dB(epre_sum); + measure->wideband_snr_db = measure->wideband_rsrp_dBm - n0_db; + + // Set other parameters + measure->K_csi_rs = count; + measure->nof_ports = 1; // No other value is currently supported + + // Return the number of active resources for this slot + return count; +} + +/** + * @brief Internal ZP-CSI-RS measurement structure + */ +typedef struct { + uint32_t cri; ///< CSI-RS resource identifier + uint32_t l0; ///< First OFDM symbol carrying CSI-RS + float epre; ///< Linear EPRE + uint32_t nof_re; ///< Total number of resource elements +} csi_rs_zp_resource_measure_t; + +static int csi_rs_zp_measure_resource(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_zp_resource_t* resource, + const cf_t* grid, + csi_rs_zp_resource_measure_t* measure) +{ + // Force CDM group to 0 + uint32_t j = 0; + + // Get subcarrier indexes + uint32_t k_list[CSI_RS_MAX_SUBC_PRB]; + int nof_k = csi_rs_location_get_k_list(&resource->resource_mapping, j, k_list); + if (nof_k <= 0) { + return SRSRAN_ERROR; + } + + // Calculate average CSI-RS RE stride + float avg_k_stride = (float)((k_list[0] + SRSRAN_NRE) - k_list[nof_k - 1]); + for (uint32_t i = 1; i < (uint32_t)nof_k; i++) { + avg_k_stride += (float)(k_list[i] - k_list[i - 1]); + } + avg_k_stride /= (float)nof_k; + if (!isnormal(avg_k_stride)) { + ERROR("Invalid avg_k_stride"); + return SRSRAN_ERROR; + } + + // Get symbol indexes + uint32_t l_list[CSI_RS_MAX_SYMBOLS_SLOT]; + int nof_l = csi_rs_location_get_l_list(&resource->resource_mapping, j, l_list); + if (nof_l <= 0) { + return SRSRAN_ERROR; + } + + // Calculate Resource Block boundaries + uint32_t rb_begin = csi_rs_rb_begin(carrier, &resource->resource_mapping); + uint32_t rb_end = csi_rs_rb_end(carrier, &resource->resource_mapping); + uint32_t rb_stride = csi_rs_rb_stride(&resource->resource_mapping); + + // Calculate ideal number of RE per symbol + uint32_t nof_re = csi_rs_count(resource->resource_mapping.density, rb_end - rb_begin); + + // Accumulators + float epre_acc = 0.0f; + + // Initialise measurement + SRSRAN_MEM_ZERO(measure, csi_rs_zp_resource_measure_t, 1); + + // Iterate time symbols + for (int l_idx = 0; l_idx < nof_l; l_idx++) { + // Get symbol index + uint32_t l = l_list[l_idx]; + + // Temporal Least Square Estimates + cf_t temp[CSI_RS_MAX_SUBC_PRB * SRSRAN_MAX_PRB_NR]; + uint32_t count_re = 0; + + // Extract RE + for (uint32_t n = rb_begin; n < rb_end; n += rb_stride) { + for (uint32_t k_idx = 0; k_idx < nof_k; k_idx++) { + // Calculate sub-carrier index k + uint32_t k = SRSRAN_NRE * n + k_list[k_idx]; + + temp[count_re++] = grid[l * SRSRAN_NRE * carrier->nof_prb + k]; + } + } + + // Verify RE count matches the expected number of RE + if (count_re == 0 || count_re != nof_re) { + ERROR("Unmatched number of RE (%d != %d)", count_re, nof_re); + return SRSRAN_ERROR; + } + + // Compute EPRE + epre_acc += srsran_vec_avg_power_cf(temp, count_re); + } + + // Set measure fields + measure->cri = resource->id; + measure->l0 = l_list[0]; + measure->epre = epre_acc / (float)nof_l; + measure->nof_re = nof_l * nof_re; + + return SRSRAN_SUCCESS; +} + +static int csi_rs_zp_measure_set(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_zp_set_t* set, + const cf_t* grid, + csi_rs_zp_resource_measure_t measurements[SRSRAN_PHCH_CFG_MAX_NOF_CSI_RS_PER_SET]) +{ + uint32_t count = 0; + + // Iterate all resources in set + for (uint32_t i = 0; i < set->count; i++) { + // Skip resource + if (!srsran_csi_rs_send(&set->data[i].periodicity, slot_cfg)) { + continue; + } + + // Perform measurement + if (csi_rs_zp_measure_resource(carrier, slot_cfg, &set->data[i], grid, &measurements[count]) < SRSRAN_SUCCESS) { + ERROR("Error measuring NZP-CSI-RS resource"); + return SRSRAN_ERROR; + } + count++; + } + + return count; +} + +int srsran_csi_rs_zp_measure_channel(const srsran_carrier_nr_t* carrier, + const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_zp_set_t* set, + const cf_t* grid, + srsran_csi_measurements_t* measure) +{ + // Verify inputs + if (carrier == NULL || slot_cfg == NULL || set == NULL || grid == NULL || measure == NULL) { + return SRSRAN_ERROR; + } + + // Perform Measurements + csi_rs_zp_resource_measure_t measurements[SRSRAN_PHCH_CFG_MAX_NOF_CSI_RS_PER_SET]; + int ret = csi_rs_zp_measure_set(carrier, slot_cfg, set, grid, measurements); + if (ret < SRSRAN_SUCCESS) { + ERROR("Error performing measurements"); + } + uint32_t count = (uint32_t)ret; + + // No NZP-CSI-RS has been scheduled for this slot + if (count == 0) { + return 0; + } + + // Average measurements + float epre_sum = 0.0f; + for (uint32_t i = 0; i < count; i++) { + epre_sum += measurements[i].epre / (float)count; + } + + // Set measurements + measure->cri = measurements[0].cri; + measure->wideband_rsrp_dBm = NAN; + measure->wideband_epre_dBm = srsran_convert_power_to_dB(epre_sum); + measure->wideband_snr_db = NAN; + + // Set other parameters + measure->K_csi_rs = count; + measure->nof_ports = 1; // No other value is currently supported + + // Return the number of active resources for this slot + return count; +} + +uint32_t srsran_csi_rs_measure_info(const srsran_csi_rs_nzp_measure_t* measure, char* str, uint32_t str_len) +{ + uint32_t len = 0; + + len = srsran_print_check(str, + str_len, + len, + "rsrp=%+.1f epre=%+.1f n0=%+.1f snr=%+.1f delay_us=%+.1f ", + measure->rsrp_dB, + measure->epre_dB, + measure->n0_dB, + measure->snr_dB); + + // Append measured CFO and the maximum CFO that can be measured + if (isnormal(measure->cfo_hz_max)) { + len = srsran_print_check(str, str_len, len, "cfo_hz=%+.1f cfo_hz_max=%+.1f", measure->cfo_hz, measure->cfo_hz_max); + } + + return len; } \ No newline at end of file diff --git a/lib/src/phy/ch_estimation/test/csi_rs_test.c b/lib/src/phy/ch_estimation/test/csi_rs_test.c index 4552f32a1..095b0774e 100644 --- a/lib/src/phy/ch_estimation/test/csi_rs_test.c +++ b/lib/src/phy/ch_estimation/test/csi_rs_test.c @@ -34,15 +34,15 @@ static uint32_t start_rb = UINT32_MAX; static uint32_t nof_rb = UINT32_MAX; static uint32_t first_symbol = UINT32_MAX; -static int test(const srsran_slot_cfg_t* slot_cfg, - const srsran_csi_rs_nzp_resource_t* resource, - srsran_channel_awgn_t* awgn, - cf_t* grid) +static int nzp_test_case(const srsran_slot_cfg_t* slot_cfg, + const srsran_csi_rs_nzp_resource_t* resource, + srsran_channel_awgn_t* awgn, + cf_t* grid) { - srsran_csi_rs_measure_t measure = {}; + srsran_csi_rs_nzp_measure_t measure = {}; // Put NZP-CSI-RS - TESTASSERT(srsran_csi_rs_nzp_put(&carrier, slot_cfg, resource, grid) == SRSRAN_SUCCESS); + TESTASSERT(srsran_csi_rs_nzp_put_resource(&carrier, slot_cfg, resource, grid) == SRSRAN_SUCCESS); // Configure N0 and add Noise TESTASSERT(srsran_channel_awgn_set_n0(awgn, (float)resource->power_control_offset - snr_dB) == SRSRAN_SUCCESS); @@ -69,6 +69,267 @@ static int test(const srsran_slot_cfg_t* slot_cfg, return SRSRAN_SUCCESS; } +static int nzp_test_brute(srsran_channel_awgn_t* awgn, cf_t* grid) +{ + // Slot configuration + srsran_slot_cfg_t slot_cfg = {}; + + // Initialise NZP-CSI-RS fix parameters, other params are not implemented + srsran_csi_rs_nzp_resource_t resource = {}; + resource.resource_mapping.cdm = srsran_csi_rs_cdm_nocdm; + resource.resource_mapping.density = srsran_csi_rs_resource_mapping_density_three; + resource.resource_mapping.row = srsran_csi_rs_resource_mapping_row_1; + resource.resource_mapping.nof_ports = 1; + + // Row 1 supported only! + uint32_t nof_freq_dom_alloc = SRSRAN_CSI_RS_NOF_FREQ_DOMAIN_ALLOC_ROW1; + + uint32_t first_symbol_begin = (first_symbol != UINT32_MAX) ? first_symbol : 0; + uint32_t first_symbol_end = (first_symbol != UINT32_MAX) ? first_symbol : 13; + for (resource.resource_mapping.first_symbol_idx = first_symbol_begin; + resource.resource_mapping.first_symbol_idx <= first_symbol_end; + resource.resource_mapping.first_symbol_idx++) { + // Iterate over possible power control offset + float power_control_offset_begin = isnormal(power_control_offset) ? power_control_offset : -8.0f; + float power_control_offset_end = isnormal(power_control_offset) ? power_control_offset : 15.0f; + for (resource.power_control_offset = power_control_offset_begin; + resource.power_control_offset <= power_control_offset_end; + resource.power_control_offset += 1.0f) { + // Iterate over all possible starting number of PRB + uint32_t start_rb_begin = (start_rb != UINT32_MAX) ? start_rb : 0; + uint32_t start_rb_end = (start_rb != UINT32_MAX) ? start_rb : carrier.nof_prb - 24; + for (resource.resource_mapping.freq_band.start_rb = start_rb_begin; + resource.resource_mapping.freq_band.start_rb <= start_rb_end; + resource.resource_mapping.freq_band.start_rb += 4) { + // Iterate over all possible number of PRB + uint32_t nof_rb_begin = (nof_rb != UINT32_MAX) ? nof_rb : 24; + uint32_t nof_rb_end = + (nof_rb != UINT32_MAX) ? nof_rb : (carrier.nof_prb - resource.resource_mapping.freq_band.start_rb); + for (resource.resource_mapping.freq_band.nof_rb = nof_rb_begin; + resource.resource_mapping.freq_band.nof_rb <= nof_rb_end; + resource.resource_mapping.freq_band.nof_rb += 4) { + // Iterate for all slot numbers + for (slot_cfg.idx = 0; slot_cfg.idx < SRSRAN_NSLOTS_PER_FRAME_NR(carrier.scs); slot_cfg.idx++) { + // Steer Frequency allocation + for (uint32_t freq_dom_alloc = 0; freq_dom_alloc < nof_freq_dom_alloc; freq_dom_alloc++) { + for (uint32_t i = 0; i < nof_freq_dom_alloc; i++) { + resource.resource_mapping.frequency_domain_alloc[i] = i == freq_dom_alloc; + } + + // Call actual test + TESTASSERT(nzp_test_case(&slot_cfg, &resource, awgn, grid) == SRSRAN_SUCCESS); + } + } + } + } + } + } + + return SRSRAN_SUCCESS; +} + +static int nzp_test_trs(srsran_channel_awgn_t* awgn, cf_t* grid) +{ + // Slot configuration + srsran_slot_cfg_t slot_cfg = {}; + + // Item 1 + // NZP-CSI-RS-Resource + // nzp-CSI-RS-ResourceId: 1 + // resourceMapping + // frequencyDomainAllocation: row1 (0) + // row1: 10 [bit length 4, 4 LSB pad bits, 0001 .... decimal value 1] + // nrofPorts: p1 (0) + // firstOFDMSymbolInTimeDomain: 4 + // cdm-Type: noCDM (0) + // density: three (2) + // three: NULL + // freqBand + // startingRB: 0 + // nrofRBs: 52 + // powerControlOffset: 0dB + // powerControlOffsetSS: db0 (1) + // scramblingID: 0 + // periodicityAndOffset: slots40 (7) + // slots40: 11 + // qcl-InfoPeriodicCSI-RS: 0 + srsran_csi_rs_nzp_resource_t resource1 = {}; + resource1.id = 1; + resource1.resource_mapping.frequency_domain_alloc[0] = 0; + resource1.resource_mapping.frequency_domain_alloc[1] = 0; + resource1.resource_mapping.frequency_domain_alloc[2] = 0; + resource1.resource_mapping.frequency_domain_alloc[3] = 1; + resource1.resource_mapping.nof_ports = 1; + resource1.resource_mapping.first_symbol_idx = 4; + resource1.resource_mapping.cdm = srsran_csi_rs_cdm_nocdm; + resource1.resource_mapping.density = srsran_csi_rs_resource_mapping_density_three; + resource1.resource_mapping.freq_band.start_rb = 0; + resource1.resource_mapping.freq_band.nof_rb = carrier.nof_prb; + resource1.power_control_offset = 0; + resource1.power_control_offset_ss = 0; + resource1.periodicity.period = 40; + resource1.periodicity.offset = 11; + + // Item 2 + // NZP-CSI-RS-Resource + // nzp-CSI-RS-ResourceId: 2 + // resourceMapping + // frequencyDomainAllocation: row1 (0) + // row1: 10 [bit length 4, 4 LSB pad bits, 0001 .... decimal value 1] + // nrofPorts: p1 (0) + // firstOFDMSymbolInTimeDomain: 8 + // cdm-Type: noCDM (0) + // density: three (2) + // three: NULL + // freqBand + // startingRB: 0 + // nrofRBs: 52 + // powerControlOffset: 0dB + // powerControlOffsetSS: db0 (1) + // scramblingID: 0 + // periodicityAndOffset: slots40 (7) + // slots40: 11 + // qcl-InfoPeriodicCSI-RS: 0 + srsran_csi_rs_nzp_resource_t resource2 = {}; + resource2.id = 1; + resource2.resource_mapping.frequency_domain_alloc[0] = 0; + resource2.resource_mapping.frequency_domain_alloc[1] = 0; + resource2.resource_mapping.frequency_domain_alloc[2] = 0; + resource2.resource_mapping.frequency_domain_alloc[3] = 1; + resource2.resource_mapping.nof_ports = 1; + resource2.resource_mapping.first_symbol_idx = 8; + resource2.resource_mapping.cdm = srsran_csi_rs_cdm_nocdm; + resource2.resource_mapping.density = srsran_csi_rs_resource_mapping_density_three; + resource2.resource_mapping.freq_band.start_rb = 0; + resource2.resource_mapping.freq_band.nof_rb = carrier.nof_prb; + resource2.power_control_offset = 0; + resource2.power_control_offset_ss = 0; + resource2.periodicity.period = 40; + resource2.periodicity.offset = 11; + + // Item 3 + // NZP-CSI-RS-Resource + // nzp-CSI-RS-ResourceId: 3 + // resourceMapping + // frequencyDomainAllocation: row1 (0) + // row1: 10 [bit length 4, 4 LSB pad bits, 0001 .... decimal value 1] + // nrofPorts: p1 (0) + // firstOFDMSymbolInTimeDomain: 4 + // cdm-Type: noCDM (0) + // density: three (2) + // three: NULL + // freqBand + // startingRB: 0 + // nrofRBs: 52 + // powerControlOffset: 0dB + // powerControlOffsetSS: db0 (1) + // scramblingID: 0 + // periodicityAndOffset: slots40 (7) + // slots40: 12 + // qcl-InfoPeriodicCSI-RS: 0 + srsran_csi_rs_nzp_resource_t resource3 = {}; + resource3.id = 1; + resource3.resource_mapping.frequency_domain_alloc[0] = 0; + resource3.resource_mapping.frequency_domain_alloc[1] = 0; + resource3.resource_mapping.frequency_domain_alloc[2] = 0; + resource3.resource_mapping.frequency_domain_alloc[3] = 1; + resource3.resource_mapping.nof_ports = 1; + resource3.resource_mapping.first_symbol_idx = 4; + resource3.resource_mapping.cdm = srsran_csi_rs_cdm_nocdm; + resource3.resource_mapping.density = srsran_csi_rs_resource_mapping_density_three; + resource3.resource_mapping.freq_band.start_rb = 0; + resource3.resource_mapping.freq_band.nof_rb = carrier.nof_prb; + resource3.power_control_offset = 0; + resource3.power_control_offset_ss = 0; + resource3.periodicity.period = 40; + resource3.periodicity.offset = 12; + + // Item 4 + // NZP-CSI-RS-Resource + // nzp-CSI-RS-ResourceId: 4 + // resourceMapping + // frequencyDomainAllocation: row1 (0) + // row1: 10 [bit length 4, 4 LSB pad bits, 0001 .... decimal value 1] + // nrofPorts: p1 (0) + // firstOFDMSymbolInTimeDomain: 8 + // cdm-Type: noCDM (0) + // density: three (2) + // three: NULL + // freqBand + // startingRB: 0 + // nrofRBs: 52 + // powerControlOffset: 0dB + // powerControlOffsetSS: db0 (1) + // scramblingID: 0 + // periodicityAndOffset: slots40 (7) + // slots40: 12 + // qcl-InfoPeriodicCSI-RS: 0 + srsran_csi_rs_nzp_resource_t resource4 = {}; + resource4.id = 1; + resource4.resource_mapping.frequency_domain_alloc[0] = 0; + resource4.resource_mapping.frequency_domain_alloc[1] = 0; + resource4.resource_mapping.frequency_domain_alloc[2] = 0; + resource4.resource_mapping.frequency_domain_alloc[3] = 1; + resource4.resource_mapping.nof_ports = 1; + resource4.resource_mapping.first_symbol_idx = 8; + resource4.resource_mapping.cdm = srsran_csi_rs_cdm_nocdm; + resource4.resource_mapping.density = srsran_csi_rs_resource_mapping_density_three; + resource4.resource_mapping.freq_band.start_rb = 0; + resource4.resource_mapping.freq_band.nof_rb = carrier.nof_prb; + resource4.power_control_offset = 0; + resource4.power_control_offset_ss = 0; + resource4.periodicity.period = 40; + resource4.periodicity.offset = 12; + + // NZP-CSI-RS-ResourceSet + // nzp-CSI-ResourceSetId: 1 + // nzp-CSI-RS-Resources: 4 items + // Item 0 + // NZP-CSI-RS-ResourceId: 1 + // Item 1 + // NZP-CSI-RS-ResourceId: 2 + // Item 2 + // NZP-CSI-RS-ResourceId: 3 + // Item 3 + // NZP-CSI-RS-ResourceId: 4 + // trs-Info: true (0) + srsran_csi_rs_nzp_set_t set = {}; + set.data[set.count++] = resource1; + set.data[set.count++] = resource2; + set.data[set.count++] = resource3; + set.data[set.count++] = resource4; + set.trs_info = true; + + for (slot_cfg.idx = 0; slot_cfg.idx < resource1.periodicity.period; slot_cfg.idx++) { + // Put NZP-CSI-RS TRS signals + int ret = srsran_csi_rs_nzp_put_set(&carrier, &slot_cfg, &set, grid); + + // Check return + if (slot_cfg.idx == 11 || slot_cfg.idx == 12) { + TESTASSERT(ret == 2); + } else { + TESTASSERT(ret == 0); + } + + // Configure N0 and add Noise + TESTASSERT(srsran_channel_awgn_set_n0(awgn, (float)set.data[0].power_control_offset - snr_dB) == SRSRAN_SUCCESS); + srsran_channel_awgn_run_c(awgn, grid, grid, SRSRAN_SLOT_LEN_RE_NR(carrier.nof_prb)); + + // Measure + srsran_csi_rs_nzp_measure_t measure = {}; + ret = srsran_csi_rs_nzp_measure_trs(&carrier, &slot_cfg, &set, grid, &measure); + + // Check return and assert measurement + if (slot_cfg.idx == 11 || slot_cfg.idx == 12) { + TESTASSERT(ret == 2); + } else { + TESTASSERT(ret == 0); + } + } + + return SRSRAN_SUCCESS; +} + static void usage(char* prog) { printf("Usage: %s [recov]\n", prog); @@ -120,10 +381,8 @@ static void parse_args(int argc, char** argv) int main(int argc, char** argv) { - int ret = SRSRAN_ERROR; - srsran_slot_cfg_t slot_cfg = {}; - srsran_csi_rs_nzp_resource_t resource = {}; - srsran_channel_awgn_t awgn = {}; + int ret = SRSRAN_ERROR; + srsran_channel_awgn_t awgn = {}; parse_args(argc, argv); @@ -138,56 +397,12 @@ int main(int argc, char** argv) goto clean_exit; } - // Fixed parameters, other params are not implemented - resource.resource_mapping.cdm = srsran_csi_rs_cdm_nocdm; - resource.resource_mapping.density = srsran_csi_rs_resource_mapping_density_three; - resource.resource_mapping.row = srsran_csi_rs_resource_mapping_row_1; - resource.resource_mapping.nof_ports = 1; + if (nzp_test_brute(&awgn, grid) < SRSRAN_SUCCESS) { + goto clean_exit; + } - // Row 1 supported only! - uint32_t nof_freq_dom_alloc = SRSRAN_CSI_RS_NOF_FREQ_DOMAIN_ALLOC_ROW1; - - uint32_t first_symbol_begin = (first_symbol != UINT32_MAX) ? first_symbol : 0; - uint32_t first_symbol_end = (first_symbol != UINT32_MAX) ? first_symbol : 13; - for (resource.resource_mapping.first_symbol_idx = first_symbol_begin; - resource.resource_mapping.first_symbol_idx <= first_symbol_end; - resource.resource_mapping.first_symbol_idx++) { - // Iterate over possible power control offset - float power_control_offset_begin = isnormal(power_control_offset) ? power_control_offset : -8.0f; - float power_control_offset_end = isnormal(power_control_offset) ? power_control_offset : 15.0f; - for (resource.power_control_offset = power_control_offset_begin; - resource.power_control_offset <= power_control_offset_end; - resource.power_control_offset += 1.0f) { - // Iterate over all possible starting number of PRB - uint32_t start_rb_begin = (start_rb != UINT32_MAX) ? start_rb : 0; - uint32_t start_rb_end = (start_rb != UINT32_MAX) ? start_rb : carrier.nof_prb - 24; - for (resource.resource_mapping.freq_band.start_rb = start_rb_begin; - resource.resource_mapping.freq_band.start_rb <= start_rb_end; - resource.resource_mapping.freq_band.start_rb += 4) { - // Iterate over all possible number of PRB - uint32_t nof_rb_begin = (nof_rb != UINT32_MAX) ? nof_rb : 24; - uint32_t nof_rb_end = - (nof_rb != UINT32_MAX) ? nof_rb : (carrier.nof_prb - resource.resource_mapping.freq_band.start_rb); - for (resource.resource_mapping.freq_band.nof_rb = nof_rb_begin; - resource.resource_mapping.freq_band.nof_rb <= nof_rb_end; - resource.resource_mapping.freq_band.nof_rb += 4) { - // Iterate for all slot numbers - for (slot_cfg.idx = 0; slot_cfg.idx < SRSRAN_NSLOTS_PER_FRAME_NR(carrier.scs); slot_cfg.idx++) { - // Steer Frequency allocation - for (uint32_t freq_dom_alloc = 0; freq_dom_alloc < nof_freq_dom_alloc; freq_dom_alloc++) { - for (uint32_t i = 0; i < nof_freq_dom_alloc; i++) { - resource.resource_mapping.frequency_domain_alloc[i] = i == freq_dom_alloc; - } - - // Call actual test - if (test(&slot_cfg, &resource, &awgn, grid) < SRSRAN_SUCCESS) { - goto clean_exit; - } - } - } - } - } - } + if (nzp_test_trs(&awgn, grid) < SRSRAN_SUCCESS) { + goto clean_exit; } ret = SRSRAN_SUCCESS; @@ -206,4 +421,4 @@ clean_exit: } return ret; -} \ No newline at end of file +}