42 KiB
42 KiB
In [96]:
import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack
import math as mt
"""N=500
T=1.0/500.0
t=np.arange(0, N*T, T)
y = np.sin(50.0 * 2.0*np.pi*t) + 0.5*np.sin(80.0 * 2.0*np.pi*t)
dft=np.fft.fft(y)
ft=np.arange(0, N/2, 1) #Dividing the amount by 2 cuts out the arbitrary frequency spikes at the end of the data
plt.plot(t[:200], y[:200], color='orange')
plt.show()
plt.plot(ft,np.abs(dft)[:N//2])
plt.show()"""
#Does N and T change the frequency value?
N=500
T=1/500.0
t=np.arange(0, N*T, T)
y = np.sin(50.0 * 2.0*np.pi*t) + 0.5*np.sin(80.0 * 2.0*np.pi*t)
dft=np.fft.fft(y)
ft=np.arange(0, N/2, 1) #Dividing the amount by 2 cuts out the arbitrary frequency spikes at the end of the data
plt.plot(t[:200], y[:200], color='orange')
plt.show()
plt.plot(ft,np.abs(dft)[:N//2])
plt.show()
# Number of samplepoints
N = 600
# sample spacing
T = 1.0 / 800.0
x = np.linspace(0.0, N*T, N)
y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
yf = np.fft.fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
plt.plot(xf, 2.0/N * np.abs(yf[:N//2]))
plt.show()
print (x.shape, y.shape, yf.shape, xf.shape)
print (yf[:N//2].shape)[0;31m---------------------------------------------------------------------------[0m [0;31mValueError[0m Traceback (most recent call last) [0;32m<ipython-input-96-5364dc22575e>[0m in [0;36m<module>[0;34m()[0m [1;32m 32[0m [0mpeak[0m[0;34m=[0m[0mmt[0m[0;34m.[0m[0mceil[0m[0;34m([0m[0mmax[0m[0;34m([0m[0mnp[0m[0;34m.[0m[0mabs[0m[0;34m([0m[0mdft[0m[0;34m)[0m[0;34m)[0m[0;34m)[0m[0;34m[0m[0m [1;32m 33[0m [0mdft[0m[0;34m=[0m[0mnp[0m[0;34m.[0m[0mndarray[0m[0;34m.[0m[0mtolist[0m[0;34m([0m[0mdft[0m[0;34m)[0m[0;34m[0m[0m [0;32m---> 34[0;31m [0mfre[0m[0;34m=[0m[0mdft[0m[0;34m.[0m[0mindex[0m[0;34m([0m[0mpeak[0m[0;34m)[0m[0;34m[0m[0m [0m[1;32m 35[0m [0mfro[0m[0;34m=[0m[0mft[0m[0;34m[[0m[0mfre[0m[0;34m][0m[0;34m[0m[0m [1;32m 36[0m [0mprint[0m [0;34m([0m[0mfro[0m[0;34m)[0m[0;34m[0m[0m [0;31mValueError[0m: 250 is not in list
In [ ]:
In [ ]: