GNU Radio 3.6.5 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 /*! 00036 * \brief Fast FFT filter with float input, float output and float taps 00037 * \ingroup filter_blk 00038 */ 00039 class FILTER_API fft_filter_fff 00040 { 00041 private: 00042 int d_ntaps; 00043 int d_nsamples; 00044 int d_fftsize; // fftsize = ntaps + nsamples - 1 00045 int d_decimation; 00046 fft::fft_real_fwd *d_fwdfft; // forward "plan" 00047 fft::fft_real_rev *d_invfft; // inverse "plan" 00048 int d_nthreads; // number of FFTW threads to use 00049 std::vector<float> d_tail; // state carried between blocks for overlap-add 00050 std::vector<float> d_new_taps; 00051 gr_complex *d_xformed_taps; // Fourier xformed taps 00052 00053 void compute_sizes(int ntaps); 00054 int tailsize() const { return d_ntaps - 1; } 00055 00056 public: 00057 /*! 00058 * \brief Construct an FFT filter for float vectors with the given taps and decimation rate. 00059 * 00060 * This is the basic implementation for performing FFT filter for fast convolution 00061 * in other blocks for complex vectors (such as fft_filter_ccc). 00062 * 00063 * \param decimation The decimation rate of the filter (int) 00064 * \param taps The filter taps (complex) 00065 * \param nthreads The number of threads for the FFT to use (int) 00066 */ 00067 fft_filter_fff(int decimation, 00068 const std::vector<float> &taps, 00069 int nthreads=1); 00070 00071 ~fft_filter_fff(); 00072 00073 /*! 00074 * \brief Set new taps for the filter. 00075 * 00076 * Sets new taps and resets the class properties to handle different sizes 00077 * \param taps The filter taps (complex) 00078 */ 00079 int set_taps(const std::vector<float> &taps); 00080 00081 /*! 00082 * \brief Set number of threads to use. 00083 */ 00084 void set_nthreads(int n); 00085 00086 /*! 00087 * \brief Get number of threads being used. 00088 */ 00089 int nthreads() const; 00090 00091 /*! 00092 * \brief Perform the filter operation 00093 * 00094 * \param nitems The number of items to produce 00095 * \param input The input vector to be filtered 00096 * \param output The result of the filter operation 00097 */ 00098 int filter(int nitems, const float *input, float *output); 00099 }; 00100 00101 00102 /*! 00103 * \brief Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps 00104 * \ingroup filter_blk 00105 */ 00106 class FILTER_API fft_filter_ccc 00107 { 00108 private: 00109 int d_ntaps; 00110 int d_nsamples; 00111 int d_fftsize; // fftsize = ntaps + nsamples - 1 00112 int d_decimation; 00113 fft::fft_complex *d_fwdfft; // forward "plan" 00114 fft::fft_complex *d_invfft; // inverse "plan" 00115 int d_nthreads; // number of FFTW threads to use 00116 std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add 00117 std::vector<gr_complex> d_new_taps; 00118 gr_complex *d_xformed_taps; // Fourier xformed taps 00119 00120 void compute_sizes(int ntaps); 00121 int tailsize() const { return d_ntaps - 1; } 00122 00123 public: 00124 /*! 00125 * \brief Construct an FFT filter for complex vectors with the given taps and decimation rate. 00126 * 00127 * This is the basic implementation for performing FFT filter for fast convolution 00128 * in other blocks for complex vectors (such as fft_filter_ccc). 00129 * 00130 * \param decimation The decimation rate of the filter (int) 00131 * \param taps The filter taps (complex) 00132 * \param nthreads The number of threads for the FFT to use (int) 00133 */ 00134 fft_filter_ccc(int decimation, 00135 const std::vector<gr_complex> &taps, 00136 int nthreads=1); 00137 00138 ~fft_filter_ccc(); 00139 00140 /*! 00141 * \brief Set new taps for the filter. 00142 * 00143 * Sets new taps and resets the class properties to handle different sizes 00144 * \param taps The filter taps (complex) 00145 */ 00146 int set_taps(const std::vector<gr_complex> &taps); 00147 00148 /*! 00149 * \brief Set number of threads to use. 00150 */ 00151 void set_nthreads(int n); 00152 00153 /*! 00154 * \brief Get number of threads being used. 00155 */ 00156 int nthreads() const; 00157 00158 /*! 00159 * \brief Perform the filter operation 00160 * 00161 * \param nitems The number of items to produce 00162 * \param input The input vector to be filtered 00163 * \param output The result of the filter operation 00164 */ 00165 int filter(int nitems, const gr_complex *input, gr_complex *output); 00166 }; 00167 00168 } /* namespace kernel */ 00169 } /* namespace filter */ 00170 } /* namespace gr */ 00171 00172 #endif /* INCLUDED_FILTER_FFT_FILTER_H */