In [1]:
from numpy import sin, linspace, pi
from pylab import plot, show, title, xlabel, ylabel, subplot
from scipy import fft, arange

##2014-10-10, Qingkai

Question:

I got a question today ask me about the amplitude relationship of an FFT spectrum and the real signal, so I did some experiment, and here's some results.

Answer:

The Parseval's Theorem tells us that the total power in the frequency domain should be equal to the time domain. So in my opinion, the amplitude of the time domain signal should be equal to the frequency domain magnitude. for example, in a simple case, you can think of a time domain sine wave signal is generated by adding two other sine wave signal with different frequency, when you do the fft transform, you should see 4 peaks (because of the complex conjugate symmetry in the frequency domain), so the amplitude in the frequency domain of a specific frequency (2 peaks) should be the same amplitude as the one in the time domain.

Toy example

To illustrate this better, I generate a sine wave by adding two other sine waves, one is amplitude 10 at 5 Hz, the other is amplitude 5 at 2 Hz, then I do a fft, and just plot half of the spectrum (because of symmetry), now you can see I have a peak at 5 Hz with amplitude 5, and the other peak at 2 Hz with amplitude 2.5, which is correct.


In [2]:
def plotSpectrum(y,Fs):
 """
 Plots a Single-Sided Amplitude Spectrum of y(t)
 """
 n = len(y) # length of the signal
 k = arange(n)
 T = n/Fs
 frq = k/T # two sides frequency range
 frq = frq[range(n/2)] # one side frequency range

 Y = fft(y)/n # fft computing and normalization
 Y = Y[range(n/2)]
 print max(abs(Y))
 plot(frq,abs(Y),'r') # plotting the spectrum
 xlabel('Freq (Hz)')
 ylabel('|Y(freq)|')

In [3]:
Fs = 150.0;  # sampling rate
Ts = 1.0/Fs; # sampling interval
t = arange(0,1,Ts) # time vector

ff = 5;   # frequency of the signal
y = 10*sin(2*pi*ff*t) + 5*sin(2*pi*2*t)

subplot(2,1,1)
plot(t,y)
xlabel('Time')
ylabel('Amplitude')
subplot(2,1,2)
plotSpectrum(y,Fs)
show()


5.0

Note:

When you test this in matlab, you may have different results (not a factor of 2) from mine, this is because there's a scaling factor in matlab, the size of this scaling factor is a matter of covention, but most commonly is a factor of N, which N is the number of data points you have. Check your FFT documentation for this.

That is, if we want to compare two signals spectrum, we need firts correct this scaling factor, because it is dependent on the total length of the signal, after we correct this, we can compare the two specturm at same frequencies, and this should tell us which signal has more energy from certain frequency.


In [ ]: