Commit 11693330 authored by Marwan Hammouda's avatar Marwan Hammouda

[develop] Added: timing offset estimation based on PBCH

    - command-line option to activate/deactivate compensation added
parent 95f1a66c
......@@ -120,6 +120,7 @@
#define CONFIG_HLP_TDRIFT "Set the timing offset/drift per frame in the RF simulator (expressed in number of samples per frame)\n"
#define CONFIG_HLP_FDopplerRate "Set the Doppler rate in Hz/s\n"
#define CONFIG_HLP_FDopplerVar "Set Doppler variance, [fdoppler +/- fdopplerVar]\n"
#define CONFIG_HLP_TDriftComp "Execute continous timing drift compensation\n"
/*--------------------------------------------------------------------------------------------------------------------------------*/
/* command line parameters for LOG utility */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
......@@ -174,5 +175,6 @@ extern int fdopplerComp; // flag to activate/deactivate continous freque
extern int RFsim_DriftPerFrame; //the timing offset/drift per frame in the RF simulator (expressed in number of samples per frame)
extern int32_t fdopplerRate; //Doppler rate in Hz/s
extern uint32_t fdopplerVar; //Doppler variance, [fdoppler +/- fdopplerVar]
extern int tdriftComp; // flag to activate/deactivate continous timing drift compensation
#endif
......@@ -576,6 +576,7 @@ int fdopplerComp = 1;
int RFsim_DriftPerFrame = 0;
int32_t fdopplerRate;
uint32_t fdopplerVar;
int tdriftComp = 1;
int main( int argc, char **argv ) {
int ru_id, CC_id = 0;
......
......@@ -432,6 +432,7 @@ int32_t fdoppler = 0; //center Doppler frequency shift
int32_t fdopplerRate; //Doppler rate in Hz/s
uint32_t fdopplerVar; //Doppler variance, [fdoppler +/- fdopplerVar]
int fdopplerComp = 1; // flag to activate continous frequency offset compensation (=0 deacticated, =1 activated (default case))
int tdriftComp = 1;
int main( int argc, char **argv ) {
......
......@@ -68,9 +68,10 @@
{"ue_k2" , CONFIG_HLP_UEK2, 0, .u16ptr=&NTN_UE_k2, .defintval=0, TYPE_UINT16, 0}, \
{"FD" , CONFIG_HLP_FDoppler, 0, .iptr=&fdoppler, .defintval=0, TYPE_INT, 0}, \
{"FC" , CONFIG_HLP_FDopplerComp, 0, .iptr=&fdopplerComp, .defintval=1, TYPE_INT, 0}, \
{"TD" , CONFIG_HLP_TDRIFT, 0, .iptr=&RFsim_DriftPerFrame, .defintval=0, TYPE_INT, 0}, \
{"TD" , CONFIG_HLP_TDRIFT, 0, .iptr=&RFsim_DriftPerFrame, .defintval=0, TYPE_INT, 0}, \
{"DSR" , CONFIG_HLP_FDopplerRate,0, .iptr=&fdopplerRate, .defintval=0, TYPE_INT32, 0}, \
{"DSV" , CONFIG_HLP_FDopplerVar, 0, .uptr=&fdopplerVar, .defintval=0, TYPE_UINT32, 0}, \
{"TC" , CONFIG_HLP_TDriftComp, 0, .iptr=&tdriftComp, .defintval=1, TYPE_INT, 0}, \
}
// clang-format on
......
......@@ -50,6 +50,11 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
const int sync_pos = 0;
uint8_t sync_offset = 0;
static int64_t TO_I_Ctrl = 0; //Integral controller for TO
int I_ScalingF = 10; //Scaling factor for the I controller, can be adjusted
static int frameLast = 0; //frame number of last call of nr_adjust_synch_ue()
static int FirstFlag = 1; //indicate the first call of nr_adjust_synch_ue()
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_IN);
short ncoef = 32767 - coef;
......@@ -83,16 +88,33 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
//ue->max_pos_fil = max_pos << 15;
int diff = (ue->max_pos_fil >> 15) - sync_pos;
int FrameDiff = (frame-frameLast+1024)%1024;
if (frame_parms->freq_range==nr_FR2)
sync_offset = 2;
if (FirstFlag)
FirstFlag = 0;
else
sync_offset = 0;
diff /= FrameDiff; //scaled by the frame number
frameLast = frame; //save the last frame number
TO_I_Ctrl += diff; //integral of all offsets
ue->rx_offset = diff;
ue->rx_offset_TO = diff+TO_I_Ctrl/I_ScalingF; //PI controller
ue->rx_offset_slot = 1;
ue->rx_offset_comp = 0;
printf("** Frame: %u, ue->rx_offset: %d, ue->rx_offset_TO: %d\n", frame, ue->rx_offset, ue->rx_offset_TO);
if ( abs(diff) < (SYNCH_HYST+sync_offset) )
extern tdriftComp;
{
TO_I_Ctrl += diff; //integral of all offsets
ue->rx_offset = 0;
else
ue->rx_offset = diff;
ue->rx_offset_TO = 0; //PI controller
ue->rx_offset_slot = 1;
ue->rx_offset_comp = 0;
}
if (tdriftComp == 0)
const int sample_shift = -(ue->rx_offset>>1);
// reset IIR filter for next offset calculation
......
......@@ -525,6 +525,9 @@ typedef struct {
int64_t max_pos_fil; /// Timing offset IIR filter
bool apply_timing_offset; /// Do time sync for current frame
int time_sync_cell;
int rx_offset_TO; /// Timing offset used for compensating the time drift due to high speed
int rx_offset_slot; /// Indicating time (in slots) after rx_offset calculation
int rx_offset_comp; /// Already compensated rx_offset
/// Timing Advance updates variables
/// Timing advance update computed from the TA command signalled from gNB
......
......@@ -916,7 +916,7 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue,
dl_ch_estimates_time,
frame_rx,
nr_slot_rx,
0,
1,
16384);
}
ue->apply_timing_offset = true;
......
......@@ -947,11 +947,6 @@ static int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimest
sample_t *out=(sample_t *)samplesVoid[a];
int nbAnt_tx = ptr->th.nbAnt;//number of Tx antennas
char filename[40];
sprintf(filename,"gNB_data.m");
char filename1[40];
sprintf(filename1,"gNB_Time.m");
//LOG_I(HW, "nbAnt_tx %d\n",nbAnt_tx);
for (int i=0; i < nsamps; i++) {//loop over nsamps
for (int a_tx=0; a_tx<nbAnt_tx; a_tx++) { //sum up signals from nbAnt_tx antennas
......@@ -966,27 +961,6 @@ static int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimest
out[i].r = (short)(outRealTmp * cos(2*M_PI*(double)SampIdxDoppler*fdopplerCurr/fsamp) - outImagTmp * sin(2*M_PI*(double)SampIdxDoppler*fdopplerCurr/fsamp));
out[i].i = (short)(outImagTmp * cos(2*M_PI*(double)SampIdxDoppler*fdopplerCurr/fsamp) + outRealTmp * sin(2*M_PI*(double)SampIdxDoppler*fdopplerCurr/fsamp));
if(t-> typeStamp == ENB_MAGICDL)
{
FILE *fptr;
FILE *fptr1;
double tTmp = SampIdxDoppler/fsamp;
if ((i%1000==0) && (tTmp <= 10))
{
printf("*************** gNB Recording!, i: %d, fdopplerCurr: %d, tTmp: %f\n", i, fdopplerCurr, tTmp);
fptr = fopen(filename,"a");
fptr1 = fopen(filename1,"a");
fprintf(fptr,"%i\n",fdopplerCurr);
fprintf(fptr1,"%f\n",tTmp);
fclose(fptr);
fclose(fptr1);
}
}
SampIdxDoppler++;
CntDoppRate++;
if ( CntDoppRate > NrSampFrame ) {
......
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