我試圖計算由用C使用FFTW3 ++所述傅立葉變換的高斯函數的。這裏是我的代碼評價傅立葉變換FFTW3高斯的和C++
main(int argc, char** argv)
{
fftw_plan p;
complex<double> *in,*out;
long N=8;
//allocation of in and the fftw plan called
in=(complex<double>*) calloc(N,sizeof(complex<double>));
p=fftw_plan_dft_1d(N,(fftw_complex*)in,(fftw_complex*)in,FFTW_BACKWARD,FFTW_ESTIMATE);
//initialize the array in with the values of a Gaussian function
gaussianf(in,N);
//Fourier transform in
fftw_execute(p);
//write the result into a file
writeft(in,N);
fftw_destroy_plan(p);
}
因爲陣列已與高斯的值進行初始化的主體部分,我希望的是,輸出也是高斯,但實際上只信封具有高斯形狀。正如我在下面的數據中所顯示的那樣,有可能看到一些負值出現了。
#input values
#x real part imag part
-10 3.72008e-44 0
-7.5 3.72336e-25 0
-5 1.38879e-11 0
-2.5 0.00193045 0
0 1 0
2.5 0.00193045 0
5 1.38879e-11 0
7.5 3.72336e-25 0
#output
#x real part imag part
-10 1.00386 0
-7.5 -1.00273 0
-5 1 0
-2.5 -0.99727 0
0 0.996139 0
2.5 -0.99727 0
5 1 0
7.5 -1.00273 0
有人能告訴我我做錯了什麼嗎?我將衷心感謝您的幫助。非常感謝。
您剛纔開箱即用的命令所描繪?我使用相同的庫,但在轉換真實和偶數數據時,我得到非零虛部。 – Vesnog