GNU Radio v3.6.2-149-ga6d285d9 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2010,2012 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_FILTER_FFT_FILTER_H 00024 #define INCLUDED_FILTER_FFT_FILTER_H 00025 00026 #include <filter/api.h> 00027 #include <vector> 00028 #include <gr_complex.h> 00029 #include <fft/fft.h> 00030 00031 namespace gr { 00032 namespace filter { 00033 namespace kernel { 00034 /*! 00035 * \brief Fast FFT filter with float input, float output and float taps 00036 * \ingroup filter_blk 00037 */ 00038 class FILTER_API fft_filter_fff 00039 { 00040 private: 00041 int d_ntaps; 00042 int d_nsamples; 00043 int d_fftsize; // fftsize = ntaps + nsamples - 1 00044 int d_decimation; 00045 fft::fft_real_fwd *d_fwdfft; // forward "plan" 00046 fft::fft_real_rev *d_invfft; // inverse "plan" 00047 int d_nthreads; // number of FFTW threads to use 00048 std::vector<float> d_tail; // state carried between blocks for overlap-add 00049 std::vector<float> d_new_taps; 00050 gr_complex *d_xformed_taps; // Fourier xformed taps 00051 00052 void compute_sizes(int ntaps); 00053 int tailsize() const { return d_ntaps - 1; } 00054 00055 public: 00056 /*! 00057 * \brief Construct an FFT filter for float vectors with the given taps and decimation rate. 00058 * 00059 * This is the basic implementation for performing FFT filter for fast convolution 00060 * in other blocks for complex vectors (such as fft_filter_ccc). 00061 * 00062 * \param decimation The decimation rate of the filter (int) 00063 * \param taps The filter taps (complex) 00064 * \param nthreads The number of threads for the FFT to use (int) 00065 */ 00066 fft_filter_fff(int decimation, 00067 const std::vector<float> &taps, 00068 int nthreads=1); 00069 00070 ~fft_filter_fff(); 00071 00072 /*! 00073 * \brief Set new taps for the filter. 00074 * 00075 * Sets new taps and resets the class properties to handle different sizes 00076 * \param taps The filter taps (complex) 00077 */ 00078 int set_taps(const std::vector<float> &taps); 00079 00080 /*! 00081 * \brief Set number of threads to use. 00082 */ 00083 void set_nthreads(int n); 00084 00085 /*! 00086 * \brief Get number of threads being used. 00087 */ 00088 int nthreads() const; 00089 00090 /*! 00091 * \brief Perform the filter operation 00092 * 00093 * \param nitems The number of items to produce 00094 * \param input The input vector to be filtered 00095 * \param output The result of the filter operation 00096 */ 00097 int filter(int nitems, const float *input, float *output); 00098 }; 00099 00100 00101 /*! 00102 * \brief Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps 00103 * \ingroup filter_blk 00104 */ 00105 class FILTER_API fft_filter_ccc 00106 { 00107 private: 00108 int d_ntaps; 00109 int d_nsamples; 00110 int d_fftsize; // fftsize = ntaps + nsamples - 1 00111 int d_decimation; 00112 fft::fft_complex *d_fwdfft; // forward "plan" 00113 fft::fft_complex *d_invfft; // inverse "plan" 00114 int d_nthreads; // number of FFTW threads to use 00115 std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add 00116 std::vector<gr_complex> d_new_taps; 00117 gr_complex *d_xformed_taps; // Fourier xformed taps 00118 00119 void compute_sizes(int ntaps); 00120 int tailsize() const { return d_ntaps - 1; } 00121 00122 public: 00123 /*! 00124 * \brief Construct an FFT filter for complex vectors with the given taps and decimation rate. 00125 * 00126 * This is the basic implementation for performing FFT filter for fast convolution 00127 * in other blocks for complex vectors (such as fft_filter_ccc). 00128 * 00129 * \param decimation The decimation rate of the filter (int) 00130 * \param taps The filter taps (complex) 00131 * \param nthreads The number of threads for the FFT to use (int) 00132 */ 00133 fft_filter_ccc(int decimation, 00134 const std::vector<gr_complex> &taps, 00135 int nthreads=1); 00136 00137 ~fft_filter_ccc(); 00138 00139 /*! 00140 * \brief Set new taps for the filter. 00141 * 00142 * Sets new taps and resets the class properties to handle different sizes 00143 * \param taps The filter taps (complex) 00144 */ 00145 int set_taps(const std::vector<gr_complex> &taps); 00146 00147 /*! 00148 * \brief Set number of threads to use. 00149 */ 00150 void set_nthreads(int n); 00151 00152 /*! 00153 * \brief Get number of threads being used. 00154 */ 00155 int nthreads() const; 00156 00157 /*! 00158 * \brief Perform the filter operation 00159 * 00160 * \param nitems The number of items to produce 00161 * \param input The input vector to be filtered 00162 * \param output The result of the filter operation 00163 */ 00164 int filter(int nitems, const gr_complex *input, gr_complex *output); 00165 }; 00166 00167 } /* namespace kernel */ 00168 } /* namespace filter */ 00169 } /* namespace gr */ 00170 00171 #endif /* INCLUDED_FILTER_FFT_FILTER_H */