cleaning up the PRACH time offset calculation

This commit is contained in:
yagoda 2020-09-07 12:17:30 +02:00 committed by Justin Tallon
parent b5a8d82058
commit 24574caf44
1 changed files with 14 additions and 8 deletions

View File

@ -603,18 +603,24 @@ bool srslte_prach_have_stored(int current_idx, uint32_t* indices, uint32_t n_ind
return false; return false;
} }
// set the offset based on the time domain time offset estimation // set the offset based on the time domain time offset estimation
float srslte_prach_set_offset(srslte_prach_t* p, int n_win) { float srslte_prach_get_offset_secs(srslte_prach_t* p, int n_win)
{
// takes the offset in samples and converts to time in seconds
return (float)p->peak_offsets[n_win] / (float)(DELTA_F_RA * p->N_zc); return (float)p->peak_offsets[n_win] / (float)(DELTA_F_RA * p->N_zc);
} }
// calculates the timing offset of the incoming PRACH by calculating the phase in frequency - alternative to time domain // calculates the timing offset of the incoming PRACH by calculating the phase in frequency - alternative to time domain
// approach // approach
int srslte_prach_calculate_time_offset(srslte_prach_t* p, cf_t* cross) float srslte_prach_calculate_time_offset_secs(srslte_prach_t* p, cf_t* cross)
{ {
// calculate the phase of the cross correlation
float freq_domain_phase = cargf(srslte_vec_acc_cc(cross, p->N_zc)); float freq_domain_phase = cargf(srslte_vec_acc_cc(cross, p->N_zc));
float ratio = (float)(p->N_ifft_ul * DELTA_F) / (float)(MAX_N_zc * DELTA_F_RA); float ratio = (float)(p->N_ifft_ul * DELTA_F) / (float)(MAX_N_zc * DELTA_F_RA);
int time_offset = round((ratio * freq_domain_phase * p->N_zc) / (2 * M_PI)); // converting from phase to number of samples
return time_offset; float num_samples = roundf((ratio * freq_domain_phase * p->N_zc) / (2 * M_PI));
// converting to time in seconds
return num_samples / ((float)p->N_ifft_ul * DELTA_F);
} }
// calculates the aggregate phase offset of the incomming PRACH signal so it can be applied to the reference signal // calculates the aggregate phase offset of the incomming PRACH signal so it can be applied to the reference signal
// before it is subtracted from the input // before it is subtracted from the input
@ -707,10 +713,10 @@ int srslte_prach_process(srslte_prach_t* p,
peak_to_avg[*n_indices] = p->peak_values[j] / corr_ave; peak_to_avg[*n_indices] = p->peak_values[j] / corr_ave;
} }
if (t_offsets) { if (t_offsets) {
t_offsets[*n_indices] = // saves the PRACH offset in seconds to t_offsets, time domain or freq domain base calc
(p->freq_domain_offset_calc) t_offsets[*n_indices] = (p->freq_domain_offset_calc)
? (((float)srslte_prach_calculate_time_offset(p, p->cross)) / ((float)p->N_ifft_ul * DELTA_F)) ? (srslte_prach_calculate_time_offset_secs(p, p->cross))
: (srslte_prach_set_offset(p, j)); : (srslte_prach_get_offset_secs(p, j));
} }
(*n_indices)++; (*n_indices)++;
} }