我正在尝试在使用Eclipse(Kepler)和MinGW(gcc 4.7.2)的Windows 8系统上的C程序中使用FFTW .dll(v 3.3.3)。我怀疑有两个问题与我的配置有关:
有人能指出我正确的方向吗?
代码:
#include <stdio.h>
#include <stdlib.h>
#include <complexUtil.h>
#include <fftw3.h>
#define N 976
main()
{
fftw_complex *in, *out;
fftw_plan p;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
FILE* infile;
float value;
int i = 0;
// Populate input array from file
infile = fopen("testData.txt", "r");
for (i=0; i<N; i++) {
fscanf(infile, "%f", &value);
(*(in + i)) = value + 0.0i;
}
fclose(infile);
// Perform fft
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(p);
fftw_destroy_plan(p);
fftw_free(in); fftw_free(out);
// Debug output
printf("in\t\tout\n");
for (i=0; i<N; i++) {
printf("%f\t%f\n",
creal((fftw_complex)* (in + i )),
creal((fftw_complex)* (out + i )));
}
return(0);
}
编译器调用:
gcc "-IC:\\Users\\Brian\\workspace\\psd\\src" "-IC:\\Users\\Brian\\workspace\\psd\\lib" "-includeC:\\Users\\Brian\\workspace\\psd\\src\\complexUtil.h" "-includeC:\\Users\\Brian\\workspace\\psd\\src\\fftw3.h" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\psd.o" "..\\src\\psd.c"
gcc "-LC:\\Users\\Brian\\workspace\\psd\\lib" -Wl,--stack,2048 -o psd.exe "src\\psd.o" -lfftw3-3
正常输出:
in out
0.188000 348.455000
0.000000 29.738027
0.021000 -88.468551
0.021000 16.764387
0.021000 -48.056287
...
调试输出:
in out
-2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 -2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
-2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 -2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
...
另一个症状是:在调试模式下,没有显示输出,因为我一直步进直到通过输出循环进行一定数量的迭代。然后我得到一个输出块,Eclipse中的步进函数显示为灰色。
答案 0 :(得分:0)
977是素数,因此它不会像FFTW所要求的那样分解为小素数的幂。因此fftw_plan_dft_1d
将失败并返回NULL,并且随后对p == NULL的FFTW的任何调用当然都会崩溃。如果您尝试N的合理值> 976,例如N = 1024,然后应该按预期工作,因为您的代码看起来没问题(除了完全没有错误检查)。