44 FFTW(
unsigned int _N,
int _alg = FFTW_ESTIMATE)
50 export_alg = FFTW_PATIENT;
63 FFTW(
unsigned int _R,
unsigned int _C,
int _alg)
69 export_alg = FFTW_PATIENT;
82 fftw_destroy_plan(pl_fft);
84 fftw_destroy_plan(pl_ifft);
85 if (pl_fft_cx != NULL)
86 fftw_destroy_plan(pl_fft_cx);
87 if (pl_ifft_cx != NULL)
88 fftw_destroy_plan(pl_ifft_cx);
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());
101 if (pl_fft_cx == NULL)
103 pl_fft_cx = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, alg);
104 if (pl_fft_cx == NULL)
106 err_handler(
"Unable to create complex data FFTW plan");
109 fftw_execute_dft(pl_fft_cx, in, out);
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());
133 if (pl_ifft_cx == NULL)
135 pl_ifft_cx = fftw_plan_dft_1d(N, in, out, FFTW_BACKWARD, alg);
136 if (pl_ifft_cx == NULL)
138 err_handler(
"Unable to create complex data IFFTW plan");
141 fftw_execute_dft(pl_ifft_cx, in, out);
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)
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();
206 pl_ifft = fftw_plan_dft_c2r_1d(N, in, out, alg);
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(
245 err_handler(
"Unable to create real data FFTW plan");
249 fftw_execute_dft_r2c(pl_fft, in, out);
252 std::complex<double> *ptr =
reinterpret_cast<std::complex<double> *
>(out);
253 const unsigned int Roff = R / 2 + 1;
254 for (
unsigned int r = 0; r < Roff; r++)
256 for (
unsigned int c = 0; c <
C; c++)
258 Pxx(r, c) = ptr[r + c * Roff];
262 for (
unsigned int r = Roff; r <
R; r++)
264 Pxx(r, 0) = conj(ptr[R - r]);
265 for (
unsigned int c = 1; c <
C; c++)
267 Pxx(r, c) = conj(ptr[R - r + (C - c) * Roff]);
276 arma::cx_mat
fft2(arma::mat &x)
278 arma::cx_mat Pxx(R, C, arma::fill::ones);
288 void ifft2(arma::cx_mat &Pxx, arma::mat &x)
291 unsigned int Roff = R / 2 + 1;
292 arma::cx_mat Ptmp(Roff, C);
293 std::complex<double> *ptr =
294 reinterpret_cast<std::complex<double> *
>(Ptmp.memptr());
295 for (
unsigned int r = 0; r < Roff; r++)
297 for (
unsigned int c = 0; c <
C; c++)
299 ptr[r + c * Roff] = Pxx(r, c);
303 fftw_complex *in =
reinterpret_cast<fftw_complex *
>(Ptmp.memptr());
304 double *out = x.memptr();
307 pl_ifft = fftw_plan_dft_c2r_2d(C, R, in, out, alg);
310 err_handler(
"Unable to create real data IFFTW plan");
313 fftw_execute_dft_c2r(pl_ifft, in, out);
335 int res = fftw_import_wisdom_from_string(wisd.c_str());
337 err_handler(
"Unable to import wisdom from string!");
346 int res = fftw_import_wisdom_from_filename(fname.c_str());
357 fftw_plan pl_w = NULL;
361 if (R == 0 || C == 0)
363 x_r = fftw_alloc_real(N);
364 x_cx1 = fftw_alloc_complex(N);
367 pl_w = fftw_plan_dft_r2c_1d(N, x_r, x_cx1, export_alg);
371 x_r = fftw_alloc_real(R * C);
372 x_cx1 = fftw_alloc_complex(R * C);
375 pl_w = fftw_plan_dft_r2c_2d(C, R, x_r, x_cx1, export_alg);
379 err_handler(
"Unable to create real data FFTW plan");
383 if (fftw_export_wisdom_to_filename(fname.c_str()) == 0)
388 fftw_destroy_plan(pl_w);
399 fftw_plan pl_w = NULL;
403 if (R == 0 || C == 0)
405 x_r = fftw_alloc_real(N);
406 x_cx1 = fftw_alloc_complex(N);
409 pl_w = fftw_plan_dft_c2r_1d(N, x_cx1, x_r, export_alg);
413 x_r = fftw_alloc_real(R * C);
414 x_cx1 = fftw_alloc_complex(R * C);
417 pl_w = fftw_plan_dft_c2r_2d(C, R, x_cx1, x_r, export_alg);
422 err_handler(
"Unable to create real data FFTW plan");
426 if (fftw_export_wisdom_to_filename(fname.c_str()) == 0)
431 fftw_destroy_plan(pl_w);
442 fftw_plan pl_w = NULL;
443 fftw_complex *x_cx1, *x_cx2;
445 if (R == 0 || C == 0)
447 x_cx1 = fftw_alloc_complex(N);
448 x_cx2 = fftw_alloc_complex(N);
451 pl_w = fftw_plan_dft_1d(N, x_cx1, x_cx2, FFTW_FORWARD, export_alg);
455 x_cx1 = fftw_alloc_complex(R * C);
456 x_cx2 = fftw_alloc_complex(R * C);
459 pl_w = fftw_plan_dft_2d(C, R, x_cx1, x_cx2, FFTW_FORWARD, export_alg);
464 err_handler(
"Unable to create complex data FFTW plan");
468 if (fftw_export_wisdom_to_filename(fname.c_str()) == 0)
473 fftw_destroy_plan(pl_w);
483 fftw_plan pl_w = NULL;
484 fftw_complex *x_cx1, *x_cx2;
486 if (R == 0 || C == 0)
488 x_cx1 = fftw_alloc_complex(N);
489 x_cx2 = fftw_alloc_complex(N);
492 pl_w = fftw_plan_dft_1d(N, x_cx2, x_cx1, FFTW_BACKWARD, export_alg);
496 x_cx1 = fftw_alloc_complex(R * C);
497 x_cx2 = fftw_alloc_complex(R * C);
500 pl_w = fftw_plan_dft_2d(C, R, x_cx2, x_cx1, FFTW_BACKWARD, export_alg);
504 err_handler(
"Unable to create complex data IFFTW plan");
508 if (fftw_export_wisdom_to_filename(fname.c_str()) == 0)
513 fftw_destroy_plan(pl_w);
void import_wisdom_file(const std::string fname)
Import wisdom from file.
unsigned int C
FFT 2D dims.
arma::mat ifft2(arma::cx_mat &Pxx)
Inverse FFT.
arma::cx_vec fft(arma::vec &x)
FFT of real input.
void ifft2(arma::cx_mat &Pxx, arma::mat &x)
Inverse 2D FFT.
void export_wisdom_fft_cx(const std::string fname)
Export complex FFT wisdom to file.
void import_wisdom_string(const std::string wisd)
Import wisdom from string.
fftw_plan pl_ifft_cx
Complex IFFTW plan.
fftw_plan pl_fft
Real FFTW plan.
FFTW(unsigned int _R, unsigned int _C, int _alg)
Constructor.
arma::cx_vec ifft_cx(arma::cx_vec &Pxx)
Inverse FFT.
FFTW(unsigned int _N, int _alg=FFTW_ESTIMATE)
Constructor.
unsigned int N
FFT length.
arma::cx_mat fft2(arma::mat &x)
FFT of real 2D input.
void ifft(arma::cx_vec &Pxx, arma::vec &x)
Inverse FFT.
void export_wisdom_fft(const std::string fname)
Export real FFT wisdom to file.
arma::vec ifft(arma::cx_vec &Pxx)
Inverse FFT.
void fft2(arma::mat &x, arma::cx_mat &Pxx)
FFT of real 2D input.
fftw_plan pl_ifft
Real IFFTW plan.
arma::cx_vec fft_cx(arma::cx_vec &x)
FFT of complex input.
int export_alg
Alg used for exporting wisdom.
void export_wisdom_ifft(const std::string fname)
Export real IFFT wisdom to file.
void ifft_cx(arma::cx_vec &Pxx, arma::cx_vec &x)
Inverse FFT.
void export_wisdom_ifft_cx(const std::string fname)
Export complex IFFT wisdom to file.
int alg
plans](http://fftw.org/fftw3_doc/Planner-Flags.html#Planner-Flags)
void fft_cx(arma::cx_vec &x, arma::cx_vec &Pxx)
FFT of complex input.
void fft(arma::vec &x, arma::cx_vec &Pxx)
FFT of real input.
fftw_plan pl_fft_cx
Complex FFTW plan.