From c762cd6f0f5217bcf615265b8ff714d545651308 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Tue, 17 Jun 2014 09:38:34 +0100 Subject: [PATCH] Cleanup of dft interface --- lte/include/lte/utils/dft.h | 27 +++++++++++----------- lte/lib/common/src/fft.c | 2 +- lte/lib/sync/src/pss.c | 2 +- lte/lib/sync/src/sss.c | 2 +- lte/lib/utils/src/convolution.c | 6 ++--- lte/lib/utils/src/dft.c | 41 ++++++++++++++++++--------------- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/lte/include/lte/utils/dft.h b/lte/include/lte/utils/dft.h index 1f981c4f2..c1d76228b 100644 --- a/lte/include/lte/utils/dft.h +++ b/lte/include/lte/utils/dft.h @@ -72,24 +72,25 @@ typedef float dft_r_t; /* Create DFT plans */ -LIBLTE_API int dft_plan(const int dft_points, dft_mode_t mode, dft_dir_t dir, dft_plan_t *plan); -LIBLTE_API int dft_plan_c2c(const int dft_points, dft_dir_t dir, dft_plan_t *plan); -LIBLTE_API int dft_plan_r2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan); -LIBLTE_API int dft_plan_c2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan); +LIBLTE_API int dft_plan(dft_plan_t *plan, const int dft_points, + dft_mode_t mode, dft_dir_t dir); +LIBLTE_API int dft_plan_c2c(dft_plan_t *plan, const int dft_points, dft_dir_t dir); +LIBLTE_API int dft_plan_r2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir); +LIBLTE_API int dft_plan_c2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir); LIBLTE_API void dft_plan_free(dft_plan_t *plan); /* Create a vector of DFT plans */ -LIBLTE_API int dft_plan_vector(const int *dft_points, dft_mode_t *modes, dft_dir_t *dirs, - int nof_plans, dft_plan_t *plans); -LIBLTE_API int dft_plan_multi_c2c(const int *dft_points, dft_dir_t dir, int nof_plans, - dft_plan_t *plans); -LIBLTE_API int dft_plan_multi_c2r(const int *dft_points, dft_dir_t dir, int nof_plans, - dft_plan_t *plans); -LIBLTE_API int dft_plan_multi_r2r(const int *dft_points, dft_dir_t dir, int nof_plans, - dft_plan_t *plans); -LIBLTE_API void dft_plan_free_vector(dft_plan_t *plan, int nof_plans); +LIBLTE_API int dft_plan_vector(dft_plan_t *plans, const int *dft_points, + dft_mode_t *modes, dft_dir_t *dirs, int nof_plans); +LIBLTE_API int dft_plan_multi_c2c(dft_plan_t *plans, const int *dft_points, + dft_dir_t dir, int nof_plans); +LIBLTE_API int dft_plan_multi_c2r(dft_plan_t *plans, const int *dft_points, + dft_dir_t dir, int nof_plans); +LIBLTE_API int dft_plan_multi_r2r(dft_plan_t *plans, const int *dft_points, + dft_dir_t dir, int nof_plans); +LIBLTE_API void dft_plan_free_vector(dft_plan_t *plans, int nof_plans); /* Compute DFT */ diff --git a/lte/lib/common/src/fft.c b/lte/lib/common/src/fft.c index e6319a5aa..40440caee 100644 --- a/lte/lib/common/src/fft.c +++ b/lte/lib/common/src/fft.c @@ -42,7 +42,7 @@ int lte_fft_init_(lte_fft_t *q, lte_cp_t cp_type, int nof_prb, dft_dir_t dir) { fprintf(stderr, "Error: Invalid nof_prb=%d\n", nof_prb); return -1; } - if (dft_plan_c2c(symbol_sz, dir, &q->fft_plan)) { + if (dft_plan_c2c(&q->fft_plan, symbol_sz, dir)) { fprintf(stderr, "Error: Creating DFT plan\n"); return -1; } diff --git a/lte/lib/sync/src/pss.c b/lte/lib/sync/src/pss.c index 70cb0741e..f32ba1f86 100644 --- a/lte/lib/sync/src/pss.c +++ b/lte/lib/sync/src/pss.c @@ -183,7 +183,7 @@ int pss_synch_set_N_id_2(pss_synch_t *q, int N_id_2) { memset(q->pss_signal_freq, 0, PSS_LEN_FREQ * sizeof(cf_t)); memcpy(&pss_signal_pad[33], pss_signal_time, PSS_LEN * sizeof(cf_t)); - if (dft_plan(PSS_LEN_FREQ - 1, COMPLEX_2_COMPLEX, BACKWARD, &plan)) { + if (dft_plan(&plan, PSS_LEN_FREQ - 1, COMPLEX_2_COMPLEX, BACKWARD)) { return -1; } plan.options = DFT_MIRROR_PRE | DFT_DC_OFFSET; diff --git a/lte/lib/sync/src/sss.c b/lte/lib/sync/src/sss.c index 25c915c6b..201a5ffb7 100644 --- a/lte/lib/sync/src/sss.c +++ b/lte/lib/sync/src/sss.c @@ -42,7 +42,7 @@ void generate_N_id_1_table(int table[30][30]); int sss_synch_init(sss_synch_t *q) { bzero(q, sizeof(sss_synch_t)); - if (dft_plan(SSS_DFT_LEN, COMPLEX_2_COMPLEX, FORWARD, &q->dftp_input)) { + if (dft_plan(&q->dftp_input, SSS_DFT_LEN, COMPLEX_2_COMPLEX, FORWARD)) { return -1; } generate_N_id_1_table(q->N_id_1_table); diff --git a/lte/lib/utils/src/convolution.c b/lte/lib/utils/src/convolution.c index f92ccd383..93ac4db56 100644 --- a/lte/lib/utils/src/convolution.c +++ b/lte/lib/utils/src/convolution.c @@ -44,13 +44,13 @@ int conv_fft_cc_init(conv_fft_cc_t *state, int input_len, int filter_len) { if (!state->input_fft || !state->filter_fft || !state->output_fft) { return -1; } - if (dft_plan(state->output_len,COMPLEX_2_COMPLEX,FORWARD,&state->input_plan)) { + if (dft_plan(&state->input_plan,state->output_len,COMPLEX_2_COMPLEX,FORWARD)) { return -2; } - if (dft_plan(state->output_len,COMPLEX_2_COMPLEX,FORWARD,&state->filter_plan)) { + if (dft_plan(&state->filter_plan,state->output_len,COMPLEX_2_COMPLEX,FORWARD)) { return -3; } - if (dft_plan(state->output_len,COMPLEX_2_COMPLEX,BACKWARD,&state->output_plan)) { + if (dft_plan(&state->output_plan,state->output_len,COMPLEX_2_COMPLEX,BACKWARD)) { return -4; } return 0; diff --git a/lte/lib/utils/src/dft.c b/lte/lib/utils/src/dft.c index 4434b8abc..9450bb23f 100644 --- a/lte/lib/utils/src/dft.c +++ b/lte/lib/utils/src/dft.c @@ -36,40 +36,44 @@ #define div(a,b) ((a-1)/b+1) -int dft_plan_multi(const int *dft_points, dft_mode_t *modes, dft_dir_t *dirs, - int nof_plans, dft_plan_t *plans) { +int dft_plan_vector(dft_plan_t *plans, const int *dft_points, + dft_mode_t *modes, dft_dir_t *dirs, int nof_plans) { int i; for (i=0;iout = fftwf_malloc(size_out*len); } -int dft_plan_c2c(const int dft_points, dft_dir_t dir, dft_plan_t *plan) { +int dft_plan_c2c(dft_plan_t *plan, const int dft_points, dft_dir_t dir) { int sign; sign = (dir == FORWARD) ? FFTW_FORWARD : FFTW_BACKWARD; allocate(plan,sizeof(fftwf_complex),sizeof(fftwf_complex), dft_points); @@ -120,7 +125,7 @@ int dft_plan_c2c(const int dft_points, dft_dir_t dir, dft_plan_t *plan) { return 0; } -int dft_plan_r2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan) { +int dft_plan_r2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir) { int sign; sign = (dir == FORWARD) ? FFTW_R2HC : FFTW_HC2R; @@ -137,8 +142,8 @@ int dft_plan_r2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan) { return 0; } -int dft_plan_c2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan) { - if (dft_plan_c2c(dft_points, dir, plan)) { +int dft_plan_c2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir) { + if (dft_plan_c2c(plan, dft_points, dir)) { return -1; } plan->mode = COMPLEX_2_REAL; @@ -221,7 +226,7 @@ void dft_run_r2r(dft_plan_t *plan, dft_r_t *in, dft_r_t *out) { } if (plan->options & DFT_PSD) { for (i=0;i<(len+1)/2-1;i++) { - out[i] = sqrtf(f_out[i]*f_out[i]+f_out[len-i-1]*f_out[len-i-1]); + out[i] = sqrtf(f_out[i]*f_out[i]+f_out[len-i-1]*f_out[len-i-1]); } } if (plan->options & DFT_OUT_DB) {