The Freq_Filt class implements an FFT based filter using the overlap-add technique. The data is filtered by first transforming the input sequence into the frequency domain with an efficient FFT implementation (i.e. FFTW) and then multiplied with a Fourier transformed version of the impulse response. The resulting data is then inversed Fourier transformed to return a filtered time domain signal. More...
#include <freq_filt.h>
Public Member Functions | |
Freq_Filt () | |
Constructor. | |
Freq_Filt (const Vec< Num_T > &b, const int xlength) | |
Constructor with initialization of the impulse response b. | |
Vec< Num_T > | filter (const Vec< Num_T > &x, const int strm=0) |
Filter data in the input vector x. | |
int | get_fft_size () |
Return FFT size. | |
int | get_blk_size () |
Return the data block size. | |
~Freq_Filt () | |
Destructor. |
The Freq_Filt class implements an FFT based filter using the overlap-add technique. The data is filtered by first transforming the input sequence into the frequency domain with an efficient FFT implementation (i.e. FFTW) and then multiplied with a Fourier transformed version of the impulse response. The resulting data is then inversed Fourier transformed to return a filtered time domain signal.
Freq_Filt is a templated class. The template paramter Num_T
defines the data type for the impulse response b
, input data x
and output data y
.
The class constructor chooses an optimal FFT length and data block size that minimizes execution time.
For example,
vec b = "1 2 3 4";
Freq_Filt<double> FF(b,8000);
where 8000 corresponds to the expected vector length of the data to be filtered. The actual number of elements does not have to be exact, but it should be close.
Here is a complete example:
vec b = "1 2 3 4"; vec x(20); x(0) = 1; // Define a filter object for doubles Freq_Filt<double> FF(b,x.length()); // Filter the data vec y = FF.filter(x); // Check the FFT and block sizes that were used int fftsize = FF.getFFTSize(); int blk = FF.getBlkSize();
To facilitate large data sets the Freq_Filt class has a streaming option. In this mode of operation data history is internally stored. This allows the class to be used for large data sets that are read from disk or streamed in real-time.
bool stream = true; vec b = "1 2 3 4"; Freq_Filt<double> FF(b,1000); vec x,y; while(!EOF) { x = "read buffer of data"; y = FF.filter(x,stream); cout << << endl; }
itpp::Freq_Filt< Num_T >::Freq_Filt | ( | ) | [inline] |
Constructor.
The empty constructor makes it possible to have other container objects of the Freq_Filt class
itpp::Freq_Filt< Num_T >::Freq_Filt | ( | const Vec< Num_T > & | b, | |
const int | xlength | |||
) | [inline] |
Constructor with initialization of the impulse response b.
Create a filter object with impulse response b. The FFT size and data block size are also initialized.
vec b = "1 2 3 4"; vec x(20); Freq_Filt FF(b,x.length());
Vec< Num_T > itpp::Freq_Filt< Num_T >::filter | ( | const Vec< Num_T > & | x, | |
const int | strm = 0 | |||
) | [inline] |
Filter data in the input vector x.
Filters data in batch mode or streaming mode
FF.filter(x); // Filters data in batch mode FF.filter(x,1); // Filters data in streaming mode
References itpp::Vec< Num_T >::length().