From 78791919352a3aa2e4791376220821261dc61fbe Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Tue, 24 Nov 2015 22:29:56 +0100 Subject: [PATCH] Fixed FastDDC! Now it works. --- fastddc.c | 14 +-- grc_tests/test_fastddc.grc | 223 ++++++++++++++++++++++++++++++++++++- 2 files changed, 228 insertions(+), 9 deletions(-) diff --git a/fastddc.c b/fastddc.c index 1e41043..7b26c0d 100644 --- a/fastddc.c +++ b/fastddc.c @@ -55,12 +55,12 @@ int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shif //Shift operation in the frequency domain: we can shift by a multiple of v. ddc->v = ddc->fft_size/ddc->overlap_length; //overlap factor | +-1 ? (or maybe ceil() this?) int middlebin=ddc->fft_size / 2; - ddc->startbin = middlebin + middlebin * shift_rate * 2; + ddc->startbin = middlebin + middlebin * (-shift_rate) * 2; //fprintf(stderr, "ddc->startbin=%g\n",(float)ddc->startbin); ddc->startbin = ddc->v * round( ddc->startbin / (float)ddc->v ); //fprintf(stderr, "ddc->startbin=%g\n",(float)ddc->startbin); ddc->offsetbin = ddc->startbin - middlebin; - ddc->post_shift = shift_rate-((float)ddc->offsetbin/ddc->fft_size); + ddc->post_shift = (ddc->pre_decimation)*(shift_rate+((float)ddc->offsetbin/ddc->fft_size)); ddc->pre_shift = ddc->offsetbin/(float)ddc->fft_size; ddc->dsadata = decimating_shift_addition_init(ddc->post_shift, ddc->post_decimation); @@ -122,9 +122,10 @@ decimating_shift_addition_status_t fastddc_inv_cc(complexf* input, complexf* out //Alias & shift & filter at once fft_swap_sides(input, ddc->fft_size); //TODO this is not very optimal, but now we stick with this slow solution until we got the algorithm working //fprintf(stderr, " === fastddc_inv_cc() ===\n"); + //The problem is, we have to say that the output_index should be the _center_ of the spectrum when i is at startbin! (startbin is at the _center_ of the input to downconvert, not at its first bin!) for(int i=0;ifft_size;i++) { - int output_index = (ddc->fft_size+i-ddc->offsetbin)%plan_inverse->size; + int output_index = (ddc->fft_size+i-ddc->offsetbin+(ddc->fft_inv_size/2))%plan_inverse->size; int tap_index = i; //fprintf(stderr, "output_index = %d , tap_index = %d, input index = %d\n", output_index, tap_index, i); //cmultadd(inv_input+output_index, input+i, taps_fft+tap_index); //cmultadd(output, input1, input2): complex output += complex input1 * complex input 2 @@ -148,7 +149,6 @@ decimating_shift_addition_status_t fastddc_inv_cc(complexf* input, complexf* out fft_swap_sides(inv_input,plan_inverse->size); fft_execute(plan_inverse); - //Normalize data for(int i=0;isize;i++) //@fastddc_inv_cc: normalize by size @@ -159,8 +159,8 @@ decimating_shift_addition_status_t fastddc_inv_cc(complexf* input, complexf* out //Overlap is scrapped, not added //Shift correction - //shift_stat=decimating_shift_addition_cc(inv_output+ddc->scrap, output, ddc->post_input_size, ddc->dsadata, ddc->post_decimation, shift_stat); - shift_stat.output_size = ddc->post_input_size; //bypass shift correction - memcpy(output, inv_output+ddc->scrap, sizeof(complexf)*ddc->post_input_size); + shift_stat=decimating_shift_addition_cc(inv_output+ddc->scrap, output, ddc->post_input_size, ddc->dsadata, ddc->post_decimation, shift_stat); + //shift_stat.output_size = ddc->post_input_size; //bypass shift correction + //memcpy(output, inv_output+ddc->scrap, sizeof(complexf)*ddc->post_input_size); return shift_stat; } diff --git a/grc_tests/test_fastddc.grc b/grc_tests/test_fastddc.grc index 492fcab..829a336 100644 --- a/grc_tests/test_fastddc.grc +++ b/grc_tests/test_fastddc.grc @@ -179,7 +179,7 @@ value - 250000 + 400000 @@ -237,6 +237,57 @@ 0 + + analog_pll_freqdet_cf + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (112, 875) + + + _rotation + 0 + + + id + analog_pll_freqdet_cf_0 + + + w + (3.141592654/200)/2 + + + max_freq + 3.141592654 + + + maxoutbuf + 0 + + + min_freq + -3.141592654 + + + minoutbuf + 0 + + analog_sig_source_x @@ -300,6 +351,57 @@ analog.GR_COS_WAVE + + blocks_multiply_const_vxx + + alias + + + + comment + + + + const + (samp_rate/decimation)*(1/(2*3.141592654)) + + + affinity + + + + _enabled + True + + + _coordinate + (136, 763) + + + _rotation + 0 + + + id + blocks_multiply_const_vxx_0 + + + type + float + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + blocks_throttle @@ -363,7 +465,7 @@ commandline - csdr fastddc_fwd_cc 4 | csdr fastddc_inv_cc 4 -0.1 + csdr fastddc_fwd_cc %d | csdr fastddc_inv_cc %d 0.4"%(decimation,decimation)+" comment @@ -651,6 +753,105 @@ 10 + + wxgui_numbersink2 + + avg_alpha + 0 + + + average + False + + + alias + + + + comment + + + + affinity + + + + decimal_places + 10 + + + _enabled + True + + + factor + 1.0 + + + _coordinate + (400, 691) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_numbersink2_0 + + + max_value + (samp_rate/decimation)/2 + + + min_value + (-samp_rate/decimation)/2 + + + notebook + + + + number_rate + 15 + + + peak_hold + False + + + ref_level + 0 + + + samp_rate + samp_rate + + + show_gauge + True + + + title + PLL locked at + + + type + float + + + units + Hz + + + win_size + + + wxgui_scopesink2 @@ -744,12 +945,24 @@ 0 0 + + analog_pll_freqdet_cf_0 + blocks_multiply_const_vxx_0 + 0 + 0 + analog_sig_source_x_0 blocks_throttle_0 0 0 + + blocks_multiply_const_vxx_0 + wxgui_numbersink2_0 + 0 + 0 + blocks_throttle_0 ha5kfu_execproc_xx_1 @@ -762,6 +975,12 @@ 0 0 + + ha5kfu_execproc_xx_1 + analog_pll_freqdet_cf_0 + 0 + 0 + ha5kfu_execproc_xx_1 wxgui_fftsink2_0