diff options
author | Tom Rondeau | 2012-04-26 20:05:59 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-04-27 23:20:28 -0400 |
commit | d79054551fee36eda99a142aff2856f20b4787fa (patch) | |
tree | 4148248086ced3aad44cd38f616106c27af2368e /gr-fft/include | |
parent | 03d62861b6f1294cdf0e9ff1c8672a7973ebc9db (diff) | |
download | gnuradio-d79054551fee36eda99a142aff2856f20b4787fa.tar.gz gnuradio-d79054551fee36eda99a142aff2856f20b4787fa.tar.bz2 gnuradio-d79054551fee36eda99a142aff2856f20b4787fa.zip |
gr-fft: creates a gr-fft top-level component.
Diffstat (limited to 'gr-fft/include')
-rw-r--r-- | gr-fft/include/fft/CMakeLists.txt | 33 | ||||
-rw-r--r-- | gr-fft/include/fft/api.h | 33 | ||||
-rw-r--r-- | gr-fft/include/fft/fft_impl_fft.h | 189 | ||||
-rw-r--r-- | gr-fft/include/fft/fft_impl_goertzel.h | 57 | ||||
-rw-r--r-- | gr-fft/include/fft/fft_vcc.h | 60 | ||||
-rw-r--r-- | gr-fft/include/fft/fft_vfc.h | 60 | ||||
-rw-r--r-- | gr-fft/include/fft/goertzel_fc.h | 63 |
7 files changed, 495 insertions, 0 deletions
diff --git a/gr-fft/include/fft/CMakeLists.txt b/gr-fft/include/fft/CMakeLists.txt new file mode 100644 index 000000000..33a8a1d21 --- /dev/null +++ b/gr-fft/include/fft/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright 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. + +######################################################################## +# Install header files +######################################################################## +install(FILES + api.h + fft_vcc.h + fft_vfc.h + goertzel_fc.h + fft_impl_fft.h + fft_impl_goertzel.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/fft + COMPONENT "fft_devel" +) + diff --git a/gr-fft/include/fft/api.h b/gr-fft/include/fft/api.h new file mode 100644 index 000000000..eef456373 --- /dev/null +++ b/gr-fft/include/fft/api.h @@ -0,0 +1,33 @@ +/* + * Copyright 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_API_H +#define INCLUDED_FFT_API_H + +#include <gruel/attributes.h> + +#ifdef gnuradio_fft_EXPORTS +# define FFT_API __GR_ATTR_EXPORT +#else +# define FFT_API __GR_ATTR_IMPORT +#endif + +#endif /* INCLUDED_FFT_API_H */ diff --git a/gr-fft/include/fft/fft_impl_fft.h b/gr-fft/include/fft/fft_impl_fft.h new file mode 100644 index 000000000..c27f2ae64 --- /dev/null +++ b/gr-fft/include/fft/fft_impl_fft.h @@ -0,0 +1,189 @@ +/* -*- 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_IMPL_FFT_H_ +#define _FFT_IMPL_FFT_H_ + +/* + * Wrappers for FFTW single precision 1d dft + */ + +#include <fft/api.h> +#include <gr_complex.h> +#include <boost/thread.hpp> + +/*! \brief Helper function for allocating complex fft buffers + */ +gr_complex* fft_impl_fft_malloc_complex(int size); + +/*! \brief Helper function for allocating float fft buffers + */ +float* fft_impl_fft_malloc_float(int size); + +/*! \brief Helper function for freeing fft buffers + */ +void fft_impl_fft_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 fft_impl_fft_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_impl_fft_complex { + int d_fft_size; + int d_nthreads; + gr_complex *d_inbuf; + gr_complex *d_outbuf; + void *d_plan; + +public: + fft_impl_fft_complex(int fft_size, bool forward = true, int nthreads=1); + virtual ~fft_impl_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_impl_fft_real_fwd { + int d_fft_size; + int d_nthreads; + float *d_inbuf; + gr_complex *d_outbuf; + void *d_plan; + +public: + fft_impl_fft_real_fwd (int fft_size, int nthreads=1); + virtual ~fft_impl_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_impl_fft_real_rev { + int d_fft_size; + int d_nthreads; + gr_complex *d_inbuf; + float *d_outbuf; + void *d_plan; + +public: + fft_impl_fft_real_rev(int fft_size, int nthreads=1); + virtual ~fft_impl_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(); +}; + +#endif diff --git a/gr-fft/include/fft/fft_impl_goertzel.h b/gr-fft/include/fft/fft_impl_goertzel.h new file mode 100644 index 000000000..b6aa71d31 --- /dev/null +++ b/gr-fft/include/fft/fft_impl_goertzel.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2011,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_IMPL_GOERTZEL_H +#define INCLUDED_FFT_IMPL_GOERTZEL_H + +#include <fft/api.h> +#include <gr_types.h> + +/*! + * \brief Implements Goertzel single-bin DFT calculation + * \ingroup misc + */ +class FFT_API fft_impl_goertzel +{ +public: + fft_impl_goertzel() {} + fft_impl_goertzel(int rate, int len, float freq); + void set_params(int rate, int len, float freq); + + // Process a input array + gr_complex batch(float *in); + + // Process sample by sample + void input(const float &in); + gr_complex output(); + bool ready() const { return d_processed == d_len; } + +private: + float d_d1; + float d_d2; + float d_wr; + float d_wi; + int d_len; + int d_processed; +}; + +#endif /* INCLUDED_FFT_IMPL_GOERTZEL_H */ diff --git a/gr-fft/include/fft/fft_vcc.h b/gr-fft/include/fft/fft_vcc.h new file mode 100644 index 000000000..932fa6f50 --- /dev/null +++ b/gr-fft/include/fft/fft_vcc.h @@ -0,0 +1,60 @@ +/* -*- 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 <fft/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace fft { + + class FFT_API fft_vcc : virtual public gr_sync_block + { + public: + + // gr::fft::fft_vcc::sptr + typedef boost::shared_ptr<fft_vcc> 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<float> &window, + bool shift=false, int nthreads=1); + + virtual void set_nthreads(int n) + { throw std::runtime_error("fft_vcc::set_nthreads not implemented.\n"); } + + virtual int nthreads() const + { throw std::runtime_error("fft_vcc::nthreads not implemented.\n"); } + + virtual bool set_window(const std::vector<float> &window) + { throw std::runtime_error("fft_vcc::set_window not implemented.\n"); } + }; + + } /* namespace fft */ +} /* namespace gr */ + +#endif /* INCLUDED_FFT_FFT_VCC_H */ diff --git a/gr-fft/include/fft/fft_vfc.h b/gr-fft/include/fft/fft_vfc.h new file mode 100644 index 000000000..01a5decdf --- /dev/null +++ b/gr-fft/include/fft/fft_vfc.h @@ -0,0 +1,60 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_FFT_FFT_VFC_H +#define INCLUDED_FFT_FFT_VFC_H + +#include <fft/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace fft { + + class FFT_API fft_vfc : virtual public gr_sync_block + { + public: + + // gr::fft::fft_vfc::sptr + typedef boost::shared_ptr<fft_vfc> sptr; + + /*! + * \brief Compute forward or reverse FFT. float vector in / complex vector out. + * \ingroup dft_blk + */ + static FFT_API sptr make(int fft_size, bool forward, + const std::vector<float> &window, + int nthreads=1); + + virtual void set_nthreads(int n) + { throw std::runtime_error("fft_vfc::set_nthreads not implemented.\n"); } + + virtual int nthreads() const + { throw std::runtime_error("fft_vfc::nthreads not implemented.\n"); } + + virtual bool set_window(const std::vector<float> &window) + { throw std::runtime_error("fft_vfc::set_window not implemented.\n"); } + }; + + } /* namespace fft */ +} /* namespace gr */ + +#endif /* INCLUDED_FFT_FFT_VFC_H */ diff --git a/gr-fft/include/fft/goertzel_fc.h b/gr-fft/include/fft/goertzel_fc.h new file mode 100644 index 000000000..0bc5384b9 --- /dev/null +++ b/gr-fft/include/fft/goertzel_fc.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2011,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_GOERTZEL_FC_H +#define INCLUDED_FFT_GOERTZEL_FC_H + +#include <fft/api.h> +#include <gr_sync_decimator.h> + +namespace gr { + namespace fft { + + class FFT_API goertzel_fc : virtual public gr_sync_decimator + { + public: + + // gr::fft::goertzel_fc::sptr + typedef boost::shared_ptr<goertzel_fc> sptr; + + /*! + * \brief Goertzel single-bin DFT calculation. + * \ingroup dft_blk + */ + static FFT_API sptr make(int rate, int len, float freq); + + virtual void set_freq (float freq) + { throw std::runtime_error("goertzel_fc::set_freq not implemented.\n"); } + + virtual void set_rate (int rate) + { throw std::runtime_error("goertzel_fc::set_rate not implemented.\n"); } + + float freq() + { throw std::runtime_error("goertzel_fc::freq not implemented.\n"); } + + int rate() + { throw std::runtime_error("goertzel_fc::rate not implemented.\n"); } + + }; + + } /* namespace fft */ +} /* namespace gr */ + +#endif /* INCLUDED_FFT_GOERTZEL_FC_H */ + |