import numpy as np
import matplotlib.pyplot as plt
# sampling rate
dt = 0.01 # 0.01초 간격
# rpm raw data
data1 = np.array([735, 743, 744, 739, 734, 752, 750, 745, 739, 751, 751, 745, 740, 757, 755, 749, 743, 745, 748, 742, 736, 748, 747, 741, 734, 751, 752, 747, 740, 737, 734, 730, 722, 731, 737, 732, 723, 738, 747, 743, 734, 747, 751, 749, 738, 750, 759, 755, 746, 752, 757, 753, 744, 747, 756, 753, 743, 749, 754, 752, 742, 743, 750, 747, 738, 740, 745, 745, 734, 737, 746, 746,734, 747, 754, 752, 741, 746, 753, 753, 741, 745, 752, 751, 741, 749, 759, 758, 746, 754,761, 760, 748, 753, 761, 761, 750, 751, 756, 757])
# FFT
fft_result1 = np.fft.fft(data1)
fft_magnitude1 = np.abs(fft_result1)
N = len(data1)
freq = np.fft.fftfreq(N, d=dt)
# plot
plt.figure(figsize=(10, 6))
plt.plot(freq, fft_magnitude1, label='Signal 1')
plt.title('FFT Result')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.xlim(4, 50)
plt.ylim(0, 500)
plt.xticks(np.arange(4, 51, 2))
plt.legend()
plt.grid(True)
plt.show()
这是汽车的转速信号,我想分析它的频率。我想将其转换为 FFT 并分析每个赫兹的信号强度。我想将y轴的单位表示为[n/rpm]。这可能吗?商业工具有这些选项,但如何应用它们呢?重采样 = 2048HZ,频谱大小 = 8192,窗函数 = Hanning,重叠 = 50%,幅度缩放 = 峰值。
x 轴的单位为 [HZ] / y 轴的单位为 [n/rpm]
计算 FFT 后,您并未缩放 FFT 的幅度。我做了这个例子作为您想要的结果的近似值,我还在信号上应用了汉明窗并在 FFT 之前去除了直流分量:
import numpy as np
%matplotlib notebook
import matplotlib.pyplot as plt
dt = 0.01 # sampling rate
data1 = np.array([735, 743, 744, 739, 734, 752, 750, 745, 739, 751, 751, 745,
740, 757, 755, 749, 743, 745, 748, 742, 736, 748, 747, 741,
734, 751, 752, 747, 740, 737, 734, 730, 722, 731, 737, 732,
723, 738, 747, 743, 734, 747, 751, 749, 738, 750, 759, 755,
746, 752, 757, 753, 744, 747, 756, 753, 743, 749, 754, 752,
742, 743, 750, 747, 738, 740, 745, 745, 734, 737, 746, 746,
734, 747, 754, 752, 741, 746, 753, 753, 741, 745, 752, 751,
741, 749, 759, 758, 746, 754, 761, 760, 748, 753, 761, 761,
750, 751, 756, 757]) # data
data1 = data1 - data1.mean() # removing the DC component
N = len(data1) # length of signal, this needs to be used for scaling the FFT
hammingWindow = np.hamming(N) # generate the hamming signal
data1 = data1 * hammingWindow # apply the hamming window
fft_result1 = np.fft.fft(data1) # get fft
fft_magnitude1 = np.abs(fft_result1)/N # calculate the magnitude and divide by N
freq = np.fft.fftfreq(N, d=dt) # get the frequency vector
halfMagnitude = 2*fft_magnitude1[:N//2] # get only half the magnitude, here you have the option of doubling as well
halfFrequencies = freq[:N//2] # get only half the frequencies
plt.figure(figsize=(10, 6)) # figsize
plt.plot(halfFrequencies, halfMagnitude, label='Signal 1') # plotting
plt.xlabel('Frequency (Hz)') # xlabel
plt.ylabel('Magnitude in original unit (in this case RPM)') # ylabel
plt.grid() # turn grid on
plt.xlim((16,40)) # xlim to reproduce your plot
plt.ylim((0,10)) # ylim to reproduce your plot
这与您想要的结果不是一对一的,但非常接近。我认为差异来自重叠或重采样: