GNU Radio 3.7.3 C++ API
fft_filter.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010,2012,2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_FILTER_FFT_FILTER_H
24 #define INCLUDED_FILTER_FFT_FILTER_H
25 
26 #include <gnuradio/filter/api.h>
27 #include <vector>
28 #include <gnuradio/gr_complex.h>
29 #include <gnuradio/fft/fft.h>
30 
31 namespace gr {
32  namespace filter {
33  namespace kernel {
34 
35  /*!
36  * \brief Fast FFT filter with float input, float output and float taps
37  * \ingroup filter_blk
38  */
40  {
41  private:
42  int d_ntaps;
43  int d_nsamples;
44  int d_fftsize; // fftsize = ntaps + nsamples - 1
45  int d_decimation;
46  fft::fft_real_fwd *d_fwdfft; // forward "plan"
47  fft::fft_real_rev *d_invfft; // inverse "plan"
48  int d_nthreads; // number of FFTW threads to use
49  std::vector<float> d_tail; // state carried between blocks for overlap-add
50  std::vector<float> d_taps; // stores time domain taps
51  gr_complex *d_xformed_taps; // Fourier xformed taps
52 
53  void compute_sizes(int ntaps);
54  int tailsize() const { return d_ntaps - 1; }
55 
56  public:
57  /*!
58  * \brief Construct an FFT filter for float vectors with the given taps and decimation rate.
59  *
60  * This is the basic implementation for performing FFT filter for fast convolution
61  * in other blocks for complex vectors (such as fft_filter_ccc).
62  *
63  * \param decimation The decimation rate of the filter (int)
64  * \param taps The filter taps (complex)
65  * \param nthreads The number of threads for the FFT to use (int)
66  */
67  fft_filter_fff(int decimation,
68  const std::vector<float> &taps,
69  int nthreads=1);
70 
71  ~fft_filter_fff();
72 
73  /*!
74  * \brief Set new taps for the filter.
75  *
76  * Sets new taps and resets the class properties to handle different sizes
77  * \param taps The filter taps (complex)
78  */
79  int set_taps(const std::vector<float> &taps);
80 
81  /*!
82  * \brief Set number of threads to use.
83  */
84  void set_nthreads(int n);
85 
86  /*!
87  * \brief Returns the taps.
88  */
89  std::vector<float> taps() const;
90 
91  /*!
92  * \brief Returns the number of taps in the filter.
93  */
94  unsigned int ntaps() const;
95 
96  /*!
97  * \brief Get number of threads being used.
98  */
99  int nthreads() const;
100 
101  /*!
102 l * \brief Perform the filter operation
103  *
104  * \param nitems The number of items to produce
105  * \param input The input vector to be filtered
106  * \param output The result of the filter operation
107  */
108  int filter(int nitems, const float *input, float *output);
109  };
110 
111 
112  /*!
113  * \brief Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps
114  * \ingroup filter_blk
115  */
117  {
118  private:
119  int d_ntaps;
120  int d_nsamples;
121  int d_fftsize; // fftsize = ntaps + nsamples - 1
122  int d_decimation;
123  fft::fft_complex *d_fwdfft; // forward "plan"
124  fft::fft_complex *d_invfft; // inverse "plan"
125  int d_nthreads; // number of FFTW threads to use
126  std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add
127  std::vector<gr_complex> d_taps; // stores time domain taps
128  gr_complex *d_xformed_taps; // Fourier xformed taps
129 
130  void compute_sizes(int ntaps);
131  int tailsize() const { return d_ntaps - 1; }
132 
133  public:
134  /*!
135  * \brief Construct an FFT filter for complex vectors with the given taps and decimation rate.
136  *
137  * This is the basic implementation for performing FFT filter for fast convolution
138  * in other blocks for complex vectors (such as fft_filter_ccc).
139  *
140  * \param decimation The decimation rate of the filter (int)
141  * \param taps The filter taps (complex)
142  * \param nthreads The number of threads for the FFT to use (int)
143  */
144  fft_filter_ccc(int decimation,
145  const std::vector<gr_complex> &taps,
146  int nthreads=1);
147 
148  ~fft_filter_ccc();
149 
150  /*!
151  * \brief Set new taps for the filter.
152  *
153  * Sets new taps and resets the class properties to handle different sizes
154  * \param taps The filter taps (complex)
155  */
156  int set_taps(const std::vector<gr_complex> &taps);
157 
158  /*!
159  * \brief Set number of threads to use.
160  */
161  void set_nthreads(int n);
162 
163  /*!
164  * \brief Returns the taps.
165  */
166  std::vector<gr_complex> taps() const;
167 
168  /*!
169  * \brief Returns the number of taps in the filter.
170  */
171  unsigned int ntaps() const;
172 
173  /*!
174  * \brief Get number of threads being used.
175  */
176  int nthreads() const;
177 
178  /*!
179  * \brief Perform the filter operation
180  *
181  * \param nitems The number of items to produce
182  * \param input The input vector to be filtered
183  * \param output The result of the filter operation
184  */
185  int filter(int nitems, const gr_complex *input, gr_complex *output);
186  };
187 
188 
189 
190  /*!
191  * \brief Fast FFT filter with gr_complex input, gr_complex output and float taps
192  * \ingroup filter_blk
193  */
195  {
196  private:
197  int d_ntaps;
198  int d_nsamples;
199  int d_fftsize; // fftsize = ntaps + nsamples - 1
200  int d_decimation;
201  fft::fft_complex *d_fwdfft; // forward "plan"
202  fft::fft_complex *d_invfft; // inverse "plan"
203  int d_nthreads; // number of FFTW threads to use
204  std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add
205  std::vector<float> d_taps; // stores time domain taps
206  gr_complex *d_xformed_taps; // Fourier xformed taps
207 
208  void compute_sizes(int ntaps);
209  int tailsize() const { return d_ntaps - 1; }
210 
211  public:
212  /*!
213  * \brief Construct an FFT filter for complex vectors with the given taps and decimation rate.
214  *
215  * This is the basic implementation for performing FFT filter for fast convolution
216  * in other blocks for complex vectors (such as fft_filter_ccf).
217  *
218  * \param decimation The decimation rate of the filter (int)
219  * \param taps The filter taps (complex)
220  * \param nthreads The number of threads for the FFT to use (int)
221  */
222  fft_filter_ccf(int decimation,
223  const std::vector<float> &taps,
224  int nthreads=1);
225 
226  ~fft_filter_ccf();
227 
228  /*!
229  * \brief Set new taps for the filter.
230  *
231  * Sets new taps and resets the class properties to handle different sizes
232  * \param taps The filter taps (complex)
233  */
234  int set_taps(const std::vector<float> &taps);
235 
236  /*!
237  * \brief Set number of threads to use.
238  */
239  void set_nthreads(int n);
240 
241  /*!
242  * \brief Returns the taps.
243  */
244  std::vector<float> taps() const;
245 
246  /*!
247  * \brief Returns the number of taps in the filter.
248  */
249  unsigned int ntaps() const;
250 
251  /*!
252  * \brief Returns the actual size of the filter.
253  *
254  * \details This value could be equal to ntaps, but we ofter
255  * build a longer filter to allow us to calculate a more
256  * efficient FFT. This value is the actual size of the filters
257  * used in the calculation of the overlap-and-save operation.
258  */
259  unsigned int filtersize() const;
260 
261  /*!
262  * \brief Get number of threads being used.
263  */
264  int nthreads() const;
265 
266  /*!
267  * \brief Perform the filter operation
268  *
269  * \param nitems The number of items to produce
270  * \param input The input vector to be filtered
271  * \param output The result of the filter operation
272  */
273  int filter(int nitems, const gr_complex *input, gr_complex *output);
274  };
275 
276  } /* namespace kernel */
277  } /* namespace filter */
278 } /* namespace gr */
279 
280 #endif /* INCLUDED_FILTER_FFT_FILTER_H */
FFT: complex in, complex out.
Definition: fft.h:71
Fast FFT filter with gr_complex input, gr_complex output and float taps.
Definition: fft_filter.h:194
std::complex< float > gr_complex
Definition: gr_complex.h:27
FFT: real in, complex out.
Definition: fft.h:114
Fast FFT filter with float input, float output and float taps.
Definition: fft_filter.h:39
FFT: complex in, float out.
Definition: fft.h:157
Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps.
Definition: fft_filter.h:116
static const float taps[NSTEPS+1][NTAPS]
Definition: interpolator_taps.h:9
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:30