diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index d1a06393b4..54c0d42db1 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -305,7 +305,6 @@ int main(int argc, char **argv) int Imcs = 9; uint8_t precod_nbr_layers = 1; int gNB_id = 0; - int ap; int tx_offset; int32_t txlev_sum = 0, atxlev[4]; int start_rb = 0; @@ -1319,17 +1318,7 @@ int main(int argc, char **argv) } else { multipath_tv_channel(UE2gNB, s_re, s_im, r_re, r_im, 2*slot_length, 0); } - - for (i=0; inb_antennas_rx; ap++) { - rxdata[ap][slot_offset+i+delay].r = (int16_t)((r_re[ap][i]) + (sqrt(sigma/2)*gaussdouble(0.0,1.0))); // convert to fixed point - rxdata[ap][slot_offset+i+delay].i = (int16_t)((r_im[ap][i]) + (sqrt(sigma/2)*gaussdouble(0.0,1.0))); - /* Add phase noise if enabled */ - if (pdu_bit_map & PUSCH_PDU_BITMAP_PUSCH_PTRS) { - phase_noise(ts, &rxdata[ap][slot_offset].r, &rxdata[ap][slot_offset].i); - } - } - } + add_noise(rxdata, (const double **) r_re, (const double **) r_im, sigma, slot_length, slot_offset, ts, delay, pdu_bit_map, frame_parms->nb_antennas_rx); } /*End input_fd */ diff --git a/openair1/SIMULATION/TOOLS/multipath_channel.c b/openair1/SIMULATION/TOOLS/multipath_channel.c index cff6f85d46..6adc33b646 100644 --- a/openair1/SIMULATION/TOOLS/multipath_channel.c +++ b/openair1/SIMULATION/TOOLS/multipath_channel.c @@ -23,6 +23,7 @@ #include #include #include +#include "nfapi_nr_interface_scf.h" #include "PHY/TOOLS/tools_defs.h" #include "SIMULATION/RF/rf.h" #include "sim.h" @@ -144,6 +145,31 @@ void multipath_channel(channel_desc_t *desc, } #else + +void add_noise(c16_t **rxdata, + const double **r_re, + const double **r_im, + const double sigma, + const int length, + const int slot_offset, + const double ts, + const int delay, + const uint16_t pdu_bit_map, + const uint8_t nb_antennas_rx) +{ + for (int i = 0; i < length; i++) { + for (int ap = 0; ap < nb_antennas_rx; ap++) { + c16_t *rxd = &rxdata[ap][slot_offset + i + delay]; + rxd->r = r_re[ap][i] + sqrt(sigma / 2) * gaussdouble(0.0, 1.0); // convert to fixed point + rxd->i = r_im[ap][i] + sqrt(sigma / 2) * gaussdouble(0.0, 1.0); + /* Add phase noise if enabled */ + if (pdu_bit_map & PUSCH_PDU_BITMAP_PUSCH_PTRS) { + phase_noise(ts, &rxdata[ap][slot_offset + i + delay].r, &rxdata[ap][slot_offset + i + delay].i); + } + } + } +} + void multipath_channel(channel_desc_t *desc, double *tx_sig_re[NB_ANTENNAS_TX], double *tx_sig_im[NB_ANTENNAS_TX], diff --git a/openair1/SIMULATION/TOOLS/sim.h b/openair1/SIMULATION/TOOLS/sim.h index fc35b5cae5..badb2c3d35 100644 --- a/openair1/SIMULATION/TOOLS/sim.h +++ b/openair1/SIMULATION/TOOLS/sim.h @@ -348,6 +348,30 @@ void set_channeldesc_name(channel_desc_t *cdesc,char *modelname); */ int random_channel(channel_desc_t *desc, uint8_t abstraction_flag); +/** +\brief Add AWGN noise and phase noise if enabled +\param rxdata output data with noise +\param r_re real part of input data without noise +\param r_im imaginary part of input data without noise +\param sigma noise power +\param length number of samples to apply the noise +\param slot_offset slot offset to start applying the noise +\param ts sampling time +\param delay introduce delay in terms of number of samples +\param pdu_bit_map bitmap indicating presence of optional PDUs +\param nb_antennas_rx number of receive antennas +*/ +void add_noise(c16_t **rxdata, + const double **r_re, + const double **r_im, + const double sigma, + const int length, + const int slot_offset, + const double ts, + const int delay, + const uint16_t pdu_bit_map, + const uint8_t nb_antennas_rx); + /**\fn void multipath_channel(channel_desc_t *desc, double tx_sig_re[NB_ANTENNAS_TX], double tx_sig_im[NB_ANTENANS_TX],