FFTW程序Demo

时间:2021-10-03 06:07:30
 #include<stdio.h>
#include<stdlib.h>
#include <fftw3.h>
#include<string.h>
#include <complex.h>
int main()
{ fftw_complex *in, *out; fftw_plan p; int N=;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); for(int i=;i<N;i++)
{
in[i][]=i+;
in[i][]=;
}
memset(out,,sizeof(out)); p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(p);
for(int i=;i<N;i++)
{
printf("%f %f i \n",out[i][],out[i][]);
}
p = fftw_plan_dft_1d(N, out, in, FFTW_BACKWARD, FFTW_ESTIMATE);
fftw_execute(p);
//...
for(int i=;i<N;i++)
{
printf("%f %f i \n",in[i][],in[i][]);
} fftw_destroy_plan(p); fftw_free(in);
fftw_free(out);
return ; }

当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