我正在尝试实现为C中的2D数组的每一行计算一维FFT。 这是我的代码(这里的m和n分别是行数和矩阵的列数):
int howmany;
int i;
int idist = 1;
int inembed;
int istride;
int j;
int m;
int n;
int odist = 1;
int onembed;
int ostride;
int rank = 1;
fftw_complex *in;
fftw_complex *out;
fftw_plan plan_forward;
m = atoi(argv[1]);
n = atoi(argv[2]);
howmany = m;
istride = n;
ostride = n;
inembed = n;
onembed = n;
in = fftw_malloc ( sizeof ( fftw_complex ) * m * n );
out = fftw_malloc ( sizeof ( fftw_complex ) * m * n );
for ( i = 0; i < ( m * n ); i++ )
{
in[i][0] = m * n - i - 1 ;
in[i][1] = 0 ;
}
printf("Print Initial Data: \n");
for ( i = 0 ; i < m ; i ++)
{
for ( j = 0; j < n; j++ )
{
printf ( " %12f\t", in[j + i * n][0]);
}
printf("\n");
}
plan_forward = fftw_plan_many_dft(rank, &n, howmany,
in, &inembed,
istride, idist,
out, &onembed,
ostride, odist,
FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute ( plan_forward );
printf("Print Result FFT:\n");
for ( i = 0 ; i < m ; i ++)
{
for ( j = 0; j < n; j++ )
{
printf ( " %4d %12f %12f\n", i, out[j + i * n][0], out[j + i * n][1] );
}
printf("\n");
}
fftw_destroy_plan ( plan_forward );
fftw_free ( out );
fftw_free ( in );
以下是4 x 4 2D阵列的结果:
Print Initial Data:
15.000000 14.000000 13.000000 12.000000
11.000000 10.000000 9.000000 8.000000
7.000000 6.000000 5.000000 4.000000
3.000000 2.000000 1.000000 0.000000
Print Result FFT:
0 36.000000 0.000000
0 32.000000 0.000000
0 28.000000 0.000000
0 24.000000 0.000000
1 8.000000 -8.000000
1 8.000000 -8.000000
1 8.000000 -8.000000
1 8.000000 -8.000000
2 8.000000 0.000000
2 8.000000 0.000000
2 8.000000 0.000000
2 8.000000 0.000000
3 8.000000 8.000000
3 8.000000 8.000000
3 8.000000 8.000000
3 8.000000 8.000000
任何人都可以告诉我为什么我的错误结果?我可能以错误的方式调用fftw_plan fftw_plan_many_dft,但我看不到它。