Pella86

FFTW Test

Oct 19th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include "fftw3.h"
  3.  
  4. using namespace std;
  5.  
  6. // macros for the real and imaginary parts
  7. #define REAL 0
  8. #define IMAG 1
  9. // length of the complex arrays
  10. #define N 8
  11.  
  12. void fft(fftw_complex *in, fftw_complex *out)
  13. {
  14.     // create a DFT plan
  15.     fftw_plan plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
  16.     // execute the plan
  17.     fftw_execute(plan);
  18.     // do some cleaning
  19.     fftw_destroy_plan(plan);
  20.     fftw_cleanup();
  21. }
  22.  
  23. int main()
  24. {
  25.  
  26.     cout << "Start program" << endl;
  27.  
  28.     // input array
  29.     fftw_complex x[N];
  30.     // output array
  31.     fftw_complex y[N];
  32.     // fill the first array with some numbers
  33.     for (int i = 0; i < N; ++i) {
  34.         x[i][REAL] = i + 1;     // i.e., { 1, 2, 3, 4, 5, 6, 7, 8 }
  35.         x[i][IMAG] = 0;
  36.     }
  37.  
  38.     // compute the FFT of x and store the results in y
  39.     fft(x, y);
  40.  
  41.     cout << "Hello world!" << endl;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment