diff options
author | Tom | 2009-12-09 23:58:17 -0500 |
---|---|---|
committer | Tom | 2009-12-09 23:58:17 -0500 |
commit | 691209a1fd00052002af42d79d7a8aff56b7df27 (patch) | |
tree | 62c22b25cb2cbb71f0fc3c89382d8d339442bf15 /gnuradio-core/src | |
parent | 65269307fcdf3228a3fcd6f33d6a4be2530f1654 (diff) | |
download | gnuradio-691209a1fd00052002af42d79d7a8aff56b7df27.tar.gz gnuradio-691209a1fd00052002af42d79d7a8aff56b7df27.tar.bz2 gnuradio-691209a1fd00052002af42d79d7a8aff56b7df27.zip |
Adding a band-edge based frequency lock loop.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/general/Makefile.am | 3 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_fll_band_edge_cc.cc | 146 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h | 90 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_fll_band_edge_cc.i | 36 |
5 files changed, 277 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index cf6ff1e65..ecef7d6e3 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 e1161c8eb..2c26b59cd 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -140,6 +140,7 @@ #include <gr_wavelet_ff.h> #include <gr_wvps_ff.h> #include <gr_copy.h> +#include <gr_fll_band_edge_cc.h> %} %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 000000000..946fc1e85 --- /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 <gr_fll_band_edge_cc.h> +#include <gr_fir_ccc.h> +#include <gr_fir_util.h> +#include <gri_fft.h> +#include <gr_io_signature.h> +#include <gr_expj.h> +#include <gr_math.h> +#include <cstdio> + +#define M_TWOPI (2*M_PI) + +gr_fll_band_edge_cc_sptr gr_make_fll_band_edge_cc (const std::vector<gr_complex> &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<gr_complex> &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<gr_complex> 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<gr_complex> &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 000000000..1c47167f8 --- /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 <gr_sync_block.h> + +class gr_fll_band_edge_cc; +typedef boost::shared_ptr<gr_fll_band_edge_cc> gr_fll_band_edge_cc_sptr; +gr_fll_band_edge_cc_sptr gr_make_fll_band_edge_cc (const std::vector<gr_complex> &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<gr_complex> &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<gr_complex> d_taps_upper; + std::vector<gr_complex> 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<gr_complex> &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<gr_complex> &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 000000000..a550bec4e --- /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<gr_complex> &taps); + +class gr_fll_band_edge_cc : public gr_sync_block +{ + private: + gr_fll_band_edge_cc (const std::vector<gr_complex> &taps); + + public: + ~gr_fll_band_edge_cc (); + + void set_taps (const std::vector<gr_complex> &taps); +}; |