diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c index e6d2ec301f304e11d2a5bd4aef955985909e6471..f5281beffc4f221089aeb497da291c4e421bacc0 100644 --- a/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c +++ b/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c @@ -3389,11 +3389,9 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, nre=12; //nb_rb*nre = y * 2^x - int16_t x = log2_approx(nb_rb*nre)-1; - //int16_t one_over_y_q15 = (int16_t)((1<<((int32_t)x+15))/((int32_t)nb_rb*(int32_t)nre)); - float y = (float)(nb_rb*nre)/(float)(1<<x); - //printf("1/(nb_rb*nre) = 1/%d = %d*2^(-15) * 2^(-%d)\n",nb_rb*nre,one_over_y_q15,x); - printf("nb_rb*nre = %d = %f * 2^(%d)\n",nb_rb*nre,y,x); + int16_t x = factor2(nb_rb*nre); + int16_t y = (nb_rb*nre)/(1<<x); + printf("nb_rb*nre = %d = %d * 2^(%d)\n",nb_rb*nre,y,x); for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { @@ -3432,8 +3430,7 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, avg[(aatx<<1)+aarx] = (((int32_t*)&avg128D)[0] + ((int32_t*)&avg128D)[1] + ((int32_t*)&avg128D)[2] + - ((int32_t*)&avg128D)[3]); - avg[(aatx<<1)+aarx] = (int32_t) ((float) avg[(aatx<<1)+aarx]/y); + ((int32_t*)&avg128D)[3])/y; printf("Channel level : %d\n",avg[(aatx<<1)+aarx]); } diff --git a/openair1/PHY/TOOLS/defs.h b/openair1/PHY/TOOLS/defs.h index 542b8edba5820b37c9e4d343fef07dfc6715414a..a90a8b718cfc36ec6ccbd3927eae8f70ae3abfea 100644 --- a/openair1/PHY/TOOLS/defs.h +++ b/openair1/PHY/TOOLS/defs.h @@ -338,6 +338,9 @@ uint8_t log2_approx64(unsigned long long int x); int16_t invSqrt(int16_t x); uint32_t angle(struct complex16 perrror); +/// computes the number of factors 2 in x +unsigned char factor2(unsigned int x); + /*!\fn int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot, uint32_t last_pilot, int32_t ignore_prefix); Compensate the phase rotation of the RF. WARNING: This function is currently unused. It has not been tested! diff --git a/openair1/PHY/TOOLS/log2_approx.c b/openair1/PHY/TOOLS/log2_approx.c index 0317a97d2f5d6fa1b3dd068dc97aee9d42612f0d..bd4d5d04ab87fec8fad51b0026163fa1a3bce3c2 100644 --- a/openair1/PHY/TOOLS/log2_approx.c +++ b/openair1/PHY/TOOLS/log2_approx.c @@ -37,6 +37,26 @@ unsigned char log2_approx(unsigned int x) return(l2); } +unsigned char factor2(unsigned int x) +{ + + int i; + unsigned char l2; + + l2=0; + + for (i=0; i<31; i++) + if ((x&(1<<i)) != 0) + break; + + l2 = i; + + //printf("factor2(%d) = %d\n",x,l2); + return(l2); +} + + + unsigned char log2_approx64(unsigned long long int x) {