I have tried to calculate the Fourier Transform of a Gaussian function by using FFTW3 in C++. Here is the main part of my code
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);
}
Since the array has been initialized with the values of a Gaussian, I would expect that the output is also a Gaussian but actually only the envelope has a Gaussian shape. As I show in the data below, where it is possible to see that some negative values have appeared.
#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
Could anyone tell me what I am doing wrong? I would really appreciate your help. Thanks a lot.
You're not doing anything wrong in the sense of the C programming or FFTW calls: those are the correct values. The real part of the FFT of a Gaussian curve does oscillate around zero. If you plot the absolute values, that might look a little more like you expect.
These oscillations are expected. In practice, one needs to use a window function to reduce these oscillations. http://en.wikipedia.org/wiki/Window_function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.