I am trying to calculate an fft with Python. I am using the function fft.fft and I am applying it to a simple Sinusoidal signal. Here is my code:
import numpy as np import matplotlib.pyplot as plt frames=100 fps=1000 t=np.linspace(0, frames, frames)/fps x=np.sin(2*np.pi*80*t)+1 plt.plot(t, x, 'o-') plt.title('seno') plt.ylabel('sin') plt.xlabel('time $s$') plt.grid() plt.show() #calculating the fft sin_fft=np.fft.fft(x) #calculating the absolute value sin_fft_abs=np.ones(len(sin_fft)) for i in range(len(sin_fft)): sin_fft_abs[i]=np.sqrt((sin_fft[i].real**2)+(sin_fft[i].imag**2)) sin_fft_final=sin_fft_abs/frames #calculating the frequencies inc=fps/frames freq=np.linspace(0, fps-inc, fps/inc) plt.plot(freq, sin_fft_final, 'o-') plt.xlim(xmax=fps/2) plt.title('seno fft') plt.ylabel('sin fft') plt.xlabel('f $Hz$') plt.grid() plt.show() It can find the right offset (1 in this simple case), but the amplitude of the peak corresponding to the Sinus Frequency (80 in this case) is half the Amplitude of the Signal, always. I have no idea why it finds the correct Offset, but not the correct Amplitude!
I would be grateful if somebody could help me, Thanks a lot, Francesca