The result of calculating the fourier transform using numerical integration is:

enter image description here

the result of using Matlab's FFT is:

enter image description here

So where did I go wrong here? I know the FT of a Gaussian should be another Gaussian. Shouldn't they be the same? Furthermore I would have thought the


Following a suggestion using the fftshift function gets me to the following plot, but this looks very different to the original fft despite documentation stating that it just centres the result around zero frequency.

enter image description here

which is more resembling what I would expect.

omega = linspace(-30,30,1000);

t = linspace(-10,10,1000);
y = exp(-t.^2./2)/sqrt(2*pi);
Yft = fft(y);

% Pre-allocate results of integration.
Y = zeros(size(omega)); 

for k=1:length(omega)
    Y(k) = trapz(t, exp(-t.^2./2)/sqrt(2*pi).*exp(1j*omega(k).*t)); 

plot(omega, real(Y), omega, imag(Y));

plot(omega, real(Yft), omega, imag(Yft));
  • 1
    $\begingroup$ To start with matlab puts frequency components in a somewhat non-intuitive way where the zero frequency components are at the edges. Use fftshift to swap it so the zero frequency components are centered. However, I think you have other problems than just this. $\endgroup$ – nivag Oct 14 '14 at 9:57
  • 1
    $\begingroup$ you should use fftshift on your second figure (which is created by the fft function) not the first. $\endgroup$ – nivag Oct 14 '14 at 10:29

There are two reasons why you get different results. The first is that you define a vector t between $-10$ and $10$, but the fft command doesn't know that. So the data are interpreted as starting at $0$. This means the first difference is that the FFT computes the transform of a delayed Gaussian impulse, not of an impulse centered at time zero. This is why you get a non-zero imaginary part in the result of the FFT.

The second problem is - as pointed out by nivag in a comment - that the first index of the result of the FFT corresponds to frequency zero, and the negative frequencies appear in the second half of the resulting vector.

  • $\begingroup$ Thanks, so how would I tell the fft that the samples start at negative time? $\endgroup$ – Dipole Oct 14 '14 at 10:33
  • $\begingroup$ @Jack: You can't. Since the FFT data are always interpreted as being periodic, you just need to shift the data such that the negative times appear at the end of the data vector. I.e., imagine your data as being continued periodically and just use the first full period starting at time zero instead of the period with center zero. $\endgroup$ – Matt L. Oct 14 '14 at 10:39
  • $\begingroup$ BTW, note that to get perfectly symmetric data you need an odd number of samples. $\endgroup$ – Matt L. Oct 14 '14 at 10:40
  • $\begingroup$ Great that actually makes sense. Does matlab have a fast way of doing this or do I need to manually slice my data array? $\endgroup$ – Dipole Oct 14 '14 at 10:44
  • $\begingroup$ @Jack: As pointed out by nivag, check out fftshift. To be honest, I never use it but it should do the job. $\endgroup$ – Matt L. Oct 14 '14 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.