From c7e363d5cf6fac6bc8ed1614b35407e35ae9b58d Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Tue, 17 Nov 2015 10:01:34 +0100 Subject: [PATCH] Fixed segmentation fault and a couple of other things. Added a GRC test for fastddc. --- Makefile | 4 +- csdr.c | 25 +- fastddc.c | 18 +- grc_tests/test_bandpass_fir_fft.grc | 1120 ++++++++++++++------------- grc_tests/test_fastddc.grc | 689 ++++++++++++++++ 5 files changed, 1295 insertions(+), 561 deletions(-) create mode 100644 grc_tests/test_fastddc.grc diff --git a/Makefile b/Makefile index 5de63bd..64f52ac 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ FFTW_PACKAGE = fftw-3.3.3 .PHONY: clean-vect clean all: csdr ddcd -libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c *.h +libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastddc.c *.h @echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\). @echo Auto-detected optimization parameters: $(PARAMS_SIMD) @echo @@ -63,7 +63,7 @@ clean-vect: rm -f dumpvect*.vect clean: clean-vect rm -f libcsdr.so csdr ddcd -install: +install: all install -m 0755 libcsdr.so /usr/lib install -m 0755 csdr /usr/bin install -m 0755 csdr-fm /usr/bin diff --git a/csdr.c b/csdr.c index 9445d6c..55ce462 100644 --- a/csdr.c +++ b/csdr.c @@ -1649,15 +1649,16 @@ int main(int argc, char *argv[]) if( !strcmp(argv[1],"fastddc_fwd_cc") ) // [transition_bw [window]] { + int decimation; if(argc<=2) return badsyntax("need required parameter (decimation)"); sscanf(argv[2],"%d",&decimation); float transition_bw = 0.05; - if(argc>=3) sscanf(argv[3],"%g",&transition_bw); + if(argc>3) sscanf(argv[3],"%g",&transition_bw); window_t window = WINDOW_DEFAULT; - if(argc>=4) window=firdes_get_window_from_string(argv[5]); + if(argc>4) window=firdes_get_window_from_string(argv[5]); else fprintf(stderr,"fastddc_fwd_cc: window = %s\n",firdes_get_string_from_window(window)); fastddc_t ddc; @@ -1683,7 +1684,7 @@ int main(int argc, char *argv[]) { FEOF_CHECK; //overlapped FFT - for(int i=0;i=3) sscanf(argv[3],"%g",&shift_rate); + if(argc>3) sscanf(argv[3],"%g",&shift_rate); float transition_bw = 0.05; - if(argc>=4) sscanf(argv[4],"%g",&transition_bw); + if(argc>4) sscanf(argv[4],"%g",&transition_bw); window_t window = WINDOW_DEFAULT; - if(argc>=5) window=firdes_get_window_from_string(argv[5]); + if(argc>5) window=firdes_get_window_from_string(argv[5]); else fprintf(stderr,"fastddc_apply_cc: window = %s\n",firdes_get_string_from_window(window)); fastddc_t ddc; @@ -1726,14 +1727,16 @@ int main(int argc, char *argv[]) fft_execute(plan_taps); //make FFT plan + complexf* inv_input = (complexf*)fft_malloc(sizeof(complexf)*ddc.fft_inv_size); + complexf* inv_output = (complexf*)fft_malloc(sizeof(complexf)*ddc.fft_inv_size); + fprintf(stderr,"fastddc_apply_cc: benchmarking FFT..."); + FFT_PLAN_T* plan_inverse = make_fft_c2c(ddc.fft_inv_size, inv_input, inv_output, 0, 1); //inverse, do benchmark + fprintf(stderr," done\n"); + + //alloc. buffers complexf* input = (complexf*)fft_malloc(sizeof(complexf)*ddc.fft_size); complexf* output = (complexf*)fft_malloc(sizeof(complexf)*ddc.output_size); - int benchmark = 1; - if(benchmark) fprintf(stderr,"fastddc_apply_cc: benchmarking FFT..."); - FFT_PLAN_T* plan_inverse = make_fft_c2c(ddc.fft_size, input, output, 0, 1); //inverse, do benchmark - if(benchmark) fprintf(stderr," done\n"); - decimating_shift_addition_status_t shift_stat; bzero(&shift_stat, sizeof(shift_stat)); for(;;) diff --git a/fastddc.c b/fastddc.c index 40d5d21..baaf597 100644 --- a/fastddc.c +++ b/fastddc.c @@ -55,11 +55,11 @@ 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; //+-1 ? (or maybe ceil() this?) //TODO: why? int middlebin=ddc->fft_size / 2; - ddc->startbin = middlebin + middlebin * shift_rate * 2; + ddc->startbin = middlebin + middlebin * shift_rate * 2; ddc->startbin = ddc->v * round( ddc->startbin / (float)ddc->v ); ddc->offsetbin = ddc->startbin - middlebin; - ddc->post_shift = ((float)ddc->offsetbin/ddc->fft_size) - shift_rate; - ddc->pre_shift = ddc->offsetbin * ddc->v; + ddc->post_shift = shift_rate-((float)ddc->offsetbin/ddc->fft_size); + ddc->pre_shift = ddc->offsetbin/(float)ddc->fft_size; //Overlap is scraped, not added ddc->scrape=ddc->overlap_length/ddc->pre_decimation; @@ -73,14 +73,16 @@ void fastddc_print(fastddc_t* ddc) { fprintf(stderr, "fastddc_print_sizes(): (fft_size = %d) = (taps_length = %d) + (input_size = %d) - 1\n" - "\t(overlap_length = %d) = taps_length - 1, taps_real_length = %d\n" - "\tdecimation = (pre_decimation = %d) * (post_decimation = %d), fft_inv_size = %d\n" - "\tstartbin = %d, offsetbin = %d, v = %d, pre_shift = %g, post_shift = %g\n" + " overlap :: (overlap_length = %d) = taps_length - 1, taps_real_length = %d\n" + " decimation :: decimation = (pre_decimation = %d) * (post_decimation = %d), fft_inv_size = %d\n" + " shift :: startbin = %d, offsetbin = %d, v = %d, pre_shift = %g, post_shift = %g\n" + " o&s :: output_size = %d, scrape = %d\n" , ddc->fft_size, ddc->taps_length, ddc->input_size, ddc->overlap_length, ddc->taps_real_length, ddc->pre_decimation, ddc->post_decimation, ddc->fft_inv_size, - ddc->startbin, ddc->offsetbin, ddc->v, ddc->pre_shift, ddc->post_shift ); + ddc->startbin, ddc->offsetbin, ddc->v, ddc->pre_shift, ddc->post_shift, + ddc->output_size, ddc->scrape ); } decimating_shift_addition_status_t fastddc_apply_cc(complexf* input, complexf* output, fastddc_t* ddc, FFT_PLAN_T* plan_inverse, complexf* taps_fft, decimating_shift_addition_status_t shift_stat) @@ -120,6 +122,6 @@ decimating_shift_addition_status_t fastddc_apply_cc(complexf* input, complexf* o //Overlap is scraped, not added //Shift correction shift_addition_data_t dsadata=decimating_shift_addition_init(ddc->post_shift, ddc->post_decimation); //this could be optimized (passed as parameter), but we would not win too much at all - shift_stat=decimating_shift_addition_cc(plan_inverse->output+ddc->scrape, output, ddc->output_size, dsadata, ddc->post_decimation, shift_stat); + shift_stat=decimating_shift_addition_cc(inv_output+ddc->scrape, output, ddc->output_size, dsadata, ddc->post_decimation, shift_stat); return shift_stat; } diff --git a/grc_tests/test_bandpass_fir_fft.grc b/grc_tests/test_bandpass_fir_fft.grc index 0d2bc4d..8f010b3 100644 --- a/grc_tests/test_bandpass_fir_fft.grc +++ b/grc_tests/test_bandpass_fir_fft.grc @@ -1,49 +1,49 @@ - - + + Sat Nov 22 11:19:26 2014 options - - id - top_block - - - _enabled - True - - - title - - author - - description - - window_size 1280, 1024 - - generate_options - wx_gui - category Custom - run_options - prompt + comment + - run + description + + + + _enabled True + + _coordinate + (24, 11) + + + _rotation + 0 + + + generate_options + wx_gui + + + id + top_block + max_nouts 0 @@ -53,36 +53,91 @@ - alias + run_options + prompt + + + run + True + + + thread_safe_setters - _coordinate - (24, 11) - - - _rotation - 0 + title + - variable + variable_slider - id - samp_rate + comment + + + + converver + float_converter + + + value + 1e3 _enabled True - value - 24e3 + _coordinate + (8, 83) - alias + _rotation + 0 + + + grid_pos + + id + freq + + + label + + + + max + samp_rate/2 + + + min + -samp_rate/2 + + + notebook + + + + num_steps + 100 + + + style + wx.SL_HORIZONTAL + + + + variable + + comment + + + + _enabled + True + _coordinate (184, 11) @@ -91,16 +146,64 @@ _rotation 0 + + id + samp_rate + + + value + 24e3 + analog_sig_source_x + + amp + 1 + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + freq + freq + + + _coordinate + (128, 83) + + + _rotation + 0 + id analog_sig_source_x_0 - _enabled - True + maxoutbuf + 0 + + + minoutbuf + 0 + + + offset + 0 type @@ -114,84 +217,24 @@ waveform analog.GR_COS_WAVE - - freq - freq - - - amp - 1 - - - offset - 0 - - - alias - - - - affinity - - - - minoutbuf - 0 - - - maxoutbuf - 0 - - - _coordinate - (128, 83) - - - _rotation - 0 - blocks_throttle - - id - blocks_throttle_0 - - - _enabled - True - - - type - complex - - - samples_per_second - samp_rate - - - vlen - 1 - - - ignoretag - True - alias + + comment + + affinity - minoutbuf - 0 - - - maxoutbuf - 0 + _enabled + True _coordinate @@ -201,460 +244,96 @@ _rotation 0 - - - variable_slider id - freq + blocks_throttle_0 - _enabled + ignoretag True - label - - - - value - 1e3 - - - min - -samp_rate/2 - - - max - samp_rate/2 - - - num_steps - 100 - - - style - wx.SL_HORIZONTAL - - - converver - float_converter - - - grid_pos - - - - notebook - - - - alias - - - - _coordinate - (8, 83) - - - _rotation + maxoutbuf 0 - - - wxgui_fftsink2 - id - wxgui_fftsink2_0_0 + minoutbuf + 0 - _enabled - True + samples_per_second + samp_rate type complex - title - FFT Plot of original signal - - - samp_rate - samp_rate - - - baseband_freq - 0 - - - y_per_div - 10 - - - y_divs - 10 - - - ref_level - 0 - - - ref_scale - 2.0 - - - fft_size - 1024 - - - fft_rate - 15 - - - peak_hold - False - - - average - False - - - avg_alpha - 0 - - - win - None - - - win_size - - - - grid_pos - - - - notebook - nb0,1 - - - freqvar - None - - - alias - - - - affinity - - - - _coordinate - (504, 219) - - - _rotation - 0 - - - - wxgui_scopesink2 - - id - wxgui_scopesink2_0 - - - _enabled - True - - - type - complex - - - title - Scope Plot of original signal - - - samp_rate - samp_rate - - - v_scale - 0 - - - v_offset - 0 - - - t_scale - 0 - - - ac_couple - False - - - xy_mode - False - - - num_inputs + vlen 1 - - win_size - - - - grid_pos - - - - notebook - nb0,0 - - - trig_mode - wxgui.TRIG_MODE_AUTO - - - y_axis_label - Counts - + + + ha5kfu_execproc_xx alias - affinity + commandline + csdr bandpass_fir_fft_cc 0.1 0.5 0.05 HAMMING + + + comment - _coordinate - (504, 435) - - - _rotation - 0 - - - - wxgui_scopesink2 - - id - wxgui_scopesink2_0_0 + affinity + _enabled True - - type - complex - - - title - Scope Plot of new signal - - - samp_rate - samp_rate - - - v_scale - 0 - - - v_offset - 0 - - - t_scale - 0 - - - ac_couple - False - - - xy_mode - False - - - num_inputs - 1 - - - win_size - - - - grid_pos - - - - notebook - nb1,0 - - - trig_mode - wxgui.TRIG_MODE_AUTO - - - y_axis_label - Counts - - - alias - - - - affinity - - _coordinate - (784, 283) + (488, 147) _rotation 0 - - - wxgui_fftsink2 id - wxgui_fftsink2_0 + ha5kfu_execproc_xx_0 - _enabled - True + maxoutbuf + 0 + + + minoutbuf + 0 type - complex - - - title - FFT Plot of new signal - - - samp_rate - samp_rate - - - baseband_freq - 0 - - - y_per_div - 10 - - - y_divs - 10 - - - ref_level - 0 - - - ref_scale - 2.0 - - - fft_size - 1024 - - - fft_rate - 15 - - - peak_hold - False - - - average - False - - - avg_alpha - 0 - - - win - None - - - win_size - - - - grid_pos - - - - notebook - nb1,1 - - - freqvar - None - - - alias - - - - affinity - - - - _coordinate - (784, 67) - - - _rotation - 0 + cc notebook - id - nb0 + alias + + + + comment + _enabled True - - style - wx.NB_TOP - - - labels - ['scope', 'fft'] - - - grid_pos - 1,1,1,1 - - - notebook - - - - alias - - _coordinate (272, 11) @@ -663,37 +342,41 @@ _rotation 0 - - - notebook + + grid_pos + 1,1,1,1 + id - nb1 - - - _enabled - True - - - style - wx.NB_TOP + nb0 labels ['scope', 'fft'] - - grid_pos - 1,2,1,1 - notebook + + style + wx.NB_TOP + + + + notebook alias + + comment + + + + _enabled + True + _coordinate (416, 11) @@ -702,49 +385,406 @@ _rotation 0 - - - ha5kfu_execproc_xx + + grid_pos + 1,2,1,1 + id - ha5kfu_execproc_xx_0 + nb1 - _enabled - True + labels + ['scope', 'fft'] - type - cc + notebook + - commandline - csdr bandpass_fir_fft_cc 0.1 0.5 0.05 HAMMING + style + wx.NB_TOP + + + + wxgui_fftsink2 + + avg_alpha + 0 + + + average + False + + + baseband_freq + 0 alias + + comment + + affinity - minoutbuf - 0 + _enabled + True - maxoutbuf - 0 + fft_size + 1024 + + + freqvar + None _coordinate - (488, 147) + (784, 67) _rotation 0 + + grid_pos + + + + id + wxgui_fftsink2_0 + + + notebook + nb1,1 + + + peak_hold + False + + + ref_level + 0 + + + ref_scale + 2.0 + + + fft_rate + 15 + + + samp_rate + samp_rate + + + title + FFT Plot of new signal + + + type + complex + + + win_size + + + + win + None + + + y_divs + 10 + + + y_per_div + 10 + + + + wxgui_fftsink2 + + avg_alpha + 0 + + + average + False + + + baseband_freq + 0 + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + fft_size + 1024 + + + freqvar + None + + + _coordinate + (504, 219) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_fftsink2_0_0 + + + notebook + nb0,1 + + + peak_hold + False + + + ref_level + 0 + + + ref_scale + 2.0 + + + fft_rate + 15 + + + samp_rate + samp_rate + + + title + FFT Plot of original signal + + + type + complex + + + win_size + + + + win + None + + + y_divs + 10 + + + y_per_div + 10 + + + + wxgui_scopesink2 + + ac_couple + False + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (504, 435) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_scopesink2_0 + + + notebook + nb0,0 + + + num_inputs + 1 + + + samp_rate + samp_rate + + + t_scale + 0 + + + title + Scope Plot of original signal + + + trig_mode + wxgui.TRIG_MODE_AUTO + + + type + complex + + + v_offset + 0 + + + v_scale + 0 + + + win_size + + + + xy_mode + False + + + y_axis_label + Counts + + + + wxgui_scopesink2 + + ac_couple + False + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (784, 283) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_scopesink2_0_0 + + + notebook + nb1,0 + + + num_inputs + 1 + + + samp_rate + samp_rate + + + t_scale + 0 + + + title + Scope Plot of new signal + + + trig_mode + wxgui.TRIG_MODE_AUTO + + + type + complex + + + v_offset + 0 + + + v_scale + 0 + + + win_size + + + + xy_mode + False + + + y_axis_label + Counts + analog_sig_source_x_0 @@ -758,12 +798,6 @@ 0 0 - - ha5kfu_execproc_xx_0 - wxgui_fftsink2_0 - 0 - 0 - blocks_throttle_0 wxgui_fftsink2_0_0 @@ -776,6 +810,12 @@ 0 0 + + ha5kfu_execproc_xx_0 + wxgui_fftsink2_0 + 0 + 0 + ha5kfu_execproc_xx_0 wxgui_scopesink2_0_0 diff --git a/grc_tests/test_fastddc.grc b/grc_tests/test_fastddc.grc new file mode 100644 index 0000000..5c3706e --- /dev/null +++ b/grc_tests/test_fastddc.grc @@ -0,0 +1,689 @@ + + + + Sat Nov 15 20:06:19 2014 + + options + + author + + + + window_size + 1280, 1024 + + + category + Custom + + + comment + + + + description + + + + _enabled + True + + + _coordinate + (10, 10) + + + _rotation + 0 + + + generate_options + wx_gui + + + id + top_block + + + max_nouts + 0 + + + realtime_scheduling + + + + run_options + prompt + + + run + True + + + thread_safe_setters + + + + title + + + + + variable_slider + + comment + + + + converver + float_converter + + + value + 50 + + + _enabled + True + + + _coordinate + (16, 267) + + + _rotation + 0 + + + grid_pos + + + + id + freq + + + label + + + + max + samp_rate/2 + + + min + -samp_rate/2 + + + notebook + + + + num_steps + 100 + + + style + wx.SL_HORIZONTAL + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (9, 170) + + + _rotation + 0 + + + id + samp_rate + + + value + 250000 + + + + analog_sig_source_x + + amp + 0.2 + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + freq + freq + + + _coordinate + (224, 29) + + + _rotation + 0 + + + id + analog_sig_source_x_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + offset + 0 + + + type + complex + + + samp_rate + samp_rate + + + waveform + analog.GR_COS_WAVE + + + + blocks_throttle + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (424, 59) + + + _rotation + 0 + + + id + blocks_throttle_0 + + + ignoretag + True + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + samples_per_second + samp_rate + + + type + complex + + + vlen + 1 + + + + ha5kfu_execproc_xx + + alias + + + + commandline + csdr fastddc_fwd_cc 10 | csdr fastddc_apply_cc 10 0.1 | csdr floatdump_f 2>&1 | head -n 100 + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (584, 59) + + + _rotation + 0 + + + id + ha5kfu_execproc_xx_1 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + type + cc + + + + notebook + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (160, 283) + + + _rotation + 0 + + + grid_pos + + + + id + nb + + + labels + ['FFT', 'Scope'] + + + notebook + + + + style + wx.NB_TOP + + + + wxgui_fftsink2 + + avg_alpha + 0 + + + average + False + + + baseband_freq + 0 + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + fft_size + 1024 + + + freqvar + None + + + _coordinate + (936, 155) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_fftsink2_0 + + + notebook + nb, 0 + + + peak_hold + False + + + ref_level + 0 + + + ref_scale + 2.0 + + + fft_rate + 15 + + + samp_rate + samp_rate + + + title + FFT plot of csdr processed signal + + + type + complex + + + win_size + + + + win + None + + + y_divs + 10 + + + y_per_div + 10 + + + + wxgui_fftsink2 + + avg_alpha + 0 + + + average + False + + + baseband_freq + 0 + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + fft_size + 1024 + + + freqvar + None + + + _coordinate + (936, 371) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_fftsink2_0_0 + + + notebook + + + + peak_hold + False + + + ref_level + 0 + + + ref_scale + 2.0 + + + fft_rate + 15 + + + samp_rate + samp_rate + + + title + FFT plot of original signal + + + type + complex + + + win_size + + + + win + None + + + y_divs + 10 + + + y_per_div + 10 + + + + wxgui_scopesink2 + + ac_couple + False + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (952, 35) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_scopesink2_0 + + + notebook + nb, 1 + + + num_inputs + 1 + + + samp_rate + samp_rate + + + t_scale + 0 + + + title + Scope plot of csdr processed signal + + + trig_mode + wxgui.TRIG_MODE_AUTO + + + type + complex + + + v_offset + 0 + + + v_scale + 0 + + + win_size + + + + xy_mode + False + + + y_axis_label + Counts + + + + analog_sig_source_x_0 + blocks_throttle_0 + 0 + 0 + + + blocks_throttle_0 + ha5kfu_execproc_xx_1 + 0 + 0 + + + blocks_throttle_0 + wxgui_fftsink2_0_0 + 0 + 0 + + + ha5kfu_execproc_xx_1 + wxgui_fftsink2_0 + 0 + 0 + + + ha5kfu_execproc_xx_1 + wxgui_scopesink2_0 + 0 + 0 + +