diff --git a/radio/rfsimulator/simulator.cpp b/radio/rfsimulator/simulator.cpp index 5c01322fa6..a940f6f023 100644 --- a/radio/rfsimulator/simulator.cpp +++ b/radio/rfsimulator/simulator.cpp @@ -1167,7 +1167,7 @@ static void rfsimulator_read_internal(rfsimulator_state_t *t, int rx_beam_id) { cf_t temp_array[nbAnt][nsamps]; - memset(temp_array, 0, sizeof(temp_array)); + bool channel_modelling = false; // Add all input nodes signal in the output buffer for (int sock = 0; sock < MAX_FD_RFSIMU; sock++) { buffer_t *ptr = &t->buf[sock]; @@ -1182,6 +1182,10 @@ static void rfsimulator_read_internal(rfsimulator_state_t *t, random_channel(ptr->channel_model, 0); if (ptr->channel_model != NULL) { // apply a channel model + if (!channel_modelling) { + memset(temp_array, 0, sizeof(temp_array)); + channel_modelling = true; + } const uint64_t dd = ptr->channel_model->channel_offset; const uint64_t channel_length = ptr->channel_model->channel_length; std::vector> ant_buffers = combine_received_beams(t, @@ -1220,19 +1224,25 @@ static void rfsimulator_read_internal(rfsimulator_state_t *t, bool apply_global_noise = get_noise_power_dBFS() != INVALID_DBFS_VALUE; if (apply_global_noise) { + if (!channel_modelling) { + memset(temp_array, 0, sizeof(temp_array)); + channel_modelling = true; + } + int16_t noise_power = (int16_t)(32767.0 / powf(10.0, .05 * -get_noise_power_dBFS())); for (int a = 0; a < nbAnt; a++) { for (int i = 0; i < nsamps; i++) { - int16_t noise_power = (int16_t)(32767.0 / powf(10.0, .05 * -get_noise_power_dBFS())); temp_array[a][i].r += noise_power + gaussZiggurat(0.0, 1.0); temp_array[a][i].i += noise_power * gaussZiggurat(0.0, 1.0); } } } - for (int a = 0; a < nbAnt; a++) { - for (int i = 0; i < nsamps; i++) { - samples[a][i].r += lroundf(temp_array[a][i].r); - samples[a][i].i += lroundf(temp_array[a][i].i); + if (channel_modelling) { + for (int a = 0; a < nbAnt; a++) { + for (int i = 0; i < nsamps; i++) { + samples[a][i].r += lroundf(temp_array[a][i].r); + samples[a][i].i += lroundf(temp_array[a][i].i); + } } } }