From cb61ff4009bda09c67f7c6be30391a94df0a76d7 Mon Sep 17 00:00:00 2001 From: ismagom Date: Fri, 25 Sep 2015 19:12:43 +0200 Subject: [PATCH] Added support for reduced sampling rates --- srslte/examples/pdsch_ue.c | 38 +++++++++++++++++------ srslte/include/srslte/common/phy_common.h | 6 ++-- srslte/lib/common/src/phy_common.c | 16 ++++++++++ srslte/lib/sync/test/pss_file.c | 6 ++-- srslte/lib/sync/test/pss_usrp.c | 31 ++++++++++++------ 5 files changed, 73 insertions(+), 24 deletions(-) diff --git a/srslte/examples/pdsch_ue.c b/srslte/examples/pdsch_ue.c index 86163096e..dfc152177 100644 --- a/srslte/examples/pdsch_ue.c +++ b/srslte/examples/pdsch_ue.c @@ -62,6 +62,7 @@ void init_plots(); pthread_t plot_thread; sem_t plot_sem; uint32_t plot_sf_idx=0; +bool plot_track = true; #endif #define PLOT_CHEST_ARGUMENT @@ -323,10 +324,12 @@ int main(int argc, char **argv) { /* set sampling frequency */ int srate = srslte_sampling_freq_hz(cell.nof_prb); if (srate != -1) { - /* Modify master clock rate for 15 Mhz */ - if (cell.nof_prb == 75) { - cuhd_set_master_clock_rate(uhd, 23.04e6); + if (srate < 10e6) { + cuhd_set_master_clock_rate(uhd, 4*srate); + } else { + cuhd_set_master_clock_rate(uhd, srate); } + printf("Setting Sampling frequency %.2f MHz\n", (float) srate/1000000); cuhd_set_rx_srate(uhd, (double) srate); } else { fprintf(stderr, "Invalid number of PRB %d\n", cell.nof_prb); @@ -530,6 +533,7 @@ int main(int argc, char **argv) { if (!prog_args.disable_plots) { if ((sfn%4) == 0 && decode_pdsch) { plot_sf_idx = srslte_ue_sync_get_sfidx(&ue_sync); + plot_track = true; sem_post(&plot_sem); } } @@ -538,6 +542,13 @@ int main(int argc, char **argv) { printf("Finding PSS... Peak: %8.1f, FrameCnt: %d, State: %d\r", srslte_sync_get_peak_value(&ue_sync.sfind), ue_sync.frame_total_cnt, ue_sync.state); + #ifndef DISABLE_GRAPHICS + if (!prog_args.disable_plots) { + plot_sf_idx = srslte_ue_sync_get_sfidx(&ue_sync); + plot_track = false; + sem_post(&plot_sem); + } + #endif } sf_cnt++; @@ -646,12 +657,21 @@ void *plot_thread_run(void *arg) { plot_real_setNewData(&pce, tmp_plot2, 4*12*ue_dl.cell.nof_prb); if (!prog_args.input_file_name) { - int max = srslte_vec_max_fi(ue_sync.strack.pss.conv_output_avg, ue_sync.strack.pss.frame_size+ue_sync.strack.pss.fft_size-1); - srslte_vec_sc_prod_fff(ue_sync.strack.pss.conv_output_avg, - 1/ue_sync.strack.pss.conv_output_avg[max], - tmp_plot2, - ue_sync.strack.pss.frame_size+ue_sync.strack.pss.fft_size-1); - plot_real_setNewData(&p_sync, tmp_plot2, ue_sync.strack.pss.frame_size); + if (plot_track) { + int max = srslte_vec_max_fi(ue_sync.strack.pss.conv_output_avg, ue_sync.strack.pss.frame_size+ue_sync.strack.pss.fft_size-1); + srslte_vec_sc_prod_fff(ue_sync.strack.pss.conv_output_avg, + 1/ue_sync.strack.pss.conv_output_avg[max], + tmp_plot2, + ue_sync.strack.pss.frame_size+ue_sync.strack.pss.fft_size-1); + plot_real_setNewData(&p_sync, tmp_plot2, ue_sync.strack.pss.frame_size); + } else { + int max = srslte_vec_max_fi(ue_sync.sfind.pss.conv_output_avg, ue_sync.sfind.pss.frame_size+ue_sync.sfind.pss.fft_size-1); + srslte_vec_sc_prod_fff(ue_sync.sfind.pss.conv_output_avg, + 1/ue_sync.sfind.pss.conv_output_avg[max], + tmp_plot2, + ue_sync.sfind.pss.frame_size+ue_sync.sfind.pss.fft_size-1); + plot_real_setNewData(&p_sync, tmp_plot2, ue_sync.sfind.pss.frame_size); + } } diff --git a/srslte/include/srslte/common/phy_common.h b/srslte/include/srslte/common/phy_common.h index b993bed6e..c37922185 100644 --- a/srslte/include/srslte/common/phy_common.h +++ b/srslte/include/srslte/common/phy_common.h @@ -43,6 +43,8 @@ #include "srslte/config.h" +#define USE_REDUCED_SAMPLING_RATES + #define SRSLTE_NSUBFRAMES_X_FRAME 10 #define SRSLTE_NSLOTS_X_FRAME (2*SRSLTE_NSUBFRAMES_X_FRAME) @@ -95,8 +97,8 @@ typedef enum {SRSLTE_CP_NORM, SRSLTE_CP_EXT} srslte_cp_t; #define SRSLTE_CP_LEN_NORM(symbol, symbol_sz) ((symbol==0)?SRSLTE_CP_LEN((symbol_sz),SRSLTE_CP_NORM_0_LEN):SRSLTE_CP_LEN((symbol_sz),SRSLTE_CP_NORM_LEN)) #define SRSLTE_CP_LEN_EXT(symbol_sz) (SRSLTE_CP_LEN((symbol_sz),SRSLTE_CP_EXT_LEN)) -#define SRSLTE_SLOT_LEN(symbol_sz) (480*((symbol_sz)/64)) -#define SRSLTE_SF_LEN(symbol_sz) (2*SRSLTE_SLOT_LEN(symbol_sz)) +#define SRSLTE_SLOT_LEN(symbol_sz) (symbol_sz*15/2) +#define SRSLTE_SF_LEN(symbol_sz) (symbol_sz*15) #define SRSLTE_SF_LEN_MAX (SRSLTE_SF_LEN(SRSLTE_SYMBOL_SZ_MAX)) #define SRSLTE_SLOT_LEN_PRB(nof_prb) (SRSLTE_SLOT_LEN(srslte_symbol_sz(nof_prb))) diff --git a/srslte/lib/common/src/phy_common.c b/srslte/lib/common/src/phy_common.c index b4fe4b34c..ba976a0cc 100644 --- a/srslte/lib/common/src/phy_common.c +++ b/srslte/lib/common/src/phy_common.c @@ -197,6 +197,21 @@ int srslte_symbol_sz(uint32_t nof_prb) { if (nof_prb<=0) { return SRSLTE_ERROR; } +#ifdef USE_REDUCED_SAMPLING_RATES + if (nof_prb<=6) { + return 128; + } else if (nof_prb<=15) { + return 256; + } else if (nof_prb<=25) { + return 384; + } else if (nof_prb<=50) { + return 768; + } else if (nof_prb<=75) { + return 1024; + } else if (nof_prb<=100) { + return 1536; + } +#else if (nof_prb<=6) { return 128; } else if (nof_prb<=15) { @@ -210,6 +225,7 @@ int srslte_symbol_sz(uint32_t nof_prb) { } else if (nof_prb<=100) { return 2048; } +#endif return SRSLTE_ERROR; } diff --git a/srslte/lib/sync/test/pss_file.c b/srslte/lib/sync/test/pss_file.c index c7f6ce857..51fbdb839 100644 --- a/srslte/lib/sync/test/pss_file.c +++ b/srslte/lib/sync/test/pss_file.c @@ -140,7 +140,7 @@ int main(int argc, char **argv) { init_plots(); #endif - flen = 4800*(fft_size/64); + flen = fft_size*15*5; buffer = malloc(sizeof(cf_t) * flen * 2); if (!buffer) { @@ -200,7 +200,7 @@ int main(int argc, char **argv) { exit(-1); } if (n < flen - peak_offset) { - fprintf(stdout, "End of file\n"); + fprintf(stdout, "End of file (n=%d, flen=%d, peak=%d)\n", n, flen, peak_offset); break; } @@ -337,7 +337,7 @@ plot_real_t pssout; plot_real_t psss1;//, psss2; -float tmp[100000]; +float tmp[1000000]; cf_t tmpce[SRSLTE_PSS_LEN]; diff --git a/srslte/lib/sync/test/pss_usrp.c b/srslte/lib/sync/test/pss_usrp.c index 8c8a43b4f..1cf09e585 100644 --- a/srslte/lib/sync/test/pss_usrp.c +++ b/srslte/lib/sync/test/pss_usrp.c @@ -148,8 +148,27 @@ int main(int argc, char **argv) { if (!disable_plots) init_plots(); #endif + + float srate = 15000.0*fft_size; - flen = 4800*(fft_size/64); + flen = srate*5/1000; + + printf("Opening UHD device...\n"); + if (cuhd_open(uhd_args, &uhd)) { + fprintf(stderr, "Error opening uhd\n"); + exit(-1); + } + + if (srate < 10e6) { + cuhd_set_master_clock_rate(uhd, 4*srate); + } else { + cuhd_set_master_clock_rate(uhd, srate); + } + + printf("Set RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srate) / 1000000); + printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); + printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); + cuhd_rx_wait_lo_locked(uhd); buffer = malloc(sizeof(cf_t) * flen * 2); if (!buffer) { @@ -177,16 +196,8 @@ int main(int argc, char **argv) { srslte_sss_synch_set_N_id_2(&sss, N_id_2); - printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { - fprintf(stderr, "Error opening uhd\n"); - exit(-1); - } printf("N_id_2: %d\n", N_id_2); - printf("Set RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, flen*2*100) / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - cuhd_rx_wait_lo_locked(uhd); + cuhd_start_rx_stream(uhd); printf("Frame length %d samples\n", flen);