fftplan_fftw3.hh
#ifndef __SDR_FFTPLAN_FFTW3_HH__
#define __SDR_FFTPLAN_FFTW3_HH__
#include "fftplan.hh"
#include <fftw3.h>
namespace sdr {
template<>
class FFTPlan<double>
{
public:
FFTPlan(const Buffer< std::complex<double> > &in, const Buffer< std::complex<double> > &out,
FFT::Direction dir)
: _in(in), _out(out)
{
if (in.size() != out.size()) {
ConfigError err;
err << "Can not construct FFT plan: input & output buffers are of different size!";
throw err;
}
if (in.isEmpty() || out.isEmpty()) {
ConfigError err;
err << "Can not construct FFT plan: input or output buffer is empty!";
throw err;
}
int fftw_dir = FFTW_FORWARD;
if (FFT::BACKWARD == dir) { fftw_dir = FFTW_BACKWARD; }
_plan = fftw_plan_dft_1d(
in.size(), (fftw_complex *)in.data(), (fftw_complex *)out.data(),
fftw_dir, FFTW_ESTIMATE);
}
FFTPlan(const Buffer< std::complex<double> > &inplace, FFT::Direction dir)
: _in(inplace), _out(inplace)
{
if (inplace.isEmpty()) {
ConfigError err;
err << "Can not construct FFT plan: Buffer is empty!";
throw err;
}
int fftw_dir = FFTW_FORWARD;
if (FFT::BACKWARD == dir) { fftw_dir = FFTW_BACKWARD; }
_plan = fftw_plan_dft_1d(
inplace.size(), (fftw_complex *)inplace.data(), (fftw_complex *)inplace.data(),
fftw_dir, FFTW_ESTIMATE);
}
virtual ~FFTPlan() {
fftw_destroy_plan(_plan);
}
void operator() () {
fftw_execute(_plan);
}
protected:
Buffer< std::complex<double> > _in;
Buffer< std::complex<double> > _out;
fftw_plan _plan;
};
template<>
class FFTPlan<float>
{
public:
FFTPlan(const Buffer< std::complex<float> > &in, const Buffer< std::complex<float> > &out,
FFT::Direction dir)
: _in(in), _out(out)
{
if (in.size() != out.size()) {
ConfigError err;
err << "Can not construct FFT plan: input & output buffers are of different size!";
throw err;
}
if (in.isEmpty() || out.isEmpty()) {
ConfigError err;
err << "Can not construct FFT plan: input or output buffer is empty!";
throw err;
}
int fftw_dir = FFTW_FORWARD;
if (FFT::BACKWARD == dir) { fftw_dir = FFTW_BACKWARD; }
_plan = fftwf_plan_dft_1d(
in.size(), (fftwf_complex *)in.data(), (fftwf_complex *)out.data(),
fftw_dir, FFTW_ESTIMATE);
}
FFTPlan(const Buffer< std::complex<float> > &inplace, FFT::Direction dir)
: _in(inplace), _out(inplace)
{
if (inplace.isEmpty()) {
ConfigError err;
err << "Can not construct FFT plan: Buffer is empty!";
throw err;
}
int fftw_dir = FFTW_FORWARD;
if (FFT::BACKWARD == dir) { fftw_dir = FFTW_BACKWARD; }
_plan = fftwf_plan_dft_1d(
inplace.size(), (fftwf_complex *)inplace.data(), (fftwf_complex *)inplace.data(),
fftw_dir, FFTW_ESTIMATE);
}
virtual ~FFTPlan() {
fftwf_destroy_plan(_plan);
}
void operator() () {
fftwf_execute(_plan);
}
protected:
Buffer< std::complex<float> > _in;
Buffer< std::complex<float> > _out;
fftwf_plan _plan;
};
}
#endif // __SDR_FFTPLAN_FFTW3_HH__
sdr::FFTPlan< double >::FFTPlan
FFTPlan(const Buffer< std::complex< double > > &in, const Buffer< std::complex< double > > &out, FFT::Direction dir)
Constructor.
Definition: fftplan_fftw3.hh:16
sdr::FFTPlan< float >::FFTPlan
FFTPlan(const Buffer< std::complex< float > > &in, const Buffer< std::complex< float > > &out, FFT::Direction dir)
Constructor.
Definition: fftplan_fftw3.hh:83
sdr::FFTPlan::operator()
void operator()()
Performs the FFT.
Definition: fftplan_native.hh:53
sdr::FFT::Direction
Direction
Direction type.
Definition: fftplan.hh:17
sdr
Definition: autocast.hh:8
sdr::FFTPlan::_in
Buffer< std::complex< Scalar > > _in
The input buffer.
Definition: fftplan_native.hh:79
sdr::FFTPlan< float >::_out
Buffer< std::complex< float > > _out
Output buffer.
Definition: fftplan_fftw3.hh:139
sdr::FFTPlan< double >::_in
Buffer< std::complex< double > > _in
Input buffer.
Definition: fftplan_fftw3.hh:69
sdr::FFTPlan< float >::~FFTPlan
virtual ~FFTPlan()
Destructor.
Definition: fftplan_fftw3.hh:126
sdr::FFTPlan::_out
Buffer< std::complex< Scalar > > _out
The output buffer.
Definition: fftplan_native.hh:81
sdr::FFTPlan< float >::FFTPlan
FFTPlan(const Buffer< std::complex< float > > &inplace, FFT::Direction dir)
Constructor.
Definition: fftplan_fftw3.hh:108
sdr::FFTPlan< double >::_plan
fftw_plan _plan
The FFT plan.
Definition: fftplan_fftw3.hh:73
sdr::FFTPlan< float >::_in
Buffer< std::complex< float > > _in
Input buffer.
Definition: fftplan_fftw3.hh:137
sdr::FFTPlan< double >::_out
Buffer< std::complex< double > > _out
Output buffer.
Definition: fftplan_fftw3.hh:71
sdr::FFTPlan
Trivial FFT implementation for buffer sizes of N=2**K.
Definition: fftplan.hh:11
sdr::FFTPlan< float >::_plan
fftwf_plan _plan
The fft plan.
Definition: fftplan_fftw3.hh:141
sdr::ConfigError
The configuration error class.
Definition: exception.hh:24
sdr::FFTPlan< double >::~FFTPlan
virtual ~FFTPlan()
Destructor.
Definition: fftplan_fftw3.hh:58
sdr::FFTPlan< double >::FFTPlan
FFTPlan(const Buffer< std::complex< double > > &inplace, FFT::Direction dir)
Constructor.
Definition: fftplan_fftw3.hh:40
sdr::Buffer
A typed buffer.
Definition: buffer.hh:111