Skip to content

Commit c84a69b

Browse files
committedFeb 28, 2014
filter: adds a ccf version of the fft filter.
Taps are converted to complex still, so no computational savings here. Just for convinience of setting taps (mostly in c++).
1 parent 92b01e3 commit c84a69b

10 files changed

+730
-64
lines changed
 

‎gr-filter/grc/filter_fft_filter_xxx.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ self.$(id).declare_sample_delay($samp_delay)
2525
<opt>output:complex</opt>
2626
<opt>taps:complex_vector</opt>
2727
</option>
28+
<option>
29+
<name>Complex->Complex (Real Taps)</name>
30+
<key>ccf</key>
31+
<opt>input:complex</opt>
32+
<opt>output:complex</opt>
33+
<opt>taps:float_vector</opt>
34+
</option>
2835
<option>
2936
<name>Float->Float (Real Taps)</name>
3037
<key>fff</key>
3138
<opt>input:float</opt>
3239
<opt>output:float</opt>
33-
<opt>taps:real_vector</opt>
40+
<opt>taps:float_vector</opt>
3441
</option>
3542
</param>
3643
<param>

‎gr-filter/include/gnuradio/filter/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ macro(expand_h root)
4747
string(REGEX REPLACE "X+" ${sig} name ${root})
4848
list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/${name}.h)
4949
endforeach(sig)
50-
50+
5151
#create a command to generate the files
5252
add_custom_command(
5353
OUTPUT ${expanded_files_h}
@@ -94,6 +94,7 @@ install(FILES
9494
dc_blocker_ff.h
9595
filter_delay_fc.h
9696
fft_filter_ccc.h
97+
fft_filter_ccf.h
9798
fft_filter_fff.h
9899
fractional_interpolator_cc.h
99100
fractional_interpolator_ff.h

‎gr-filter/include/gnuradio/filter/fft_filter.h

+99-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- c++ -*- */
22
/*
3-
* Copyright 2010,2012 Free Software Foundation, Inc.
3+
* Copyright 2010,2012,2014 Free Software Foundation, Inc.
44
*
55
* This file is part of GNU Radio
66
*
@@ -49,7 +49,7 @@ namespace gr {
4949
std::vector<float> d_tail; // state carried between blocks for overlap-add
5050
std::vector<float> d_taps; // stores time domain taps
5151
gr_complex *d_xformed_taps; // Fourier xformed taps
52-
52+
5353
void compute_sizes(int ntaps);
5454
int tailsize() const { return d_ntaps - 1; }
5555

@@ -77,7 +77,7 @@ namespace gr {
7777
* \param taps The filter taps (complex)
7878
*/
7979
int set_taps(const std::vector<float> &taps);
80-
80+
8181
/*!
8282
* \brief Set number of threads to use.
8383
*/
@@ -92,12 +92,12 @@ namespace gr {
9292
* \brief Returns the number of taps in the filter.
9393
*/
9494
unsigned int ntaps() const;
95-
95+
9696
/*!
9797
* \brief Get number of threads being used.
9898
*/
9999
int nthreads() const;
100-
100+
101101
/*!
102102
l * \brief Perform the filter operation
103103
*
@@ -108,7 +108,7 @@ l * \brief Perform the filter operation
108108
int filter(int nitems, const float *input, float *output);
109109
};
110110

111-
111+
112112
/*!
113113
* \brief Fast FFT filter with gr_complex input, gr_complex output and gr_complex taps
114114
* \ingroup filter_blk
@@ -126,7 +126,7 @@ l * \brief Perform the filter operation
126126
std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add
127127
std::vector<gr_complex> d_taps; // stores time domain taps
128128
gr_complex *d_xformed_taps; // Fourier xformed taps
129-
129+
130130
void compute_sizes(int ntaps);
131131
int tailsize() const { return d_ntaps - 1; }
132132

@@ -154,12 +154,12 @@ l * \brief Perform the filter operation
154154
* \param taps The filter taps (complex)
155155
*/
156156
int set_taps(const std::vector<gr_complex> &taps);
157-
157+
158158
/*!
159159
* \brief Set number of threads to use.
160160
*/
161161
void set_nthreads(int n);
162-
162+
163163
/*!
164164
* \brief Returns the taps.
165165
*/
@@ -169,12 +169,100 @@ l * \brief Perform the filter operation
169169
* \brief Returns the number of taps in the filter.
170170
*/
171171
unsigned int ntaps() const;
172-
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+
*/
194+
class FILTER_API fft_filter_ccf
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+
173261
/*!
174262
* \brief Get number of threads being used.
175263
*/
176264
int nthreads() const;
177-
265+
178266
/*!
179267
* \brief Perform the filter operation
180268
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* -*- c++ -*- */
2+
/*
3+
* Copyright 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_CCF_H
24+
#define INCLUDED_FILTER_FFT_FILTER_CCF_H
25+
26+
#include <gnuradio/filter/api.h>
27+
#include <gnuradio/sync_decimator.h>
28+
29+
namespace gr {
30+
namespace filter {
31+
32+
/*!
33+
* \brief Fast FFT filter with gr_complex input, gr_complex output and float taps
34+
* \ingroup filter_blk
35+
*
36+
* \details
37+
* This block implements a complex decimating filter using the
38+
* fast convolution method via an FFT. The decimation factor is an
39+
* interger that is greater than or equal to 1.
40+
*
41+
* The filter takes a set of complex (or real) taps to use in the
42+
* filtering operation. These taps can be defined as anything that
43+
* satisfies the user's filtering needs. For standard filters such
44+
* as lowpass, highpass, bandpass, etc., the filter.firdes and
45+
* filter.optfir classes provide convenient generating methods.
46+
*
47+
* This filter is implemented by using the FFTW package to perform
48+
* the required FFTs. An optional argument, nthreads, may be
49+
* passed to the constructor (or set using the set_nthreads member
50+
* function) to split the FFT among N number of threads. This can
51+
* improve performance on very large FFTs (that is, if the number
52+
* of taps used is very large) if you have enough threads/cores to
53+
* support it.
54+
*/
55+
class FILTER_API fft_filter_ccf : virtual public sync_decimator
56+
{
57+
public:
58+
// gr::filter::fft_filter_ccf::sptr
59+
typedef boost::shared_ptr<fft_filter_ccf> sptr;
60+
61+
/*!
62+
* Build an FFT filter blocks.
63+
*
64+
* \param decimation >= 1
65+
* \param taps complex filter taps
66+
* \param nthreads number of threads for the FFT to use
67+
*/
68+
static sptr make(int decimation,
69+
const std::vector<float> &taps,
70+
int nthreads=1);
71+
72+
virtual void set_taps(const std::vector<float> &taps) = 0;
73+
virtual std::vector<float> taps() const = 0;
74+
75+
/*!
76+
* \brief Set number of threads to use.
77+
*/
78+
virtual void set_nthreads(int n) = 0;
79+
80+
/*!
81+
* \brief Get number of threads being used.
82+
*/
83+
virtual int nthreads() const = 0;
84+
};
85+
86+
} /* namespace filter */
87+
} /* namespace gr */
88+
89+
#endif /* INCLUDED_FILTER_FFT_FILTER_CCF_H */

‎gr-filter/lib/CMakeLists.txt

+6-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ macro(expand_cc root)
4848
list(APPEND expanded_files_cc ${CMAKE_CURRENT_BINARY_DIR}/${name}.cc)
4949
list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/${name}.h)
5050
endforeach(sig)
51-
51+
5252
#create a command to generate the source files
5353
add_custom_command(
5454
OUTPUT ${expanded_files_cc}
@@ -66,15 +66,15 @@ macro(expand_cc root)
6666
${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
6767
${root} ${root}.h.t ${ARGN}
6868
)
69-
69+
7070
#make source files depends on headers to force generation
7171
set_source_files_properties(${expanded_files_cc}
7272
PROPERTIES OBJECT_DEPENDS "${expanded_files_h}"
7373
)
74-
74+
7575
#install rules for the generated cc files
76-
list(APPEND generated_sources ${expanded_files_cc})
77-
list(APPEND generated_headers ${expanded_files_h})
76+
list(APPEND generated_sources ${expanded_files_cc})
77+
list(APPEND generated_headers ${expanded_files_h})
7878
endmacro(expand_cc)
7979

8080
########################################################################
@@ -128,6 +128,7 @@ list(APPEND filter_sources
128128
dc_blocker_ff_impl.cc
129129
filter_delay_fc_impl.cc
130130
fft_filter_ccc_impl.cc
131+
fft_filter_ccf_impl.cc
131132
fft_filter_fff_impl.cc
132133
fractional_interpolator_cc_impl.cc
133134
fractional_interpolator_ff_impl.cc

0 commit comments

Comments
 (0)
Please sign in to comment.