Commit b2ae5502 authored by Sagar Parsawar's avatar Sagar Parsawar

Harmonizing abs32, abs64, absF, angle64 functions across LTE/NR

parent 502b4d59
...@@ -131,14 +131,6 @@ void lte_sync_time_free(void) { ...@@ -131,14 +131,6 @@ void lte_sync_time_free(void) {
} }
static inline int abs32(int x) {
return (((int)((short*)&x)[0])*((int)((short*)&x)[0]) + ((int)((short*)&x)[1])*((int)((short*)&x)[1]));
}
static inline double absF(struct complexd x) {
return x.r*x.r+x.i*x.i;
}
#define complexNull(c) bzero((void*) &(c), sizeof(c)) #define complexNull(c) bzero((void*) &(c), sizeof(c))
#define SHIFT 17 #define SHIFT 17
...@@ -368,12 +360,6 @@ int lte_sync_time_eNB(int32_t **rxdata, ///rx data in time domain ...@@ -368,12 +360,6 @@ int lte_sync_time_eNB(int32_t **rxdata, ///rx data in time domain
} }
static inline int64_t abs64(int64_t x) {
return (((int64_t)((int32_t *)&x)[0])*((int64_t)((int32_t *)&x)[0]) + ((int64_t)
((int32_t *)&x)[1])*((int64_t)((int32_t *)&x)[1]));
}
int ru_sync_time(RU_t *ru, int ru_sync_time(RU_t *ru,
int64_t *lev, int64_t *lev,
int64_t *avg) { int64_t *avg) {
......
...@@ -35,16 +35,11 @@ ...@@ -35,16 +35,11 @@
//#define DEBUG_PDSCH //#define DEBUG_PDSCH
//#define DEBUG_PDCCH //#define DEBUG_PDCCH
//#define DEBUG_CH //#define DEBUG_PBCH
//#define DEBUG_PRS_CHEST //#define DEBUG_PRS_CHEST // To enable PRS Matlab dumps
//#define DEBUG_PRS_PRINTS //#define DEBUG_PRS_PRINTS // To enable PRS channel estimation debug logs
extern short nr_qpsk_mod_table[8]; extern short nr_qpsk_mod_table[8];
static inline int abs32(int x)
{
return (((int)((short*)&x)[0])*((int)((short*)&x)[0]) + ((int)((short*)&x)[1])*((int)((short*)&x)[1]));
}
int nr_prs_channel_estimation(uint8_t gNB_id, int nr_prs_channel_estimation(uint8_t gNB_id,
uint8_t rsc_id, uint8_t rsc_id,
uint8_t rep_num, uint8_t rep_num,
...@@ -613,7 +608,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -613,7 +608,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
k = nushift; k = nushift;
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("PBCH DMRS Correlation : ThreadId %d, gNB_id %d , OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",proc->thread_id, gNB_id,ue->frame_parms.ofdm_symbol_size, printf("PBCH DMRS Correlation : ThreadId %d, gNB_id %d , OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",proc->thread_id, gNB_id,ue->frame_parms.ofdm_symbol_size,
ue->frame_parms.Ncp,Ns,k, symbol); ue->frame_parms.Ncp,Ns,k, symbol);
#endif #endif
...@@ -627,7 +622,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -627,7 +622,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
pil = (int16_t *)&pilot[0]; pil = (int16_t *)&pilot[0];
rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL); printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset); printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
printf("rxF addr %p\n", rxF); printf("rxF addr %p\n", rxF);
...@@ -641,7 +636,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -641,7 +636,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
current_ssb->c_re += ch[0]; current_ssb->c_re += ch[0];
current_ssb->c_im += ch[1]; current_ssb->c_im += ch[1];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])); printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
printf("pilot 0 : rxF - > (%d,%d) addr %p ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]); printf("pilot 0 : rxF - > (%d,%d) addr %p ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -657,7 +652,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -657,7 +652,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
current_ssb->c_re += ch[0]; current_ssb->c_re += ch[0];
current_ssb->c_im += ch[1]; current_ssb->c_im += ch[1];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -668,7 +663,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -668,7 +663,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
current_ssb->c_re += ch[0]; current_ssb->c_re += ch[0];
current_ssb->c_im += ch[1]; current_ssb->c_im += ch[1];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -693,7 +688,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -693,7 +688,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
current_ssb->c_re += ch[0]; current_ssb->c_re += ch[0];
current_ssb->c_im += ch[1]; current_ssb->c_im += ch[1];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -708,7 +703,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -708,7 +703,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
current_ssb->c_re += ch[0]; current_ssb->c_re += ch[0];
current_ssb->c_im += ch[1]; current_ssb->c_im += ch[1];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
pil += 2; pil += 2;
...@@ -722,7 +717,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, ...@@ -722,7 +717,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
current_ssb->c_re += ch[0]; current_ssb->c_re += ch[0];
current_ssb->c_im += ch[1]; current_ssb->c_im += ch[1];
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -778,7 +773,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -778,7 +773,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
k = nushift; k = nushift;
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("PBCH Channel Estimation : ThreadId %d, gNB_id %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",proc->thread_id, gNB_id,ch_offset,ue->frame_parms.ofdm_symbol_size, printf("PBCH Channel Estimation : ThreadId %d, gNB_id %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",proc->thread_id, gNB_id,ch_offset,ue->frame_parms.ofdm_symbol_size,
ue->frame_parms.Ncp,Ns,k, symbol); ue->frame_parms.Ncp,Ns,k, symbol);
#endif #endif
...@@ -870,7 +865,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -870,7 +865,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
memset(dl_ch,0,sizeof(struct complex16)*(ue->frame_parms.ofdm_symbol_size)); memset(dl_ch,0,sizeof(struct complex16)*(ue->frame_parms.ofdm_symbol_size));
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL); printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset); printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
printf("rxF addr %p\n", rxF); printf("rxF addr %p\n", rxF);
...@@ -882,7 +877,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -882,7 +877,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])); printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
printf("pilot 0 : rxF - > (%d,%d) addr %p ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]); printf("pilot 0 : rxF - > (%d,%d) addr %p ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -901,7 +896,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -901,7 +896,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
multadd_real_vector_complex_scalar(fm, multadd_real_vector_complex_scalar(fm,
...@@ -915,7 +910,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -915,7 +910,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
...@@ -943,7 +938,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -943,7 +938,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
multadd_real_vector_complex_scalar(fl, multadd_real_vector_complex_scalar(fl,
...@@ -962,7 +957,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -962,7 +957,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
multadd_real_vector_complex_scalar(fm, multadd_real_vector_complex_scalar(fm,
...@@ -976,7 +971,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -976,7 +971,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
#ifdef DEBUG_CH #ifdef DEBUG_PBCH
printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif #endif
......
...@@ -600,24 +600,6 @@ int pss_synchro_nr(PHY_VARS_NR_UE *PHY_vars_UE, int is, int rate_change) ...@@ -600,24 +600,6 @@ int pss_synchro_nr(PHY_VARS_NR_UE *PHY_vars_UE, int is, int rate_change)
} }
static inline int abs32(int x)
{
return (((int)((short*)&x)[0])*((int)((short*)&x)[0]) + ((int)((short*)&x)[1])*((int)((short*)&x)[1]));
}
static inline int64_t abs64(int64_t x)
{
return (((int64_t)((int32_t*)&x)[0])*((int64_t)((int32_t*)&x)[0]) + ((int64_t)((int32_t*)&x)[1])*((int64_t)((int32_t*)&x)[1]));
}
static inline double angle64(int64_t x)
{
double re=((int32_t*)&x)[0];
double im=((int32_t*)&x)[1];
return (atan2(im,re));
}
/******************************************************************* /*******************************************************************
* *
......
...@@ -1113,4 +1113,26 @@ static inline int release_thread(pthread_mutex_t *mutex, ...@@ -1113,4 +1113,26 @@ static inline int release_thread(pthread_mutex_t *mutex,
return(0); return(0);
} }
static inline int32_t abs32(int32_t x)
{
return (((int32_t)((int16_t*)&x)[0])*((int32_t)((int16_t*)&x)[0]) + ((int32_t)((int16_t*)&x)[1])*((int32_t)((int16_t*)&x)[1]));
}
static inline int64_t abs64(int64_t x)
{
return (((int64_t)((int32_t*)&x)[0])*((int64_t)((int32_t*)&x)[0]) + ((int64_t)((int32_t*)&x)[1])*((int64_t)((int32_t*)&x)[1]));
}
static inline double absF(struct complexd x) {
return x.r*x.r+x.i*x.i;
}
static inline double angle64(int64_t x)
{
double re=((int32_t*)&x)[0];
double im=((int32_t*)&x)[1];
return (atan2(im,re));
}
#endif // __PHY_DEFS_COMMON_H__ #endif // __PHY_DEFS_COMMON_H__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment