版本:Python 3.9.1+numpy 1.21.3
运行出错!!,求解惑。
#Compute and Plot FFT
tic = time.perf_counter()
plt.figure(3)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
yf = fft(x)
plt.plot(xf, 2.0/N * np.abs(yf[0:np.int(N/2)]))
plt.grid()
plt.xlabel('Frequency (Hz)')
plt.ylabel('Accel (g)')
plt.title('FFT - ' + file_path)
toc = time.clock()
print("FFT Time:",toc-tic)
plt.show()
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\vibration analysis\vibration-analysis-MATLAB-Python-functions\Load_Plot_RMS_FFT.py", line 58, in
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
File "<__array_function__ internals>", line 5, in linspace
File "D:\python\lib\site-packages\numpy\core\function_base.py", line 120, in linspace
num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer