44 FFTW(
unsigned int _N,
int _alg = FFTW_ESTIMATE )
63 FFTW(
unsigned int _R,
unsigned int _C,
int _alg )
82 fftw_destroy_plan(
pl_fft );
97 void fft_cx( arma::cx_vec& x, arma::cx_vec& Pxx )
99 fftw_complex* in =
reinterpret_cast<fftw_complex*
>( x.memptr() );
100 fftw_complex* out =
reinterpret_cast<fftw_complex*
>( Pxx.memptr() );
103 pl_fft_cx = fftw_plan_dft_1d(
N, in, out, FFTW_FORWARD,
alg );
106 err_handler(
"Unable to create complex data FFTW plan" );
119 arma::cx_vec Pxx(
N );
129 void ifft_cx( arma::cx_vec& Pxx, arma::cx_vec& x )
131 fftw_complex* in =
reinterpret_cast<fftw_complex*
>( Pxx.memptr() );
132 fftw_complex* out =
reinterpret_cast<fftw_complex*
>( x.memptr() );
138 err_handler(
"Unable to create complex data IFFTW plan" );
162 void fft( arma::vec& x, arma::cx_vec& Pxx )
164 double* in = x.memptr();
165 fftw_complex* out =
reinterpret_cast<fftw_complex*
>( Pxx.memptr() );
168 pl_fft = fftw_plan_dft_r2c_1d(
N, in, out,
alg );
171 err_handler(
"Unable to create real data FFTW plan" );
175 fftw_execute_dft_r2c(
pl_fft, in, out );
176 int offset =
static_cast<int>( ceil(
N / 2.0 ) );
177 int n_elem =
N - offset;
178 for(
int i = 0; i < n_elem; ++i )
180 Pxx( offset + i ) = std::conj( Pxx( n_elem - i ) );
188 arma::cx_vec
fft( arma::vec& x )
190 arma::cx_vec Pxx(
N );
200 void ifft( arma::cx_vec& Pxx, arma::vec& x )
202 fftw_complex* in =
reinterpret_cast<fftw_complex*
>( Pxx.memptr() );
203 double* out = x.memptr();
209 err_handler(
"Unable to create real data IFFTW plan" );
212 fftw_execute_dft_c2r(
pl_ifft, in, out );
221 arma::vec
ifft( arma::cx_vec& Pxx )
233 void fft2( arma::mat& x, arma::cx_mat& Pxx )
235 arma::cx_mat Ptmp(
R / 2 + 1,
C, arma::fill::ones );
236 double* in = x.memptr();
237 fftw_complex* out =
reinterpret_cast<fftw_complex*
>( Ptmp.memptr() );
240 pl_fft = fftw_plan_dft_r2c_2d(
C,
R, in, out,
244 err_handler(
"Unable to create real data FFTW plan" );
248 fftw_execute_dft_r2c(
pl_fft, in, out );
251 std::complex<double>* ptr =
reinterpret_cast<std::complex<double>*
>( out );
252 const unsigned int Roff =
R / 2 + 1;
253 for(
unsigned int r = 0; r < Roff; r++ )
255 for(
unsigned int c = 0; c <
C; c++ )
257 Pxx( r, c ) = ptr[r + c * Roff];
261 for(
unsigned int r = Roff; r <
R; r++ )
263 Pxx( r, 0 ) = conj( ptr[
R - r] );
264 for(
unsigned int c = 1; c <
C; c++ )
266 Pxx( r, c ) = conj( ptr[
R - r + (
C - c ) * Roff] );
275 arma::cx_mat
fft2( arma::mat& x )
277 arma::cx_mat Pxx(
R,
C, arma::fill::ones );
287 void ifft2( arma::cx_mat& Pxx, arma::mat& x )
290 unsigned int Roff =
R / 2 + 1;
291 arma::cx_mat Ptmp( Roff,
C );
292 std::complex<double>* ptr =
reinterpret_cast<std::complex<double>*
>( Ptmp.memptr() );
293 for(
unsigned int r = 0; r < Roff; r++ )
295 for(
unsigned int c = 0; c <
C; c++ )
297 ptr[r + c * Roff] = Pxx( r, c );
301 fftw_complex* in =
reinterpret_cast<fftw_complex*
>( Ptmp.memptr() );
302 double* out = x.memptr();
308 err_handler(
"Unable to create real data IFFTW plan" );
311 fftw_execute_dft_c2r(
pl_ifft, in, out );
320 arma::mat
ifft2( arma::cx_mat& Pxx )
333 int res = fftw_import_wisdom_from_string( wisd.c_str() );
335 err_handler(
"Unable to import wisdom from string!" );
344 int res = fftw_import_wisdom_from_filename( fname.c_str() );
346 err_handler(
"Unable to import wisdom from file!" );
355 fftw_plan pl_w = NULL;
359 if(
R == 0 ||
C == 0 )
361 x_r = fftw_alloc_real(
N );
362 x_cx1 = fftw_alloc_complex(
N );
365 pl_w = fftw_plan_dft_r2c_1d(
N, x_r, x_cx1,
export_alg );
369 x_r = fftw_alloc_real(
R *
C );
370 x_cx1 = fftw_alloc_complex(
R *
C );
373 pl_w = fftw_plan_dft_r2c_2d(
C,
R, x_r, x_cx1,
export_alg );
377 err_handler(
"Unable to create real data FFTW plan" );
381 if( fftw_export_wisdom_to_filename( fname.c_str() ) == 0 )
386 fftw_destroy_plan( pl_w );
397 fftw_plan pl_w = NULL;
401 if(
R == 0 ||
C == 0 )
403 x_r = fftw_alloc_real(
N );
404 x_cx1 = fftw_alloc_complex(
N );
407 pl_w = fftw_plan_dft_c2r_1d(
N, x_cx1, x_r,
export_alg );
411 x_r = fftw_alloc_real(
R *
C );
412 x_cx1 = fftw_alloc_complex(
R *
C );
415 pl_w = fftw_plan_dft_c2r_2d(
C,
R, x_cx1, x_r,
export_alg );
420 err_handler(
"Unable to create real data FFTW plan" );
424 if( fftw_export_wisdom_to_filename( fname.c_str() ) == 0 )
429 fftw_destroy_plan( pl_w );
440 fftw_plan pl_w = NULL;
441 fftw_complex *x_cx1, *x_cx2;
443 if(
R == 0 ||
C == 0 )
445 x_cx1 = fftw_alloc_complex(
N );
446 x_cx2 = fftw_alloc_complex(
N );
449 pl_w = fftw_plan_dft_1d(
N, x_cx1, x_cx2, FFTW_FORWARD,
export_alg );
453 x_cx1 = fftw_alloc_complex(
R *
C );
454 x_cx2 = fftw_alloc_complex(
R *
C );
457 pl_w = fftw_plan_dft_2d(
C,
R, x_cx1, x_cx2, FFTW_FORWARD,
export_alg );
462 err_handler(
"Unable to create complex data FFTW plan" );
466 if( fftw_export_wisdom_to_filename( fname.c_str() ) == 0 )
471 fftw_destroy_plan( pl_w );
482 fftw_plan pl_w = NULL;
483 fftw_complex *x_cx1, *x_cx2;
485 if(
R == 0 ||
C == 0 )
487 x_cx1 = fftw_alloc_complex(
N );
488 x_cx2 = fftw_alloc_complex(
N );
491 pl_w = fftw_plan_dft_1d(
N, x_cx2, x_cx1, FFTW_BACKWARD,
export_alg );
495 x_cx1 = fftw_alloc_complex(
R *
C );
496 x_cx2 = fftw_alloc_complex(
R *
C );
499 pl_w = fftw_plan_dft_2d(
C,
R, x_cx2, x_cx1, FFTW_BACKWARD,
export_alg );
503 err_handler(
"Unable to create complex data IFFTW plan" );
507 if( fftw_export_wisdom_to_filename( fname.c_str() ) == 0 )
512 fftw_destroy_plan( pl_w );
void ifft_cx(arma::cx_vec &Pxx, arma::cx_vec &x)
Inverse FFT.
fftw_plan pl_fft_cx
Complex FFTW plan.
int alg
plans](http://fftw.org/fftw3_doc/Planner-Flags.html#Planner-Flags)
arma::cx_vec fft(arma::vec &x)
FFT of real input.
FFTW(unsigned int _N, int _alg=FFTW_ESTIMATE)
Constructor.
fftw_plan pl_ifft
Real IFFTW plan.
arma::mat ifft2(arma::cx_mat &Pxx)
Inverse FFT.
arma::cx_mat fft2(arma::mat &x)
FFT of real 2D input.
FFTW(unsigned int _R, unsigned int _C, int _alg)
Constructor.
void export_wisdom_ifft_cx(const std::string fname)
Export complex IFFT wisdom to file.
arma::vec ifft(arma::cx_vec &Pxx)
Inverse FFT.
void export_wisdom_fft_cx(const std::string fname)
Export complex FFT wisdom to file.
fftw_plan pl_ifft_cx
Complex IFFTW plan.
void fft2(arma::mat &x, arma::cx_mat &Pxx)
FFT of real 2D input.
unsigned int C
FFT 2D dims.
arma::cx_vec fft_cx(arma::cx_vec &x)
FFT of complex input.
void ifft(arma::cx_vec &Pxx, arma::vec &x)
Inverse FFT.
void export_wisdom_ifft(const std::string fname)
Export real IFFT wisdom to file.
void export_wisdom_fft(const std::string fname)
Export real FFT wisdom to file.
arma::cx_vec ifft_cx(arma::cx_vec &Pxx)
Inverse FFT.
void import_wisdom_file(const std::string fname)
Import wisdom from file.
fftw_plan pl_fft
Real FFTW plan.
unsigned int N
FFT length.
int export_alg
Alg used for exporting wisdom.
void fft(arma::vec &x, arma::cx_vec &Pxx)
FFT of real input.
void import_wisdom_string(const std::string wisd)
Import wisdom from string.
void ifft2(arma::cx_mat &Pxx, arma::mat &x)
Inverse 2D FFT.
void fft_cx(arma::cx_vec &x, arma::cx_vec &Pxx)
FFT of complex input.