GNU Radio 3.6.4.1 C++ API
fft_filter.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010,2012 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 <filter/api.h>
27 #include <vector>
28 #include <gr_complex.h>
29 #include <fft/fft.h>
30 
31 namespace gr {
32  namespace filter {
33  namespace kernel {
34  /*!
35  * \brief Fast FFT filter with float input, float output and float taps
36  * \ingroup filter_blk
37  */
39  {
40  private:
41  int d_ntaps;
42  int d_nsamples;
43  int d_fftsize; // fftsize = ntaps + nsamples - 1
44  int d_decimation;
45  fft::fft_real_fwd *d_fwdfft; // forward "plan"
46  fft::fft_real_rev *d_invfft; // inverse "plan"
47  int d_nthreads; // number of FFTW threads to use
48  std::vector<float> d_tail; // state carried between blocks for overlap-add
49  std::vector<float> d_new_taps;
50  gr_complex *d_xformed_taps; // Fourier xformed taps
51 
52  void compute_sizes(int ntaps);
53  int tailsize() const { return d_ntaps - 1; }
54 
55  public:
56  /*!
57  * \brief Construct an FFT filter for float vectors with the given taps and decimation rate.
58  *
59  * This is the basic implementation for performing FFT filter for fast convolution
60  * in other blocks for complex vectors (such as fft_filter_ccc).
61  *
62  * \param decimation The decimation rate of the filter (int)
63  * \param taps The filter taps (complex)
64  * \param nthreads The number of threads for the FFT to use (int)
65  */
66  fft_filter_fff(int decimation,
67  const std::vector<float> &taps,
68  int nthreads=1);
69 
70  ~fft_filter_fff();
71 
72  /*!
73  * \brief Set new taps for the filter.
74  *
75  * Sets new taps and resets the class properties to handle different sizes
76  * \param taps The filter taps (complex)
77  */
78  int set_taps(const std::vector<float> &taps);
79 
80  /*!
81  * \brief Set number of threads to use.
82  */
83  void set_nthreads(int n);
84 
85  /*!
86  * \brief Get number of threads being used.
87  */
88  int nthreads() const;
89 
90  /*!
91  * \brief Perform the filter operation
92  *
93  * \param nitems The number of items to produce
94  * \param input The input vector to be filtered
95  * \param output The result of the filter operation
96  */
97  int filter(int nitems, const float *input, float *output);
98  };
99 
100 
101  /*!
102  * \brief Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps
103  * \ingroup filter_blk
104  */
106  {
107  private:
108  int d_ntaps;
109  int d_nsamples;
110  int d_fftsize; // fftsize = ntaps + nsamples - 1
111  int d_decimation;
112  fft::fft_complex *d_fwdfft; // forward "plan"
113  fft::fft_complex *d_invfft; // inverse "plan"
114  int d_nthreads; // number of FFTW threads to use
115  std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add
116  std::vector<gr_complex> d_new_taps;
117  gr_complex *d_xformed_taps; // Fourier xformed taps
118 
119  void compute_sizes(int ntaps);
120  int tailsize() const { return d_ntaps - 1; }
121 
122  public:
123  /*!
124  * \brief Construct an FFT filter for complex vectors with the given taps and decimation rate.
125  *
126  * This is the basic implementation for performing FFT filter for fast convolution
127  * in other blocks for complex vectors (such as fft_filter_ccc).
128  *
129  * \param decimation The decimation rate of the filter (int)
130  * \param taps The filter taps (complex)
131  * \param nthreads The number of threads for the FFT to use (int)
132  */
133  fft_filter_ccc(int decimation,
134  const std::vector<gr_complex> &taps,
135  int nthreads=1);
136 
137  ~fft_filter_ccc();
138 
139  /*!
140  * \brief Set new taps for the filter.
141  *
142  * Sets new taps and resets the class properties to handle different sizes
143  * \param taps The filter taps (complex)
144  */
145  int set_taps(const std::vector<gr_complex> &taps);
146 
147  /*!
148  * \brief Set number of threads to use.
149  */
150  void set_nthreads(int n);
151 
152  /*!
153  * \brief Get number of threads being used.
154  */
155  int nthreads() const;
156 
157  /*!
158  * \brief Perform the filter operation
159  *
160  * \param nitems The number of items to produce
161  * \param input The input vector to be filtered
162  * \param output The result of the filter operation
163  */
164  int filter(int nitems, const gr_complex *input, gr_complex *output);
165  };
166 
167  } /* namespace kernel */
168  } /* namespace filter */
169 } /* namespace gr */
170 
171 #endif /* INCLUDED_FILTER_FFT_FILTER_H */