# Why are analytic FFT and computational FFT not matching?

I have an exponentially decaying function that I want to Fourier transform. My question is why I am not getting the same result with the analytical form and the computational one with np.fft? I have a function r(t) defined as follow:

    import numpy as np
fs =5e6
f0 = fs/2/102
dt = 1./fs
t = np.arange(0,0.0021544,dt)
tau = 30e-6
r = lambda t : (1/tau)*np.exp(-t/(tau))


that I want to Fourier-transform. According to the definition of the Fourier transform of this function r I am expecting:

    tp =t[0:102] # so half of a period
freq = np.fft.fftfreq(np.size(tp), d = dt)
Rf_def = np.divide(1,1+1j*2*np.pi*freq*tau)  # This is the analytical definition of the fourier transform of my function r(tp)


But when I do :

    Rf = np.fft.fft(r(tp))


I don't get the same result as the analytical FFT that I defined above. Why is that ?

This is a plot of the analytical form of the fourier transform so plt.plot(Rf_def).

This is a plot of the compututional fourier transfrom so plt.plot(Rf).

• can you please expand your answer. Does that mean that the analytical and compututional forms won' match with this sampling Frequency ? – Tassou Apr 14 '17 at 17:11
• Thank you for your answers, but I think that you do not really get me. Here is a link to a better developped question : dsp.stackexchange.com/questions/40248/… I would appreciate if you take a look at it. Thank you! – Tassou Apr 14 '17 at 20:48
• I think editing this question was better than creating a new one. – Jan-Bert Apr 15 '17 at 7:07

The fourier transform is defined for both positive and negative frequencies. It looks like your first plot is just the positive frequencies, whereas the second plot contains both the positive and negative frequencies. It's common in computational fft routines to have the positive frequencies occupy elements 1 to N/2 in the results vector, and then elements N/2 to N are the negative frequencies. Also, computational results are often unscaled. You'll need to divide the results by the length of the window. Here is a short article I wrote explaining this for matlab http://mechanicalvibration.com/Making_matlab_s_fft_functio.html Your results for python should be similar.

There's something very basic you're missing here -- FFT is not the "classic" Fourier transform. FFT is really DFT (Discrete Fourier Transform).

A "classic" Fourier transform has a continuous input, as well as a continuous output. DFT has discrete input and output.

What you refer to as the "analytic FFT of $r$" is in reality the (continuous) classic Fourier transform (assuming continuous input and output), of a continuous function $r(t)$. In this case, the transform is indeed an expression similar to the one you've put into Rf_def.

However, what you're calculating with np.fft.fftfreq is the DFT of a discrete sequence. This is not the same thing as the classic Fourier transform, hence the different results.

Specifically, if you'll do the analytic math with the classic Fourier transform definition, you'll realize that feeding a discrete argument to the classic Fourier transform produces a periodic output - this is exactly what you see in the second plot - a periodic sum of the first plot. (hint for the analytic math: use for the transform's input a product of a continuous function with an impulse train, then use the product-convolution transform pair)

An FFT is just s fast way to compute a DFT. A DFT of any strictly real input will always be conjugate symmetric. Half of a DFT of a sampled waveform will resemble the FT of that waveform only if that waveform is strictly bandlimited (perfectly low-pass filtered) to below half the sample rate.