FFTW程序Demo

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include <fftw3.h>
 4 #include<string.h>
 5 #include <complex.h>
 6 int main()
 7 {
 8 
 9     fftw_complex *in, *out;
10 
11     fftw_plan p;
12 
13         int N=3;
14     in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
15 
16     out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
17 
18     for(int i=0;i<N;i++)
19     {
20         in[i][0]=i+1;
21         in[i][1]=0;
22     }
23     memset(out,0,sizeof(out));
24 
25 
26     p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
27     fftw_execute(p);
28     for(int i=0;i<N;i++)
29     {
30         printf("%f %f i \n",out[i][0],out[i][1]);
31     }
32     p = fftw_plan_dft_1d(N, out, in, FFTW_BACKWARD, FFTW_ESTIMATE);
33     fftw_execute(p);
34 //...
35     for(int i=0;i<N;i++)
36     {
37         printf("%f %f i \n",in[i][0],in[i][1]);
38     }
39 
40     fftw_destroy_plan(p);
41 
42     fftw_free(in);
43     fftw_free(out);
44     return 0;
45 
46 }

当n=3的时候结果为:

6.000000 0.000000 i
-1.500000 0.866025 i
-1.500000 -0.866025 i
3.000000 0.000000 i
6.000000 0.000000 i
9.000000 0.000000 i

 

当n=4的时候结果为:

10.000000 0.000000 i
-2.000000 2.000000 i
-2.000000 0.000000 i
-2.000000 -2.000000 i
4.000000 0.000000 i
8.000000 0.000000 i
12.000000 0.000000 i
16.000000 0.000000 i

posted on 2016-04-28 16:14  holyprince  阅读(795)  评论(0编辑  收藏  举报

导航