Hello Francesco,
It appears that you are looking for the kind fft normalization that approximates a Fourier transform. If that is not what you are looking for, then this answer is not germane, but if it is, then
Y(f) = Integral {-inf,inf} X(t) exp(-i 2 pi f t) dt
which you can approximate with
dt = 1/Fs;
Y = fft(X)*dt;
In not every case is dt is defined by dt = 1/Fs but it is here.
For reasons known only to themselves, Mathworks has a gaussian function whose integral as a continuous function = 1/4. For f=0 the expression for Y above approximates this integral so as you know, the answer should be Y(0) = 1/4.
They chose a different normalization fft(X)/n (less appropriate to this situation) so you don't get that answer. Your expression fft(X)/L does give the answer, but that's a coincidence having to do with the specific limits of the t array. To get the answer of 1/4, the factor should be dt. The code below illustrates that, where the limits of the t array have been changed to +-.7 to remove the coincidence.
Rather than plot out half of the frequency domain, the code plots the entire domain and uses fftshift to put zero frequency at the center of the freq array.
As to the question of doubled amplitudes, you can do that any time including this one, but it only makes sense for a set of real signals, each of the form A_m cos(2 pi f_m t + phi) [maybe times a decay factor exp(-g_m t) ]. In that case the fft(X)/n normalization gives peaks at frequency +-f_m, of height A_m / 2, each with a complex phase factor. People take abs of that, double the size of the peak (the f=0 value should not be doubled but that mistake gets made often) and plot out positive frequencies only. That gives you the amplitudes A_m of the cos functions so you can see a spectrum. But at that point you have thrown away phase information so you can’t do an ifft to get back to the original signal.
In the case of a continuous function like a Gaussian there is no real incentive or purpose to do all that.
Fs = 100;
t = -0.7:1/Fs:0.7;
L = length(t);
X = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01)));
figure(1)
plot(t,X)
title('Gaussian Pulse in Time Domain')
xlabel('Time (t)')
ylabel('X(t)')
n = 2^nextpow2(L);
Y = fftshift(fft(X,n));
f = Fs*(-n/2:n/2-1)/n;
P1 = abs(Y)/n;
P2 = abs(Y)/L;
P3 = abs(Y)*(1/Fs);
figure(2)
plot(f,P1,f,P2,f,P3)
title('Gaussian Pulse in Frequency Domain')
xlabel('Frequency (f)')
ylabel('|P(f)|')
Best Answer