implement helper function to calculate FFT size for a given sampling rate

This commit is contained in:
Xavier Arteaga 2021-09-28 16:18:43 +02:00 committed by Andre Puschmann
parent 7496b7c14f
commit 3763d04578
2 changed files with 39 additions and 0 deletions

View File

@ -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

View File

@ -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