From 9e4df97d8409173b4c994e6780d94655f9ff65ed Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Wed, 21 Aug 2024 18:08:29 +0200 Subject: [PATCH] move function add_noise() to file openair1/SIMULATION/TOOLS/phase_noise.c --- openair1/SIMULATION/TOOLS/multipath_channel.c | 25 -------- openair1/SIMULATION/TOOLS/phase_noise.c | 35 +++++++++-- openair1/SIMULATION/TOOLS/sim.h | 62 +++++++++---------- 3 files changed, 60 insertions(+), 62 deletions(-) diff --git a/openair1/SIMULATION/TOOLS/multipath_channel.c b/openair1/SIMULATION/TOOLS/multipath_channel.c index de616bf86c..f17c2166a3 100644 --- a/openair1/SIMULATION/TOOLS/multipath_channel.c +++ b/openair1/SIMULATION/TOOLS/multipath_channel.c @@ -143,31 +143,6 @@ void __attribute__ ((no_sanitize_address)) multipath_channel(channel_desc_t *des #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 uint16_t ptrs_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) * gaussZiggurat(0.0, 1.0); // convert to fixed point - rxd->i = r_im[ap][i] + sqrt(sigma / 2) * gaussZiggurat(0.0, 1.0); - /* Add phase noise if enabled */ - if (pdu_bit_map & ptrs_bit_map) { - phase_noise(ts, &rxdata[ap][slot_offset + i + delay].r, &rxdata[ap][slot_offset + i + delay].i); - } - } - } -} - void __attribute__ ((no_sanitize_address)) 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/phase_noise.c b/openair1/SIMULATION/TOOLS/phase_noise.c index 8c2b36dfec..fa406e7ff9 100644 --- a/openair1/SIMULATION/TOOLS/phase_noise.c +++ b/openair1/SIMULATION/TOOLS/phase_noise.c @@ -22,8 +22,14 @@ #include #include "sim.h" - +#define ResolSinCos 100 static uint16_t LUTSin[ResolSinCos+1]; + +/* Initialisation function for SIN table values */ +void InitSinLUT( void ) { + for ( int i=0; i<(ResolSinCos+1); i++ ) { + LUTSin[i] = sin((double)(M_PI*i)/(2*ResolSinCos)) * (1<<14); //Format: Q14 + /* linear phase noise model */ void phase_noise(double ts, int16_t * InRe, int16_t * InIm) { @@ -61,9 +67,28 @@ void phase_noise(double ts, int16_t * InRe, int16_t * InIm) InIm[0]= (int16_t)(y>>14); i++; } -/* Initialisation function for SIN table values */ -void InitSinLUT( void ) { - for ( int i=0; i<(ResolSinCos+1); i++ ) { - LUTSin[i] = sin((double)(M_PI*i)/(2*ResolSinCos)) * (1<<14); //Format: Q14 + +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 uint16_t ptrs_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) * gaussZiggurat(0.0, 1.0); // convert to fixed point + rxd->i = r_im[ap][i] + sqrt(sigma / 2) * gaussZiggurat(0.0, 1.0); + /* Add phase noise if enabled */ + if (pdu_bit_map & ptrs_bit_map) { + phase_noise(ts, &rxdata[ap][slot_offset + i + delay].r, &rxdata[ap][slot_offset + i + delay].i); + } + } } } diff --git a/openair1/SIMULATION/TOOLS/sim.h b/openair1/SIMULATION/TOOLS/sim.h index 34cae4ba55..ffd5bef8ed 100644 --- a/openair1/SIMULATION/TOOLS/sim.h +++ b/openair1/SIMULATION/TOOLS/sim.h @@ -379,32 +379,6 @@ void get_cexp_doppler(struct complexd *cexp_doppler, channel_desc_t *chan_desc, */ 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 ptrs_bit_map -\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 uint16_t ptrs_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], @@ -569,17 +543,41 @@ int load_channellist(uint8_t nb_tx, uint8_t nb_rx, double sampling_rate, uint64_ double N_RB2sampling_rate(uint16_t N_RB); double N_RB2channel_bandwidth(uint16_t N_RB); +void InitSinLUT(void); + /* Linear phase noise model */ -/*! +/** \brief This function produce phase noise and add to input signal - \param ts Sampling time + \param ts Sampling time \param *Re *Im Real and Imag part of the signal */ -//look-up table for the sine (cosine) function -#define ResolSinCos 100 -void InitSinLUT( void ); -void phase_noise(double ts, int16_t * InRe, int16_t * InIm); +void phase_noise(double ts, int16_t *InRe, int16_t *InIm); +/** +\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 ptrs_bit_map +\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 uint16_t ptrs_bit_map, + const uint8_t nb_antennas_rx); void do_DL_sig(sim_t *sim, uint16_t subframe,