I compare the forward FFT using FFTW and MATLAB fft
. The input signal is a Gaussian. Code:
FFTW using C:
float *signal; /*input signal*/
int nt; /*length of the signal*/
fftw_complex *in, *out;
fftw_plan plan1;
in = fftw_malloc(nt*sizeof(fftw_complex));
out = fftw_malloc(nt*sizeof(fftw_complex));
for (j=0;j<nt;j++){
in[j][0]=(double)signal[j];
in[j][1]=0.0;
}
plan1 = fftw_plan_dft_1d(nt, in, out, -1, FFTW_ESTIMATE);
fftw_execute(plan1);
fftw_destroy_plan(plan1);
for (j=0;j<nt;j++){
real[j]=(float)out[j][0];
imag[j]=(float)out[j][1];
}
fft
function in MATLAB:
fft(signal);
I plot the real and imaginary parts of both results:
The real part are almost the same value, while the imaginary part has quite different values. How to fix this problem?