From f588d670adccc4c1eef7291f880b418a2a95b432 Mon Sep 17 00:00:00 2001 From: ismagom Date: Thu, 13 Mar 2014 18:03:39 +0000 Subject: [PATCH] Fixed bug when receiving all zeros samples --- examples/pbch_ue.c | 46 +++++++++++++++++++++++++---------------- lte/lib/phch/src/pbch.c | 20 ++++++++++++++++++ 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/examples/pbch_ue.c b/examples/pbch_ue.c index e2f82bbf9..73d418b8c 100644 --- a/examples/pbch_ue.c +++ b/examples/pbch_ue.c @@ -57,7 +57,7 @@ #define NOF_PORTS 2 -float find_threshold = 40.0, track_threshold = 8.0; +float find_threshold = 30.0, track_threshold = 10.0; int max_track_lost = 20, nof_slots = -1; int track_len=300; char *input_file_name = NULL; @@ -65,7 +65,7 @@ int disable_plots = 0; int go_exit=0; -float uhd_freq = 2400000000.0, uhd_gain = 20.0; +float uhd_freq = 2600000000.0, uhd_gain = 20.0; char *uhd_args = ""; filesource_t fsrc; @@ -328,6 +328,7 @@ int main(int argc, char **argv) { float cfo; int n; int nof_found_mib = 0; + float timeoffset = 0; #ifdef DISABLE_UHD if (argc < 3) { @@ -398,18 +399,23 @@ int main(int argc, char **argv) { INFO("FIND %3d:\tPAR=%.2f\n", frame_cnt, sync_get_peak_to_avg(&sfind)); if (find_idx != -1) { /* if found peak, go to track and set track threshold */ - frame_cnt = -1; - last_found = 0; - sync_set_threshold(&strack, track_threshold); - sync_force_N_id_2(&strack, sync_get_N_id_2(&sfind)); cell_id = sync_get_cell_id(&sfind); - mib_decoder_init(cell_id); - nof_found_mib = 0; - nslot = sync_get_slot_id(&sfind); - nslot=(nslot+10)%20; - cfo = 0; - printf("\n"); - state = TRACK; + if (cell_id != -1) { + frame_cnt = -1; + last_found = 0; + sync_set_threshold(&strack, track_threshold); + sync_force_N_id_2(&strack, sync_get_N_id_2(&sfind)); + mib_decoder_init(cell_id); + nof_found_mib = 0; + nslot = sync_get_slot_id(&sfind); + nslot=(nslot+10)%20; + cfo = 0; + timeoffset = 0; + printf("\n"); + state = TRACK; + } else { + printf("cellid=-1\n"); + } } if (verbose == VERBOSE_NONE) { printf("Finding PSS... PAR=%.2f\r", sync_get_peak_to_avg(&sfind)); @@ -423,8 +429,10 @@ int main(int argc, char **argv) { if (track_idx != -1) { /* compute cumulative moving average CFO */ cfo = (sync_get_cfo(&strack) + frame_cnt * cfo) / (frame_cnt + 1); + /* compute cumulative moving average time offset */ + timeoffset = (float) (track_idx-track_len + timeoffset * frame_cnt) / (frame_cnt + 1); last_found = frame_cnt; - find_idx += track_idx - track_len; + find_idx = (find_idx + track_idx - track_len)%FLEN; if (nslot != sync_get_slot_id(&strack)) { INFO("Expected slot %d but got %d\n", nslot, sync_get_slot_id(&strack)); printf("\r\n"); @@ -432,6 +440,9 @@ int main(int argc, char **argv) { printf("\r\n"); state = FIND; } + } else { + /* if sync not found, adjust time offset with the averaged value */ + find_idx = (find_idx + (int) timeoffset)%FLEN; } /* if we missed too many PSS go back to FIND */ @@ -448,11 +459,10 @@ int main(int argc, char **argv) { cfo_correct(&cfocorr, input_buffer, -cfo/128); - if (nslot == 0) { + if (nslot == 0 && find_idx + 960 < FLEN) { INFO("Finding MIB at idx %d\n", find_idx); if (mib_decoder_run(&input_buffer[find_idx], &mib)) { INFO("MIB detected attempt=%d\n", frame_cnt); - last_found = frame_cnt; if (verbose == VERBOSE_NONE) { if (!nof_found_mib) { printf("\r\n"); @@ -466,8 +476,8 @@ int main(int argc, char **argv) { INFO("MIB not found attempt %d\n",frame_cnt); } if (frame_cnt) { - printf("SFN: %4d\tCFO: %+.4f KHz\tTimeOffset: %4d\tErrors: %4d/%4d\tErrorRate: %.1e\r", mib.sfn, - cfo*15, find_idx, frame_cnt-2*(nof_found_mib-1), frame_cnt, + printf("SFN: %4d, CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Errors: %4d/%4d, ErrorRate: %.1e\r", mib.sfn, + cfo*15, timeoffset/5, find_idx, frame_cnt-2*(nof_found_mib-1), frame_cnt, (float) (frame_cnt-2*(nof_found_mib-1))/frame_cnt); fflush(stdout); } diff --git a/lte/lib/phch/src/pbch.c b/lte/lib/phch/src/pbch.c index c3f98f40f..b92533bbd 100644 --- a/lte/lib/phch/src/pbch.c +++ b/lte/lib/phch/src/pbch.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "phch.h" #include "lte/phch/pbch.h" @@ -57,6 +58,7 @@ bool pbch_exists(int nframe, int nslot) { int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id, bool put) { int i; cf_t *ptr; + assert(cell_id >= 0); if (put) { ptr = input; output += nof_prb * RE_X_RB / 2 - 36; @@ -110,6 +112,9 @@ int pbch_get(cf_t *slot1_data, cf_t *pbch, int nof_prb, lte_cp_t cp, int cell_id /** Initializes the PBCH channel receiver */ int pbch_init(pbch_t *q, int cell_id, lte_cp_t cp) { int ret = -1; + if (cell_id < 0) { + return -1; + } bzero(q, sizeof(pbch_t)); q->cell_id = cell_id; q->cp = cp; @@ -374,9 +379,24 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int n /* unrate matching */ rm_conv_rx(q->temp, q->pbch_rm_f, 4 * nof_bits, 120); + /* FIXME: If channel estimates are zero, received LLR are NaN. Check and return error */ + for (j=0;j<120;j++) { + if (isnan(q->pbch_rm_f[j]) || isinf(q->pbch_rm_f[j])) { + return 0; + } + } + /* decode */ viterbi_decode_f(&q->decoder, q->pbch_rm_f, q->data); + int c=0; + for (j=0;j<40;j++) { + c+=q->data[j]; + } + if (!c) { + c=1; + } + if (!pbch_crc_check(q->data, nof_ports)) { /* unpack MIB */ pbch_mib_unpack(q->data, mib);