I am getting started with Python's FFT. I tested it on a signal that is a sum of three signals, two of which have an eigenfrequency of the grid, the third one does not (but due to large no. of data points, I still get a peak at the correct position).
However, the amplitudes are a bit off. The amplitude of the third signal is a bit higher than it should be (>=5.1 instead of 5). I was expecting that the amplitude would be lower for this signal, as it does not have one of the eigenfrequencies. But how can it be higher?
Also, for the two "well-defined" components of my signal, the amplitude is only correct to order 10^(-2). Again, one of them is a bit larger than the actual value. Are these numerical errors in the fft routine or is something wrong with my code?
import numpy as np import matplotlib.pyplot as plt from numpy.fft import fft, fftfreq, ifft L = 5 N = 1000 pi2 = 2*np.pi x = np.linspace(0, L, N) y1 = 10*np.sin(6*(2*np.pi/5)*x) ## has one of the eigenfrequencies y2 = 20*np.sin(10*(2*np.pi/5)*x) ## has one of the eigenfrequencies y3 = 5 *np.cos(626.3*x) ## lies between the highest and second highest eigenfrequencies y = y1 + y2 + y3 A = fft(y,N) freqs = fftfreq(N, d=L/N) * pi2 mask = freqs > 0 plt.figure(1) plt.plot(freqs[mask], 2*np.abs(A[mask]/N)) plt.show()