我正在使用这个fftw库。
目前我正在尝试以 e^(-(x^2+y^2)/a^2) 的形式绘制二维高斯曲线。
这是代码:
using namespace std;
int main(int argc, char** argv ){
fftw_complex *in, *out, *data;
fftw_plan p;
int i,j;
int w=16;
int h=16;
double a = 2;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*w*h);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*w*h);
for(i=0;i<w;i++){
for(j=0;j<h;j++){
in[i*h+j][0] = exp(- (i*i+j*j)/(a*a));
in[i*h+j][1] = 0;
}
}
p = fftw_plan_dft_2d(w, h, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(p);
//This is something that print what's in the matrix
print_2d(out,w,h);
fftw_destroy_plan(p);
fftw_free(in);
fftw_free(out);
return 0;
}
原来负数出现了。我认为高斯的傅里叶变换是另一个高斯,它不应该包含任何负数。
此外,当前原点位于 in[0]