From bfe88c1e10d5c4a7e2bd44477422f4a93d1d83dc Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Sun, 9 Apr 2017 19:00:07 +0200 Subject: [PATCH] Working FIR resonator and related GRC test --- csdr.c | 19 +- grc_tests/test_bpsk31_to_octave.grc | 675 +++++++++++++++++++++++++ grc_tests/test_resonators_fir.grc | 752 ++++++++++++++++++++++++++++ libcsdr.c | 35 +- libcsdr.h | 2 +- 5 files changed, 1457 insertions(+), 26 deletions(-) create mode 100644 grc_tests/test_bpsk31_to_octave.grc create mode 100644 grc_tests/test_resonators_fir.grc diff --git a/csdr.c b/csdr.c index 4180d8c..73e6234 100755 --- a/csdr.c +++ b/csdr.c @@ -2719,10 +2719,10 @@ int main(int argc, char *argv[]) int octave=(argc>=6 && !strcmp("--octave",argv[5])); - complexf* taps=(complexf*)calloc(sizeof(complexf),length); + complexf* taps=(complexf*)malloc(sizeof(complexf)*length); //Make the filter - firdes_add_resonator_c(taps, length, rate, window); + firdes_add_resonator_c(taps, length, rate, window, 0, 1); //Do the output if(octave) printf("taps=["); @@ -2744,6 +2744,7 @@ int main(int argc, char *argv[]) if(!strcmp(argv[1],"resonators_fir_cc")) // { + //rule of thumb: bw = 2/taps_length, which does not equal to transition_bw if(argc<=2) return badsyntax("need required parameter (taps_length)"); int taps_length; @@ -2754,24 +2755,20 @@ int main(int argc, char *argv[]) for(int i=0;i + + + Mon Oct 13 20:03:23 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 + + comment + + + + _enabled + True + + + _coordinate + (184, 11) + + + _rotation + 0 + + + id + samp_rate + + + value + 48e3 + + + + audio_source + + alias + + + + comment + + + + affinity + + + + device_name + + + + _enabled + True + + + _coordinate + (56, 107) + + + _rotation + 0 + + + id + audio_source_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + num_outputs + 1 + + + ok_to_block + True + + + samp_rate + int(samp_rate) + + + + blocks_file_sink + + append + False + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + file + /home/pcfl/Asztal/szakdoga/dipterv1/bpsk31_input_f.raw + + + _coordinate + (232, 251) + + + _rotation + 0 + + + id + blocks_file_sink_0 + + + type + float + + + unbuffered + False + + + vlen + 1 + + + + blocks_file_sink + + append + False + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + file + /home/pcfl/Asztal/szakdoga/dipterv1/bpsk31_baseband_c.raw + + + _coordinate + (1032, 91) + + + _rotation + 0 + + + id + blocks_file_sink_0_0 + + + type + complex + + + unbuffered + False + + + vlen + 1 + + + + freq_xlating_fir_filter_xxx + + alias + + + + center_freq + 2000 + + + comment + + + + affinity + + + + decim + 1 + + + _enabled + True + + + _coordinate + (296, 123) + + + _rotation + 0 + + + id + freq_xlating_fir_filter_xxx_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + samp_rate + samp_rate + + + taps + [1] + + + type + fcc + + + + low_pass_filter + + beta + 6.76 + + + alias + + + + comment + + + + affinity + + + + cutoff_freq + 1000 + + + decim + 1 + + + _enabled + True + + + type + fir_filter_ccf + + + _coordinate + (536, 99) + + + _rotation + 0 + + + gain + 1 + + + id + low_pass_filter_0 + + + interp + 1 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + samp_rate + samp_rate + + + width + 100 + + + win + firdes.WIN_HAMMING + + + + notebook + + alias + + + + comment + + + + _enabled + True + + + _coordinate + (280, 11) + + + _rotation + 0 + + + grid_pos + + + + id + nb + + + labels + ['tab1', 'tab2', 'tab3', 'tab4'] + + + 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 + (1032, 187) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_fftsink2_0 + + + notebook + + + + peak_hold + False + + + ref_level + 0 + + + ref_scale + 2.0 + + + fft_rate + 15 + + + samp_rate + samp_rate + + + title + FFT Plot + + + 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 + (232, 339) + + + _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 + + + type + float + + + win_size + + + + win + None + + + y_divs + 10 + + + y_per_div + 10 + + + + audio_source_0 + blocks_file_sink_0 + 0 + 0 + + + audio_source_0 + freq_xlating_fir_filter_xxx_0 + 0 + 0 + + + audio_source_0 + wxgui_fftsink2_0_0 + 0 + 0 + + + freq_xlating_fir_filter_xxx_0 + low_pass_filter_0 + 0 + 0 + + + low_pass_filter_0 + blocks_file_sink_0_0 + 0 + 0 + + + low_pass_filter_0 + wxgui_fftsink2_0 + 0 + 0 + + diff --git a/grc_tests/test_resonators_fir.grc b/grc_tests/test_resonators_fir.grc new file mode 100644 index 0000000..f3c6324 --- /dev/null +++ b/grc_tests/test_resonators_fir.grc @@ -0,0 +1,752 @@ + + + + Sun Nov 16 15:12:31 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 + + comment + + + + _enabled + True + + + _coordinate + (8, 83) + + + _rotation + 0 + + + id + samp_rate + + + value + 100e3 + + + + analog_random_source_x + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (8, 155) + + + _rotation + 0 + + + id + analog_random_source_x_0 + + + maxoutbuf + 0 + + + max + 2147483647 + + + minoutbuf + 0 + + + min + -2147483648 + + + num_samps + 1000 + + + type + int + + + repeat + True + + + + blocks_deinterleave + + alias + + + + blocksize + 1 + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (384, 169) + + + _rotation + 0 + + + id + blocks_deinterleave_0 + + + type + float + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + num_streams + 2 + + + vlen + 1 + + + + blocks_float_to_complex + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (544, 169) + + + _rotation + 0 + + + id + blocks_float_to_complex_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + + + blocks_int_to_float + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (208, 179) + + + _rotation + 0 + + + id + blocks_int_to_float_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + scale + 2147483647. + + + vlen + 1 + + + + blocks_throttle + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (736, 179) + + + _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 resonators_fir_cc 101 -0.2 -0.1 0 0.1 0.2 + + + comment + + + + affinity + + + + _enabled + 1 + + + _coordinate + (168, 339) + + + _rotation + 0 + + + id + ha5kfu_execproc_xx_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + type + cc + + + + wxgui_fftsink2 + + avg_alpha + 0 + + + average + False + + + baseband_freq + 0 + + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + fft_size + 1024 + + + freqvar + None + + + _coordinate + (472, 435) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_fftsink2_0 + + + notebook + + + + peak_hold + False + + + ref_level + 0 + + + ref_scale + 2.0 + + + fft_rate + 15 + + + samp_rate + samp_rate + + + title + FFT Plot + + + 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 + (976, 107) + + + _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 + + + type + complex + + + win_size + + + + win + None + + + y_divs + 10 + + + y_per_div + 10 + + + + wxgui_scopesink2 + + ac_couple + False + + + alias + + + + comment + + + + affinity + + + + _enabled + 0 + + + _coordinate + (480, 299) + + + _rotation + 0 + + + grid_pos + + + + id + wxgui_scopesink2_0 + + + notebook + + + + num_inputs + 1 + + + samp_rate + samp_rate + + + t_scale + 0 + + + title + Scope Plot + + + trig_mode + wxgui.TRIG_MODE_AUTO + + + type + complex + + + v_offset + 0 + + + v_scale + 0 + + + win_size + + + + xy_mode + False + + + y_axis_label + Counts + + + + analog_random_source_x_0 + blocks_int_to_float_0 + 0 + 0 + + + blocks_deinterleave_0 + blocks_float_to_complex_0 + 0 + 0 + + + blocks_deinterleave_0 + blocks_float_to_complex_0 + 1 + 1 + + + blocks_float_to_complex_0 + blocks_throttle_0 + 0 + 0 + + + blocks_int_to_float_0 + blocks_deinterleave_0 + 0 + 0 + + + blocks_throttle_0 + ha5kfu_execproc_xx_0 + 0 + 0 + + + blocks_throttle_0 + wxgui_fftsink2_0_0 + 0 + 0 + + + ha5kfu_execproc_xx_0 + wxgui_fftsink2_0 + 0 + 0 + + + ha5kfu_execproc_xx_0 + wxgui_scopesink2_0 + 0 + 0 + + diff --git a/libcsdr.c b/libcsdr.c index d8e93f3..c62cb5b 100755 --- a/libcsdr.c +++ b/libcsdr.c @@ -2009,8 +2009,10 @@ void simple_agc_cc(complexf* input, complexf* output, int input_size, float rate } } -void firdes_add_resonator_c(complexf* output, int length, float rate, window_t window) +void firdes_add_resonator_c(complexf* output, int length, float rate, window_t window, int add, int normalize) { + //add=0: malloc output previously + //add=1: calloc output previously complexf* taps = (complexf*)malloc(sizeof(complexf)*length); int middle=length/2; float phase = 0, phase_addition = -rate*M_PI*2; @@ -2027,20 +2029,25 @@ void firdes_add_resonator_c(complexf* output, int length, float rate, window_t w } //Normalize filter kernel - float sum=0; - for(int i=0;i