I have four cosines with frequencies 400e-3, 500e-3, 600e-3 and 700e-3 and I am trying to do the FFT of them but under the time I need, I cannot distinguish the four. Is there a way to distinguish the peaks without changing the tmax time of 1.76 and the frequencies?
JavaScript
x
25
25
1
import numpy as np
2
import scipy.fftpack
3
from scipy.fftpack import fftfreq
4
from scipy.fft import fft
5
import matplotlib.pyplot as plt
6
7
8
t = np.linspace(0,1.76,2400)
9
f = [400e-3, 500e-3, 600e-3, 700e-3] # these are the frequencies
10
yy = 0
11
12
for i in f:
13
y = 0.5*np.cos(2*np.pi*i*t)
14
yy = yy + y
15
16
plt.figure(0)
17
plt.plot(t, yy)
18
19
20
f = fftfreq(len(t), np.diff(t)[0])
21
yf = fft(yy)
22
plt.figure(1)
23
plt.plot(f[:t.size//2], np.abs(yf[:t.size//2]))
24
plt.show()
25
Here are the results:
Advertisement
Answer
The solution was to increase tmax of
JavaScript
1
2
1
t = np.linspace(0,1.76,2400)
2
i.e. 1.76. FFT makes bins the size of 1/tmax and the small tmax is, the bigger the bins are leading to less resolution.