From 3763d04578da2d763961c59f4de186182644fe8e Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 28 Sep 2021 16:18:43 +0200 Subject: [PATCH] implement helper function to calculate FFT size for a given sampling rate --- lib/include/srsran/phy/common/phy_common_nr.h | 8 +++++ lib/src/phy/common/phy_common_nr.c | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/include/srsran/phy/common/phy_common_nr.h b/lib/include/srsran/phy/common/phy_common_nr.h index 931be19b4..f33d2adfa 100644 --- a/lib/include/srsran/phy/common/phy_common_nr.h +++ b/lib/include/srsran/phy/common/phy_common_nr.h @@ -596,6 +596,14 @@ SRSRAN_API srsran_mcs_table_t srsran_mcs_table_from_str(const char* str); */ SRSRAN_API uint32_t srsran_min_symbol_sz_rb(uint32_t nof_prb); +/** + * @brief Computes the minimum valid symbol size for a given amount of PRB + * @attention The valid FFT sizes are radix 2 and radix 3 between 128 to 4096 points. + * @param nof_prb Number of PRB + * @return The minimum valid FFT size if the number of PRB is in range, 0 otherwise + */ +SRSRAN_API int srsran_symbol_sz_from_srate(double srate_hz, srsran_subcarrier_spacing_t scs); + /** * @brief Computes the time in seconds between the beginning of the slot and the given symbol * @remark All symbol size reference and values are taken from TS 38.211 section 5.3 OFDM baseband signal generation diff --git a/lib/src/phy/common/phy_common_nr.c b/lib/src/phy/common/phy_common_nr.c index 8a5d410df..9f514ccbf 100644 --- a/lib/src/phy/common/phy_common_nr.c +++ b/lib/src/phy/common/phy_common_nr.c @@ -244,6 +244,37 @@ uint32_t srsran_min_symbol_sz_rb(uint32_t nof_prb) return 0; } +int srsran_symbol_sz_from_srate(double srate_hz, srsran_subcarrier_spacing_t scs) +{ + // Make sure srate is valid + if (!isnormal(srate_hz) || srate_hz < 0.0) { + return SRSRAN_ERROR; + } + + // Convert srate to integer and Hz + uint32_t srate_int_hz = (uint32_t)srate_hz; + + // Get subcarrier spacing in Hz + uint32_t scs_int_hz = SRSRAN_SUBC_SPACING_NR(scs); + + // Check the symbol size if a integer + if (srate_int_hz % scs_int_hz != 0) { + ERROR("Invalid sampling rate %.2f MHz with subcarrrier spacing %d kHz", srate_hz / 1e6, scs_int_hz / 1000); + return SRSRAN_ERROR; + } + + // Calculate symbol size in samples + uint32_t symbol_sz = srate_int_hz / scs_int_hz; + + // Verify the symbol size can have an integer cyclic prefix size + if ((symbol_sz * 144U) % 2048 != 0 && (symbol_sz * (16U << (uint32_t)scs)) % 2048 != 0) { + ERROR("The sampling rate %.2f MHz with subcarrrier spacing %d kHz", srate_hz / 1e6, scs_int_hz / 1000); + return SRSRAN_ERROR; + } + + return (int)symbol_sz; +} + float srsran_symbol_offset_s(uint32_t l, srsran_subcarrier_spacing_t scs) { // Compute at what symbol there is a longer CP