From a07f3966a359466eb20a4abef1c7869e072ea3a5 Mon Sep 17 00:00:00 2001 From: ismagom Date: Mon, 3 Feb 2014 20:34:28 +0100 Subject: [PATCH] Issue1 fixed --- examples/cell_search.c | 1 + examples/pss_scan_usrp.c | 77 ++++++++++++++++++++++++++-------------- include/sync/pss.h | 2 +- lib/sync/src/sync.c | 10 +++--- uhd/uhd_utils.c | 26 ++++++++------ 5 files changed, 73 insertions(+), 43 deletions(-) diff --git a/examples/cell_search.c b/examples/cell_search.c index 797b5d4e2..cff0a0369 100644 --- a/examples/cell_search.c +++ b/examples/cell_search.c @@ -221,6 +221,7 @@ int main(int argc, char **argv) { INFO("State Sync, Slot idx=%d\n", frame_idx); idx = sync_run(&synch, input_buffer, read_offset); if (idx != -1) { + idx -= 960; slot_start = read_offset + idx; read_length = idx; read_offset += FLEN; diff --git a/examples/pss_scan_usrp.c b/examples/pss_scan_usrp.c index ca4fc26bf..c7f1fef8e 100644 --- a/examples/pss_scan_usrp.c +++ b/examples/pss_scan_usrp.c @@ -18,15 +18,18 @@ #define FLEN 9600 #define FLEN_PERIOD 0.005 +#define RSSI_DECIM 20 + #define IS_SIGNAL(i) (10*log10f(rssi[i]) + 30 > rssi_threshold) int band, earfcn=-1; -float find_threshold = 40.0, track_threshold = 25.0; +float find_threshold = 40.0, track_threshold = 8.0; int earfcn_start=-1, earfcn_end = -1; float rssi_threshold = -30.0; int max_track_lost=9; int nof_frames_find=8, nof_frames_track=100, nof_samples_rssi=50000; +int track_len=500; cf_t *input_buffer; float *cfo_v; @@ -39,6 +42,7 @@ float gain = 20.0; #define MAX_EARFCN 1000 lte_earfcn_t channels[MAX_EARFCN]; float rssi[MAX_EARFCN]; +float rssi_d[MAX_EARFCN/RSSI_DECIM]; float freqs[MAX_EARFCN]; float cfo[MAX_EARFCN]; float p2a[MAX_EARFCN]; @@ -57,6 +61,7 @@ void usage(char *prog) { printf("\t-f pss_find_threshold [Default %.2f]\n", find_threshold); printf("\t-T pss_track_nof_frames [Default %d]\n", nof_frames_track); printf("\t-t pss_track_threshold [Default %.2f]\n", track_threshold); + printf("\t-l pss_track_len [Default %d]\n", track_len); printf("\t-g gain [Default %.2f dB]\n", gain); printf("\t-v [set verbose to debug, default none]\n"); } @@ -196,11 +201,10 @@ int preprocess_idx(int *in, int *out, int *period, int len) { int rssi_scan() { int n=0; int i; - float rssi_d[MAX_EARFCN/10]; if (nof_bands > 100) { /* scan every Mhz, that is 10 freqs */ - for (i=0;i= nof_frames_find) { state = INIT; @@ -337,22 +349,28 @@ int main(int argc, char **argv) { } break; case TRACK: - /* TODO: find peak around find_idx */ - idx_v[frame_cnt] = sync_run(&synch, input_buffer, FLEN); - p2a_v[frame_cnt] = sync_get_peak_to_avg(&synch); + INFO("Tracking PSS find_idx %d offset %d\n", find_idx, find_idx + track_len); + + filesink_write(&fs, &input_buffer[FLEN+find_idx+track_len], track_len); + + track_idx = sync_run(&strack, input_buffer, FLEN + find_idx - track_len); + p2a_v[frame_cnt] = sync_get_peak_to_avg(&strack); /* save cell id for the best peak-to-avg */ if (p2a_v[frame_cnt] > max_peak_to_avg) { max_peak_to_avg = p2a_v[frame_cnt]; - cell_id = sync_get_cell_id(&synch); + cell_id = sync_get_cell_id(&strack); } - if (idx_v[frame_cnt] != -1) { - cfo_v[frame_cnt] = sync_get_cfo(&synch); + if (track_idx != -1) { + cfo_v[frame_cnt] = sync_get_cfo(&strack); last_found = frame_cnt; + find_idx += track_idx - track_len; + idx_v[frame_cnt] = find_idx; } else { + idx_v[frame_cnt] = -1; cfo_v[frame_cnt] = 0.0; } - /* if we missed to many frames it is not a cell, next freq */ + /* if we missed to many PSS it is not a cell, next freq */ if (frame_cnt - last_found > max_track_lost) { INFO("\n[%3d/%d]: EARFCN %d Freq. %.2f MHz %d frames lost\n", freq, nof_bands, channels[freq].id, channels[freq].fd, frame_cnt - last_found); @@ -370,9 +388,9 @@ int main(int argc, char **argv) { valid_frames = preprocess_idx(idx_v, idx_valid, t, frame_cnt); sfo = sfo_estimate_period(idx_valid, t, valid_frames, FLEN_PERIOD); - printf("\n[%3d/%d]: FOUND EARFCN %d Freq. %.2f MHz, " - "RSSI %3.2f dBm, PAR %2.2f dB, CFO=%+.2f KHz, SFO=%+2.3f KHz, CELL_ID=%3d\n", freq, nof_bands, - channels[freq].id, channels[freq].fd, 10*log10f(rssi[freq]) + 30, + printf("\n[%3d/%d]: FOUND EARFCN %d Freq. %.2f MHz. " + "PAR %2.2f dB, CFO=%+.2f KHz, SFO=%+2.3f KHz, CELL_ID=%3d\n", freq, nof_bands, + channels[freq].id, channels[freq].fd, 10*log10f(p2a[freq]), cfo[freq] * 15, sfo / 1000, cell_id); state = INIT; freq++; @@ -387,7 +405,7 @@ int main(int argc, char **argv) { print_to_matlab(); - sync_free(&synch); + sync_free(&sfind); base_free(); printf("\n\nDone\n"); @@ -414,6 +432,13 @@ void print_to_matlab() { } fprintf(f, "];\n"); + + fprintf(f, "rssi_d=["); + for (i=0;ithreshold); - q->peak_to_avg = peak_value[N_id_2] / mean_value[N_id_2]; + DEBUG("PSS possible peak N_id_2=%d, pos=%d peak=%.2f par=%.2f threshold=%.2f\n", + N_id_2, peak_pos[N_id_2], peak_value[N_id_2], q->peak_to_avg, q->threshold); + /* If peak detected */ peak_detected = 0; - if (peak_pos[N_id_2] > 128) { + if (peak_pos[N_id_2] + read_offset > 128) { if (q->pss_mode == ABSOLUTE) { if (peak_value[N_id_2] > q->threshold) { peak_detected = 1; @@ -171,7 +171,7 @@ int sync_run(sync_t *q, cf_t *input, int read_offset) { INFO("SSS detected N_id_1=%d, slot_idx=%d, m0=%d, m1=%d\n", q->N_id_1, q->slot_id, m0, m1); - return peak_pos[N_id_2] - 960; + return peak_pos[N_id_2]; } else { return -1; } diff --git a/uhd/uhd_utils.c b/uhd/uhd_utils.c index 173164cb5..b33eb344b 100644 --- a/uhd/uhd_utils.c +++ b/uhd/uhd_utils.c @@ -5,9 +5,10 @@ #include "uhd.h" #include "utils/vector.h" +#include "utils/debug.h" int uhd_rssi_scan(void *uhd, float *freqs, float *rssi, int nof_bands, double fs, int nsamp) { - int i; + int i, j; int ret = -1; _Complex float *buffer; double f; @@ -21,22 +22,25 @@ int uhd_rssi_scan(void *uhd, float *freqs, float *rssi, int nof_bands, double fs uhd_set_rx_srate(uhd, fs); for (i=0;i