From 691209a1fd00052002af42d79d7a8aff56b7df27 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 9 Dec 2009 23:58:17 -0500 Subject: [PATCH] Adding a band-edge based frequency lock loop. --- gnuradio-core/src/lib/general/Makefile.am | 3 + gnuradio-core/src/lib/general/general.i | 2 + .../src/lib/general/gr_fll_band_edge_cc.cc | 146 ++++++++++++++++++ .../src/lib/general/gr_fll_band_edge_cc.h | 90 +++++++++++ .../src/lib/general/gr_fll_band_edge_cc.i | 36 +++++ grc/blocks/Makefile.am | 1 + grc/blocks/block_tree.xml | 2 + grc/blocks/gr_fll_band_edge_cc.xml | 40 +++++ 8 files changed, 320 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_fll_band_edge_cc.cc create mode 100644 gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h create mode 100644 gnuradio-core/src/lib/general/gr_fll_band_edge_cc.i create mode 100644 grc/blocks/gr_fll_band_edge_cc.xml diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index cf6ff1e6..ecef7d6e 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -76,6 +76,7 @@ libgeneral_la_SOURCES = \ gr_fft_vcc_fftw.cc \ gr_fft_vfc.cc \ gr_firdes.cc \ + gr_fll_band_edge_cc.cc \ gr_float_to_char.cc \ gr_float_to_complex.cc \ gr_float_to_short.cc \ @@ -229,6 +230,7 @@ grinclude_HEADERS = \ gr_fft_vcc_fftw.h \ gr_fft_vfc.h \ gr_firdes.h \ + gr_fll_band_edge_cc.h \ gr_float_to_char.h \ gr_float_to_complex.h \ gr_float_to_short.h \ @@ -396,6 +398,7 @@ swiginclude_HEADERS = \ gr_fft_vcc.i \ gr_fft_vfc.i \ gr_firdes.i \ + gr_fll_band_edge_cc.i \ gr_float_to_char.i \ gr_float_to_complex.i \ gr_float_to_short.i \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index e1161c8e..2c26b59c 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -140,6 +140,7 @@ #include #include #include +#include %} %include "gr_nop.i" @@ -260,3 +261,4 @@ %include "gr_wavelet_ff.i" %include "gr_wvps_ff.i" %include "gr_copy.i" +%include "gr_fll_band_edge_cc.i" diff --git a/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.cc b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.cc new file mode 100644 index 00000000..946fc1e8 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.cc @@ -0,0 +1,146 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define M_TWOPI (2*M_PI) + +gr_fll_band_edge_cc_sptr gr_make_fll_band_edge_cc (const std::vector &taps) +{ + return gr_fll_band_edge_cc_sptr (new gr_fll_band_edge_cc (taps)); +} + + +gr_fll_band_edge_cc::gr_fll_band_edge_cc (const std::vector &taps) + : gr_sync_block ("fll_band_edge_cc", + gr_make_io_signature (1, 1, sizeof(gr_complex)), + gr_make_io_signature (1, 1, sizeof(gr_complex))), + d_updated (false) +{ + d_alpha = 0.01; + d_beta = 0.25*d_alpha*d_alpha; + d_max_freq = M_TWOPI * 0.25; + d_min_freq = M_TWOPI * -0.5; + + d_freq = 0; + d_phase = 0; + + std::vector vtaps(0, taps.size()); + d_filter_upper = gr_fir_util::create_gr_fir_ccc(vtaps); + d_filter_lower = gr_fir_util::create_gr_fir_ccc(vtaps); + + set_taps(taps); +} + +gr_fll_band_edge_cc::~gr_fll_band_edge_cc () +{ +} + +void +gr_fll_band_edge_cc::set_taps (const std::vector &taps) +{ + unsigned int i; + + for(i = 0; i < taps.size(); i++) { + d_taps_upper.push_back(taps[i]); + d_taps_lower.push_back(conj(taps[i])); + } + + d_filter_upper->set_taps(d_taps_upper); + d_filter_lower->set_taps(d_taps_lower); + + // Set the history to ensure enough input items for each filter + set_history(d_taps_upper.size()+1); + + d_updated = true; +} + +void +gr_fll_band_edge_cc::print_taps() +{ + unsigned int i; + printf("Upper Band-edge: ["); + for(i = 0; i < d_taps_upper.size(); i++) { + printf(" %.4e + j%.4e,", d_taps_upper[i].real(), d_taps_upper[i].imag()); + } + printf("]\n\n"); + + printf("Lower Band-edge: ["); + for(i = 0; i < d_taps_lower.size(); i++) { + printf(" %.4e + j%.4e,", d_taps_lower[i].real(), d_taps_lower[i].imag()); + } + printf("]\n\n"); +} + +int +gr_fll_band_edge_cc::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + + if (d_updated) { + d_updated = false; + return 0; // history requirements may have changed. + } + + int i; + gr_complex nco_out; + float out_upper, out_lower; + float error; + for(i = 0; i < noutput_items; i++) { + nco_out = gr_expj(d_phase); + out[i] = in[i] * nco_out; + + out_upper = norm(d_filter_upper->filter(&out[i])); + out_lower = norm(d_filter_lower->filter(&out[i])); + error = 0.1*(out_lower - out_upper); + printf("error: %f\n", out_upper); + + d_freq = d_freq + d_beta * error; + d_phase = d_phase + d_freq + d_alpha * error; + + if(d_phase > M_PI) + d_phase -= M_TWOPI; + else if(d_phase < -M_PI) + d_phase += M_TWOPI; + + if (d_freq > d_max_freq) + d_freq = d_max_freq; + else if (d_freq < d_min_freq) + d_freq = d_min_freq; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h new file mode 100644 index 00000000..1c47167f --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h @@ -0,0 +1,90 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef INCLUDED_GR_FLL_BAND_EDGE_CC_H +#define INCLUDED_GR_FLL_BAND_EDGE_CC_H + +#include + +class gr_fll_band_edge_cc; +typedef boost::shared_ptr gr_fll_band_edge_cc_sptr; +gr_fll_band_edge_cc_sptr gr_make_fll_band_edge_cc (const std::vector &taps); + +class gr_fir_ccc; +class gri_fft_complex; + +/*! + * \class gr_fll_band_edge_cc + * \brief Frequency Lock Loop using band-edge filters + * + * \ingroup general + */ + +class gr_fll_band_edge_cc : public gr_sync_block +{ + private: + /*! + * Build the FLL + * \param taps (vector/list of gr_complex) The taps of the band-edge filter + */ + friend gr_fll_band_edge_cc_sptr gr_make_fll_band_edge_cc (const std::vector &taps); + + float d_alpha; + float d_beta; + float d_max_freq; + float d_min_freq; + + gr_fir_ccc* d_filter_upper; + gr_fir_ccc* d_filter_lower; + std::vector d_taps_upper; + std::vector d_taps_lower; + bool d_updated; + float d_freq; + float d_phase; + + /*! + * Build the FLL + * \param taps (vector/list of gr_complex) The taps of the band-edge filter + */ + gr_fll_band_edge_cc(const std::vector &taps); + +public: + ~gr_fll_band_edge_cc (); + + /*! + * Resets the filter taps with the new prototype filter + * \param taps (vector/list of gr_complex) The band-edge filter + */ + void set_taps (const std::vector &taps); + + /*! + * Print the taps to screen. + */ + void print_taps(); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.i b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.i new file mode 100644 index 00000000..a550bec4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.i @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,fll_band_edge_cc); + +gr_fll_band_edge_cc_sptr gr_make_fll_band_edge_cc (const std::vector &taps); + +class gr_fll_band_edge_cc : public gr_sync_block +{ + private: + gr_fll_band_edge_cc (const std::vector &taps); + + public: + ~gr_fll_band_edge_cc (); + + void set_taps (const std::vector &taps); +}; diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index 9c91af54..a284d6d8 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -108,6 +108,7 @@ dist_ourdata_DATA = \ gr_file_source.xml \ gr_filter_delay_fc.xml \ gr_fir_filter_xxx.xml \ + gr_fll_band_edge_cc.xml \ gr_float_to_char.xml \ gr_float_to_complex.xml \ gr_float_to_short.xml \ diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 57703f6d..ba597756 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -138,6 +138,8 @@ gr_pll_freqdet_cf gr_pll_refout_cc + gr_fll_band_edge_cc + gr_correlate_access_code_bb gr_pn_correlator_cc gr_simple_correlator diff --git a/grc/blocks/gr_fll_band_edge_cc.xml b/grc/blocks/gr_fll_band_edge_cc.xml new file mode 100644 index 00000000..4fe2c03f --- /dev/null +++ b/grc/blocks/gr_fll_band_edge_cc.xml @@ -0,0 +1,40 @@ + + + + FLL Band-Edge + gr_fll_band_edge_cc + from gnuradio import gr + gr.fll_band_edge_cc($taps) + set_taps($taps) + + + Type + type + enum + + + + + Taps + taps + complex_vector + + + in + $type.input + + + out + $type.output + + -- 2.30.2