From 41188b409e8b85cf6fcba5298670c16ce93f338b Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 12 Sep 2017 11:10:32 +0200 Subject: [PATCH] cleaned up cfo set tolerance functions --- lib/examples/pdsch_ue.c | 8 +++++++- lib/include/srslte/phy/sync/sync.h | 4 ++++ lib/include/srslte/phy/ue/ue_sync.h | 3 +++ lib/include/srslte/phy/ue/ue_ul.h | 10 +++++++--- lib/src/phy/sync/pss.c | 14 +++++++------- lib/src/phy/sync/sync.c | 25 +++++++++++++++---------- lib/src/phy/ue/ue_sync.c | 10 ++++++---- lib/src/phy/ue/ue_ul.c | 14 +++++++++++--- srsue/src/phy/phch_worker.cc | 3 ++- 9 files changed, 62 insertions(+), 29 deletions(-) diff --git a/lib/examples/pdsch_ue.c b/lib/examples/pdsch_ue.c index cf7bed2e4..b4f96a34b 100644 --- a/lib/examples/pdsch_ue.c +++ b/lib/examples/pdsch_ue.c @@ -585,6 +585,10 @@ int main(int argc, char **argv) { /* If a new line is detected set verbose level to Debug */ if (fgets(input, sizeof(input), stdin)) { srslte_verbose = SRSLTE_VERBOSE_DEBUG; + ue_dl.pkt_errors = 0; + ue_dl.pkts_total = 0; + ue_dl.nof_detected = 0; + nof_trials = 0; } } @@ -778,10 +782,12 @@ int main(int argc, char **argv) { if (sfn == 1024) { sfn = 0; PRINT_LINE_ADVANCE_CURSOR(); + /* ue_dl.pkt_errors = 0; ue_dl.pkts_total = 0; ue_dl.nof_detected = 0; - nof_trials = 0; + nof_trials = 0; + */ } } diff --git a/lib/include/srslte/phy/sync/sync.h b/lib/include/srslte/phy/sync/sync.h index 610de2d43..1c70b2449 100644 --- a/lib/include/srslte/phy/sync/sync.h +++ b/lib/include/srslte/phy/sync/sync.h @@ -87,6 +87,7 @@ typedef struct SRSLTE_API { uint32_t cp_len; srslte_cfo_t cfocorr; srslte_cfo_t cfocorr2; + float current_cfo_tol; sss_alg_t sss_alg; bool detect_cp; bool sss_en; @@ -147,6 +148,9 @@ SRSLTE_API srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, SRSLTE_API void srslte_sync_set_threshold(srslte_sync_t *q, float threshold); +SRSLTE_API void srslte_sync_set_cfo_tol(srslte_sync_t *q, + float tol); + /* Gets the subframe idx (0 or 5) */ SRSLTE_API uint32_t srslte_sync_get_sf_idx(srslte_sync_t *q); diff --git a/lib/include/srslte/phy/ue/ue_sync.h b/lib/include/srslte/phy/ue/ue_sync.h index dde9fb566..bd280acd0 100644 --- a/lib/include/srslte/phy/ue/ue_sync.h +++ b/lib/include/srslte/phy/ue/ue_sync.h @@ -181,6 +181,9 @@ SRSLTE_API int srslte_ue_sync_zerocopy(srslte_ue_sync_t *q, SRSLTE_API int srslte_ue_sync_zerocopy_multi(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE_MAX_PORTS]); +SRSLTE_API void srslte_ue_sync_set_cfo_tol(srslte_ue_sync_t *q, + float tol); + SRSLTE_API void srslte_ue_sync_set_cfo(srslte_ue_sync_t *q, float cfo); diff --git a/lib/include/srslte/phy/ue/ue_ul.h b/lib/include/srslte/phy/ue/ue_ul.h index 843948087..3492180e3 100644 --- a/lib/include/srslte/phy/ue/ue_ul.h +++ b/lib/include/srslte/phy/ue/ue_ul.h @@ -75,7 +75,8 @@ typedef struct SRSLTE_API { bool normalize_en; bool cfo_en; - + + float current_cfo_tol; float current_cfo; srslte_pucch_format_t last_pucch_format; @@ -114,10 +115,13 @@ SRSLTE_API void srslte_ue_ul_free(srslte_ue_ul_t *q); SRSLTE_API int srslte_ue_ul_set_cell(srslte_ue_ul_t *q, srslte_cell_t cell); -SRSLTE_API void srslte_ue_ul_set_cfo(srslte_ue_ul_t *q, +SRSLTE_API void srslte_ue_ul_set_cfo_tol(srslte_ue_ul_t *q, + float tol); + +SRSLTE_API void srslte_ue_ul_set_cfo(srslte_ue_ul_t *q, float cur_cfo); -SRSLTE_API void srslte_ue_ul_set_cfo_enable(srslte_ue_ul_t *q, +SRSLTE_API void srslte_ue_ul_set_cfo_enable(srslte_ue_ul_t *q, bool enabled); SRSLTE_API void srslte_ue_ul_set_normalization(srslte_ue_ul_t *q, diff --git a/lib/src/phy/sync/pss.c b/lib/src/phy/sync/pss.c index 3d221528c..f7b35071d 100644 --- a/lib/src/phy/sync/pss.c +++ b/lib/src/phy/sync/pss.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "srslte/phy/sync/pss.h" #include "srslte/phy/dft/dft.h" @@ -95,9 +96,9 @@ int srslte_pss_synch_init_fft_offset(srslte_pss_synch_t *q, uint32_t frame_size, */ int srslte_pss_synch_init_fft_offset_decim(srslte_pss_synch_t *q, uint32_t max_frame_size, uint32_t max_fft_size, - int offset, int decimate) { + int offset, int decimate) +{ - int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL) { @@ -121,7 +122,7 @@ int srslte_pss_synch_init_fft_offset_decim(srslte_pss_synch_t *q, q->frame_size = frame_size; buffer_size = fft_size + frame_size + 1; - + if(q->decimate > 1) { int filter_order = 3; srslte_filt_decim_cc_init(&q->filter,q->decimate,filter_order); @@ -183,16 +184,15 @@ int srslte_pss_synch_init_fft_offset_decim(srslte_pss_synch_t *q, #ifdef CONVOLUTION_FFT - for(N_id_2 = 0; N_id_2<3; N_id_2++) + for(N_id_2=0; N_id_2<3; N_id_2++) q->pss_signal_freq_full[N_id_2] = srslte_vec_malloc(buffer_size * sizeof(cf_t)); if (srslte_conv_fft_cc_init(&q->conv_fft, frame_size, fft_size)) { fprintf(stderr, "Error initiating convolution FFT\n"); goto clean_and_exit; } - for(int i =0; i< 3; i++) - { - srslte_dft_run_c(&q->conv_fft.filter_plan, q->pss_signal_time[i], q->pss_signal_freq_full[i]); + for(int i=0; i<3; i++) { + srslte_dft_run_c(&q->conv_fft.filter_plan, q->pss_signal_time[i], q->pss_signal_freq_full[i]); } #endif diff --git a/lib/src/phy/sync/sync.c b/lib/src/phy/sync/sync.c index 2ec4bfc78..2d7128e39 100644 --- a/lib/src/phy/sync/sync.c +++ b/lib/src/phy/sync/sync.c @@ -38,9 +38,11 @@ #include "srslte/phy/sync/cfo.h" #define MEANPEAK_EMA_ALPHA 0.1 -#define CFO_EMA_ALPHA 0.2 +#define CFO_EMA_ALPHA 0.1 #define CP_EMA_ALPHA 0.1 +#define DEFAULT_CFO_TOL 50.0 // Hz + static bool fft_size_isvalid(uint32_t fft_size) { if (fft_size >= SRSLTE_SYNC_FFT_SZ_MIN && fft_size <= SRSLTE_SYNC_FFT_SZ_MAX && (fft_size%64) == 0) { return true; @@ -94,9 +96,8 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o goto clean_exit; } - // Set a CFO tolerance of approx 50 Hz - srslte_cfo_set_tol(&q->cfocorr, 50.0/(15000.0*q->fft_size)); - srslte_cfo_set_tol(&q->cfocorr2, 50.0/(15000.0*q->fft_size)); + // Set default CFO tolerance + srslte_sync_set_cfo_tol(q, DEFAULT_CFO_TOL); for (int i=0;i<2;i++) { q->cfo_i_corr[i] = srslte_vec_malloc(sizeof(cf_t)*q->frame_size); @@ -114,10 +115,11 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o srslte_sync_set_cp(q, SRSLTE_CP_NORM); q->decimate = decimate; - if(!decimate) + if(!decimate) { decimate = 1; + } - if (srslte_pss_synch_init_fft_offset_decim(&q->pss, max_offset, fft_size,0,decimate)) { + if (srslte_pss_synch_init_fft_offset_decim(&q->pss, max_offset, fft_size, 0, decimate)) { fprintf(stderr, "Error initializing PSS object\n"); goto clean_exit; } @@ -220,9 +222,7 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse } // Update CFO tolerance - srslte_cfo_set_tol(&q->cfocorr, 50.0/(15000.0*q->fft_size)); - srslte_cfo_set_tol(&q->cfocorr2, 50.0/(15000.0*q->fft_size)); - + srslte_sync_set_cfo_tol(q, q->current_cfo_tol); DEBUG("SYNC init with frame_size=%d, max_offset=%d and fft_size=%d\n", frame_size, max_offset, fft_size); @@ -234,6 +234,11 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse return ret; } +void srslte_sync_set_cfo_tol(srslte_sync_t *q, float tol) { + q->current_cfo_tol = tol; + srslte_cfo_set_tol(&q->cfocorr, tol/(15000.0*q->fft_size)); + srslte_cfo_set_tol(&q->cfocorr2, tol/(15000.0*q->fft_size)); +} void srslte_sync_set_threshold(srslte_sync_t *q, float threshold) { q->threshold = threshold; @@ -591,7 +596,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, cf_t *input, uint32_t } else { q->mean_cfo2 = SRSLTE_VEC_EMA(cfo2, q->mean_cfo2, q->cfo_ema_alpha); } - + ret = SRSLTE_SYNC_FOUND; } else { ret = SRSLTE_SYNC_FOUND_NOSPACE; diff --git a/lib/src/phy/ue/ue_sync.c b/lib/src/phy/ue/ue_sync.c index 02d28c258..2126950a6 100644 --- a/lib/src/phy/ue/ue_sync.c +++ b/lib/src/phy/ue/ue_sync.c @@ -210,7 +210,7 @@ int srslte_ue_sync_init_multi_decim(srslte_ue_sync_t *q, if(srslte_sync_init(&q->strack, q->frame_len, TRACK_FRAME_SIZE, q->fft_size)) { fprintf(stderr, "Error initiating sync track\n"); goto clean_exit; - } + } } else { if(srslte_sync_init(&q->strack, q->frame_len, SRSLTE_CP_LEN_NORM(1,q->fft_size), q->fft_size)) { fprintf(stderr, "Error initiating sync track\n"); @@ -220,12 +220,12 @@ int srslte_ue_sync_init_multi_decim(srslte_ue_sync_t *q, ret = SRSLTE_SUCCESS; } - + clean_exit: if (ret == SRSLTE_ERROR) { srslte_ue_sync_free(q); } - return ret; + return ret; } uint32_t srslte_ue_sync_sf_len(srslte_ue_sync_t *q) { @@ -238,7 +238,7 @@ void srslte_ue_sync_free(srslte_ue_sync_t *q) { } if (!q->file_mode) { srslte_sync_free(&q->sfind); - srslte_sync_free(&q->strack); + srslte_sync_free(&q->strack); } else { srslte_filesource_free(&q->file_source); } @@ -380,6 +380,8 @@ void srslte_ue_sync_set_cfo(srslte_ue_sync_t *q, float cfo) { srslte_sync_set_cfo(&q->strack, cfo/15000); } +void srslte_ue_sync_set_cfo_tol(srslte_ue_sync_t *q, float cfo_tol) {} + float srslte_ue_sync_get_sfo(srslte_ue_sync_t *q) { return q->mean_sfo/5e-3; } diff --git a/lib/src/phy/ue/ue_ul.c b/lib/src/phy/ue/ue_ul.c index 82f0eec91..7032df215 100644 --- a/lib/src/phy/ue/ue_ul.c +++ b/lib/src/phy/ue/ue_ul.c @@ -38,6 +38,8 @@ #define MAX_SFLEN SRSLTE_SF_LEN(srslte_symbol_sz(max_prb)) +#define DEFAULT_CFO_TOL 50.0 // Hz + int srslte_ue_ul_init(srslte_ue_ul_t *q, uint32_t max_prb) { @@ -62,8 +64,8 @@ int srslte_ue_ul_init(srslte_ue_ul_t *q, fprintf(stderr, "Error creating CFO object\n"); goto clean_exit; } - - srslte_cfo_set_tol(&q->cfo, 0); + + srslte_ue_ul_set_cfo_tol(q, DEFAULT_CFO_TOL); if (srslte_pusch_init_ue(&q->pusch, max_prb)) { fprintf(stderr, "Error creating PUSCH object\n"); @@ -155,7 +157,9 @@ int srslte_ue_ul_set_cell(srslte_ue_ul_t *q, fprintf(stderr, "Error resizing CFO object\n"); return SRSLTE_ERROR; } - srslte_cfo_set_tol(&q->cfo, 50.0/(15000.0*srslte_symbol_sz(q->cell.nof_prb))); + + srslte_ue_ul_set_cfo_tol(q, q->current_cfo_tol); + if (srslte_pusch_set_cell(&q->pusch, q->cell)) { fprintf(stderr, "Error resizing PUSCH object\n"); return SRSLTE_ERROR; @@ -178,6 +182,10 @@ int srslte_ue_ul_set_cell(srslte_ue_ul_t *q, return ret; } +void srslte_ue_ul_set_cfo_tol(srslte_ue_ul_t *q, float tol) { + q->current_cfo_tol = tol; + srslte_cfo_set_tol(&q->cfo, tol/(15000.0*srslte_symbol_sz(q->cell.nof_prb))); +} void srslte_ue_ul_set_cfo(srslte_ue_ul_t *q, float cur_cfo) { q->current_cfo = cur_cfo; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 0e9932224..17dc3e1ea 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -545,11 +545,12 @@ int phch_worker::decode_pdsch(srslte_ra_dl_grant_t *grant, uint8_t *payload[SRSL snprintf(timestr, 64, ", dec_time=%4d us", (int) t[0].tv_usec); #endif - Info("PDSCH: l_crb=%2d, harq=%d, nof_tb=%d, tbs={%d, %d}, mcs={%d, %d}, rv={%d, %d}, crc={%s, %s}, snr=%.1f dB, n_iter=%d%s\n", + Info("PDSCH: l_crb=%2d, harq=%d, nof_tb=%d, tbs={%d, %d}, mcs={%d, %d}, rv={%d, %d}, crc={%s, %s}, snr=%.1f dB, cfo=%.1f Hzn_iter=%d%s\n", grant->nof_prb, harq_pid, grant->nof_tb, grant->mcs[0].tbs / 8, grant->mcs[1].tbs / 8, grant->mcs[0].idx, grant->mcs[1].idx, rv[0], rv[1], acks[0] ? "OK" : "KO", acks[1] ? "OK" : "KO", 10 * log10(srslte_chest_dl_get_snr(&ue_dl.chest)), + cfo*15000, srslte_pdsch_last_noi(&ue_dl.pdsch), timestr);