Commit 99463054 authored by Marwan Hammouda's avatar Marwan Hammouda

[develop] Added: LUT for sin/cos and function nr_apply_Doppler()

parent a903ec64
......@@ -738,3 +738,10 @@ uint32_t get_ssb_offset_to_pointA(uint32_t absoluteFrequencySSB,
AssertFatal(sco % scs_scaling == 0, "ssb offset %d can create frequency offset\n", sco);
return ssb_offset_point_a;
}
uint16_t LUTSin[ResolSinCos+1];
void InitSinLUT( void ) {
for ( int i=0; i<(ResolSinCos+1); i++ ) {
LUTSin[i] = sin((double)M_PI/2/ResolSinCos*i) * (1<<14); //Format: Q14
}
}
......@@ -131,4 +131,10 @@ int get_ssb_subcarrier_offset(uint32_t absoluteFrequencySSB, uint32_t absoluteFr
#define min(a,b) cmin(a,b)
#endif
//look-up table for the sine (cosine) function
#define ResolSinCos 100
extern uint16_t LUTSin[ResolSinCos+1];
void InitSinLUT( void );
#endif
......@@ -1224,7 +1224,7 @@ void *ru_thread( void *param ) {
//slot_duration.tv_nsec = 0.5e6;
slot_duration.tv_nsec = 0.5e6;
InitSinLUT();
while (!oai_exit) {
......
......@@ -140,4 +140,9 @@ int nr_layer_precoder_cm(int16_t **datatx_F_precoding,
int *prec_matrix,
uint8_t n_layers,
int32_t re_offset);
// apply frequency offset compensation
void nr_apply_Doppler( void *in, uint32_t len, int32_t fDoppler, uint32_t *SampIdxDoppler, NR_DL_FRAME_PARMS *fp );
#endif
......@@ -26,6 +26,7 @@
#include "PHY/LTE_ESTIMATION/lte_estimation.h"
#include "PHY/NR_UE_ESTIMATION/nr_estimation.h"
#include <common/utils/LOG/log.h>
#include "nr/nr_common.h"
//#define DEBUG_FEP
......@@ -330,3 +331,45 @@ void apply_nr_rotation_RX(NR_DL_FRAME_PARMS *frame_parms,
}
}
}
typedef struct complex16 sample_t; // 2*16 bits complex number
//Apply the givin Doppler shift to the input signal with a fixed number of samples
void nr_apply_Doppler( void *in, uint32_t len, int32_t fDoppler, uint32_t *SampIdxDoppler, NR_DL_FRAME_PARMS *fp ) {
int16_t SinDopper, CosDopper; // sine/cosine value from the LUT
sample_t *sigComp = (sample_t *)in;
for ( int k=0; k < len; k++ ) {
int64_t IdxInt = (int64_t)*SampIdxDoppler * fDoppler * ResolSinCos*4;
IdxInt = IdxInt>0 ? IdxInt+fp->samples_per_frame*100/2 : IdxInt-fp->samples_per_frame*100/2; //rounding
IdxInt = IdxInt / (fp->samples_per_frame*100);
int16_t IdxModulo = IdxInt % (ResolSinCos*4);
IdxModulo = IdxModulo<0 ? IdxModulo+ResolSinCos*4 : IdxModulo;
if ( IdxModulo < 2*ResolSinCos ) {
if ( IdxModulo < ResolSinCos ) {
SinDopper = LUTSin[IdxModulo];
CosDopper = LUTSin[ResolSinCos-IdxModulo];
}
else {
SinDopper = LUTSin[2*ResolSinCos-IdxModulo];
CosDopper = -LUTSin[IdxModulo-ResolSinCos];
}
}
else {
if ( IdxModulo < 3*ResolSinCos ) {
SinDopper = -LUTSin[IdxModulo-2*ResolSinCos];
CosDopper = -LUTSin[3*ResolSinCos-IdxModulo];
}
else {
SinDopper = -LUTSin[4*ResolSinCos-IdxModulo];
CosDopper = LUTSin[IdxModulo-3*ResolSinCos];
}
}
sample_t sigTmp = sigComp[k];
sigComp[k].r= ( (int32_t)sigTmp.r*CosDopper - (int32_t)sigTmp.i*SinDopper )>>14;
sigComp[k].i= ( (int32_t)sigTmp.i*CosDopper + (int32_t)sigTmp.r*SinDopper )>>14;
(*SampIdxDoppler)++;
}
}
\ No newline at end of file
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