FFT频率错误,代码是否存在问题

时间:2019-05-24 07:08:09

标签: python-3.x fft

想将原始加速度计数据转换为频率,但是我已将电动机上的频率设置为120hz,并用另一台设备检查,我无法对加速度计数据进行FFT以获得电动机产生的正确频率

使用Python 3.7,数据使用最有可能是正确的,所以想知道代码中是否有问题

from scipy.fftpack import fft
import numpy as np
from scipy import pi
import matplotlib.pyplot as plt
%matplotlib inline

# Sampling rate and time vector
start_time = 0 # seconds
end_time = 2 # seconds
sampling_rate = 6660 # Hz
N =(end_time - start_time)*sampling_rate # array size

# Nyquist Sampling Criteria
T = 1/sampling_rate # inverse of the sampling rate
x = np.linspace(0.0, 1.0/(2.0*T), int(N/2))

# FFT algorithm
yr = fft(X) # "raw" FFT with both + and - frequencies
y = 2/N * np.abs(yr[0:np.int(N/2)]) # positive freqs only

# Plotting the results
plt.plot(x, y)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Vibration (g)')

0 个答案:

没有答案