From 32f807a8c8f1bcadfd8f8ad4c5a46c1b099f8c8f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 2 May 2012 16:14:09 -0400 Subject: filter: Reworking filter to have a set of basic implementation classes for filters of different kinds. The GR blocks are templated now and call from fir_filters for the volk-specific implemenation. Note the modification to build_utils.py to accomodate these changes. --- gr-filter/include/filter/CMakeLists.txt | 15 ++- gr-filter/include/filter/fft.h | 195 ---------------------------- gr-filter/include/filter/fft_vcc.h | 57 -------- gr-filter/include/filter/fir_filter.h | 112 ++++++++++++++++ gr-filter/include/filter/fir_filter_XXX.h.t | 55 ++++++++ gr-filter/include/filter/fir_filter_fff.h | 53 -------- 6 files changed, 175 insertions(+), 312 deletions(-) delete mode 100644 gr-filter/include/filter/fft.h delete mode 100644 gr-filter/include/filter/fft_vcc.h create mode 100644 gr-filter/include/filter/fir_filter.h create mode 100644 gr-filter/include/filter/fir_filter_XXX.h.t delete mode 100644 gr-filter/include/filter/fir_filter_fff.h (limited to 'gr-filter/include') diff --git a/gr-filter/include/filter/CMakeLists.txt b/gr-filter/include/filter/CMakeLists.txt index a3c83f3dc..4889312da 100644 --- a/gr-filter/include/filter/CMakeLists.txt +++ b/gr-filter/include/filter/CMakeLists.txt @@ -32,7 +32,7 @@ os.chdir('${CMAKE_CURRENT_BINARY_DIR}') if __name__ == '__main__': import build_utils - root, inp = sys.argv[1:3] + root, inp = sys.argv[1:3] for sig in sys.argv[3:]: name = re.sub ('X+', sig, root) d = build_utils.standard_dict2(name, sig, 'filter') @@ -64,19 +64,20 @@ endmacro(expand_h) ######################################################################## # Invoke macro to generate various sources ####################################################################### -#expand_h(fir_filter_XXX fff ccc ccf fcc fsf scc) +expand_h(fir_filter_XXX fff ccf ccc) -#add_custom_target(filter_generated_includes DEPENDS -# ${generated_includes} -#) +add_custom_target(filter_generated_includes DEPENDS + ${generated_includes} +) ######################################################################## # Install header files ######################################################################## install(FILES api.h - fir_filter_fff.h - DESTINATION ${GR_INCLUDE_DIR}/gnuradio/fft + fir_filter.h + ${generated_includes} + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/filter COMPONENT "fft_devel" ) diff --git a/gr-filter/include/filter/fft.h b/gr-filter/include/filter/fft.h deleted file mode 100644 index 5cc2e21e8..000000000 --- a/gr-filter/include/filter/fft.h +++ /dev/null @@ -1,195 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003,2008,2012 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 _FFT_FFT_H_ -#define _FFT_FFT_H_ - -/* - * Wrappers for FFTW single precision 1d dft - */ - -#include -#include -#include - -namespace gr { - namespace fft { - - - /*! \brief Helper function for allocating complex fft buffers - */ - gr_complex* malloc_complex(int size); - - /*! \brief Helper function for allocating float fft buffers - */ - float* malloc_float(int size); - - /*! \brief Helper function for freeing fft buffers - */ - void free(void *b); - - /*! - * \brief Export reference to planner mutex for those apps that - * want to use FFTW w/o using the fft_impl_fftw* classes. - */ - class FFT_API planner { - public: - typedef boost::mutex::scoped_lock scoped_lock; - /*! - * Return reference to planner mutex - */ - static boost::mutex &mutex(); - }; - - /*! - * \brief FFT: complex in, complex out - * \ingroup misc - */ - class FFT_API fft_complex { - int d_fft_size; - int d_nthreads; - gr_complex *d_inbuf; - gr_complex *d_outbuf; - void *d_plan; - - public: - fft_complex(int fft_size, bool forward = true, int nthreads=1); - virtual ~fft_complex(); - - /* - * These return pointers to buffers owned by fft_impl_fft_complex - * into which input and output take place. It's done this way in - * order to ensure optimal alignment for SIMD instructions. - */ - gr_complex *get_inbuf() const { return d_inbuf; } - gr_complex *get_outbuf() const { return d_outbuf; } - - int inbuf_length() const { return d_fft_size; } - int outbuf_length() const { return d_fft_size; } - - /*! - * Set the number of threads to use for caclulation. - */ - void set_nthreads(int n); - - /*! - * Get the number of threads being used by FFTW - */ - int nthreads() const { return d_nthreads; } - - /*! - * compute FFT. The input comes from inbuf, the output is placed in - * outbuf. - */ - void execute(); - }; - - /*! - * \brief FFT: real in, complex out - * \ingroup misc - */ - class FFT_API fft_real_fwd { - int d_fft_size; - int d_nthreads; - float *d_inbuf; - gr_complex *d_outbuf; - void *d_plan; - - public: - fft_real_fwd (int fft_size, int nthreads=1); - virtual ~fft_real_fwd (); - - /* - * These return pointers to buffers owned by fft_impl_fft_real_fwd - * into which input and output take place. It's done this way in - * order to ensure optimal alignment for SIMD instructions. - */ - float *get_inbuf() const { return d_inbuf; } - gr_complex *get_outbuf() const { return d_outbuf; } - - int inbuf_length() const { return d_fft_size; } - int outbuf_length() const { return d_fft_size / 2 + 1; } - - /*! - * Set the number of threads to use for caclulation. - */ - void set_nthreads(int n); - - /*! - * Get the number of threads being used by FFTW - */ - int nthreads() const { return d_nthreads; } - - /*! - * compute FFT. The input comes from inbuf, the output is placed in - * outbuf. - */ - void execute(); - }; - - /*! - * \brief FFT: complex in, float out - * \ingroup misc - */ - class FFT_API fft_real_rev { - int d_fft_size; - int d_nthreads; - gr_complex *d_inbuf; - float *d_outbuf; - void *d_plan; - - public: - fft_real_rev(int fft_size, int nthreads=1); - virtual ~fft_real_rev(); - - /* - * These return pointers to buffers owned by fft_impl_fft_real_rev - * into which input and output take place. It's done this way in - * order to ensure optimal alignment for SIMD instructions. - */ - gr_complex *get_inbuf() const { return d_inbuf; } - float *get_outbuf() const { return d_outbuf; } - - int inbuf_length() const { return d_fft_size / 2 + 1; } - int outbuf_length() const { return d_fft_size; } - - /*! - * Set the number of threads to use for caclulation. - */ - void set_nthreads(int n); - - /*! - * Get the number of threads being used by FFTW - */ - int nthreads() const { return d_nthreads; } - - /*! - * compute FFT. The input comes from inbuf, the output is placed in - * outbuf. - */ - void execute(); - }; - - } /* namespace fft */ -} /*namespace gr */ - -#endif /* _FFT_FFT_H_ */ diff --git a/gr-filter/include/filter/fft_vcc.h b/gr-filter/include/filter/fft_vcc.h deleted file mode 100644 index 561ae858d..000000000 --- a/gr-filter/include/filter/fft_vcc.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2007,2008,2012 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_FFT_FFT_VCC_H -#define INCLUDED_FFT_FFT_VCC_H - -#include -#include - -namespace gr { - namespace fft { - - class FFT_API fft_vcc : virtual public gr_sync_block - { - public: - - // gr::fft::fft_vcc::sptr - typedef boost::shared_ptr sptr; - - /*! - * \brief Compute forward or reverse FFT. complex vector in / complex vector out. - * \ingroup dft_blk - */ - static FFT_API sptr make(int fft_size, bool forward, - const std::vector &window, - bool shift=false, int nthreads=1); - - virtual void set_nthreads(int n) = 0; - - virtual int nthreads() const = 0; - - virtual bool set_window(const std::vector &window) = 0; - }; - - } /* namespace fft */ -} /* namespace gr */ - -#endif /* INCLUDED_FFT_FFT_VCC_H */ diff --git a/gr-filter/include/filter/fir_filter.h b/gr-filter/include/filter/fir_filter.h new file mode 100644 index 000000000..c307fea46 --- /dev/null +++ b/gr-filter/include/filter/fir_filter.h @@ -0,0 +1,112 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010,2012 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. + */ + +#include +#include +#include + +namespace gr { + namespace filter { + namespace impl { + + class FILTER_API fir_filter_fff + { + public: + fir_filter_fff(int decimation, + const std::vector &taps); + ~fir_filter_fff(); + + void set_taps(const std::vector &taps); + std::vector taps() const; + unsigned int ntaps() const; + + float filter(const float input[]); + void filterN(float output[], + const float input[], + unsigned long n); + void filterNdec(float output[], + const float input[], + unsigned long n, + unsigned int decimate); + + private: + unsigned int d_ntaps; + float *d_taps; + }; + + /**************************************************************/ + + class FILTER_API fir_filter_ccf + { + public: + fir_filter_ccf(int decimation, + const std::vector &taps); + ~fir_filter_ccf(); + + void set_taps(const std::vector &taps); + std::vector taps() const; + unsigned int ntaps() const; + + gr_complex filter(const gr_complex input[]); + void filterN(gr_complex output[], + const gr_complex input[], + unsigned long n); + void filterNdec(gr_complex output[], + const gr_complex input[], + unsigned long n, + unsigned int decimate); + + private: + unsigned int d_ntaps; + gr_complex *d_taps; + }; + + /**************************************************************/ + + class FILTER_API fir_filter_ccc + { + public: + fir_filter_ccc(int decimation, + const std::vector &taps); + ~fir_filter_ccc(); + + void set_taps(const std::vector &taps); + std::vector taps() const; + unsigned int ntaps() const; + + gr_complex filter(const gr_complex input[]); + void filterN(gr_complex output[], + const gr_complex input[], + unsigned long n); + void filterNdec(gr_complex output[], + const gr_complex input[], + unsigned long n, + unsigned int decimate); + + private: + unsigned int d_ntaps; + gr_complex *d_taps; + }; + + } /* namespace impl */ + } /* namespace filter */ +} /* namespace gr */ diff --git a/gr-filter/include/filter/fir_filter_XXX.h.t b/gr-filter/include/filter/fir_filter_XXX.h.t new file mode 100644 index 000000000..ef6b8bfc9 --- /dev/null +++ b/gr-filter/include/filter/fir_filter_XXX.h.t @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2012 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. + */ + +/* @WARNING@ */ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include +#include + +namespace gr { + namespace filter { + + class FILTER_API @BASE_NAME@ : virtual public gr_sync_decimator + { + public: + + // gr::filter::@BASE_NAME@::sptr + typedef boost::shared_ptr<@BASE_NAME@> sptr; + + /*! + * \brief FIR filter with @I_TYPE@ input, @O_TYPE@ output, and @TAP_TYPE@ taps + * \ingroup filter_blk + */ + static FILTER_API sptr make(int decimation, + const std::vector<@TAP_TYPE@> &taps); + + virtual void set_taps (const std::vector<@TAP_TYPE@> &taps) = 0; + virtual std::vector<@TAP_TYPE@> taps () const = 0; + }; + + } /* namespace filter */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-filter/include/filter/fir_filter_fff.h b/gr-filter/include/filter/fir_filter_fff.h deleted file mode 100644 index 5b6d19b34..000000000 --- a/gr-filter/include/filter/fir_filter_fff.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2012 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 FILTER_FIR_FILTER_FFF_H -#define FILTER_FIR_FILTER_FFF_H - -#include -#include - -namespace gr { - namespace filter { - - class FILTER_API fir_filter_fff : virtual public gr_sync_decimator - { - public: - - // gr::filter::fir_filter_fff::sptr - typedef boost::shared_ptr sptr; - - /*! - * \brief FIR filter with float input, float output, and float taps - * \ingroup filter_blk - */ - static FILTER_API sptr make(int decimation, - const std::vector &taps); - - virtual void set_taps (const std::vector &taps) = 0; - virtual std::vector taps () const = 0; - }; - - } /* namespace filter */ -} /* namespace gr */ - -#endif /* FILTER_FIR_FILTER_FFF_H */ -- cgit