我正在尝试查找由100Hz PWM驱动器驱动的螺线管产生的电流信号中的频谱。信号以19200 Hz采样。
以下是信号图。该信号是较长时间序列数据的一部分。从22秒点中提取1024个数据点。
以下代码用于分析
import numpy as np
import matplotlib.pyplot as plt
plt.figure(1)
plt.plot(t,y)
Fs=19200 # (Hz) sampling rate
N=len(y) # length of signal
time=N/Fs #total time of signal, 1/time is the fundamantal frequency
freq=np.arange(N)/time # frequency vector for fft spectrum plot
freq=freq[0:int(N/2)] # one sided frequecy
Y=np.fft.fft(y)/N*2 # fft of signal
Y=Y[0:int(N/2)] # one sided frequency
plt.figure(2)
plt.plot(freq,abs(Y)) # one sided frequency plot
plt.xlabel("Hz")
plt.ylabel("Units")
plt.title("FFT spectrum")
plt.grid()
plt.show()
人们会期望频谱中占主导地位的100 Hz分量,但是numpy fft结果不能反映这一点。以下是numpy.fft
频率图。
以下是对相似信号进行Matlab fft分析的图表。正如预期的那样,有一个占主导地位的100Hz分量,它谐波。
答案 0 :(得分:0)
我建议您对已经知道分析结果的函数执行离散傅立叶变换。对看到的内容满意后,就可以对不知道结果的东西运行一些代码行,就像我在本讨论中已经做过的那样
Numerical Fourier Transform of rectangular function
如您所见,在Matlab和Python中,频谱的右侧(fftshift(y))都必须在数值傅立叶变换之前和之后执行。
您可能还对所谓的Nyquist定理感兴趣,该定理规定了可以应用数值傅立叶变换的最小采样频率,但是我不认为这是您的问题,因为您的频谱看起来很高。
顺便说一下,下面将介绍使用python对步进函数执行快速傅立叶变换的正确方法
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-3, 3, 0.01)
y = np.zeros(len(x))
y[200:400] = 1
# Step function for which the Fourier Transform is well known to be sin(x)/x
yShift = np.fft.fftshift(y)
# Shift of the N/2 sampling data on the right side to the left side
fftyShift = np.fft.fft(yShift)
# Numerical Fourier Transform (Lanczos)
ffty = np.fft.fftshift(fftyShift)
# Shift of the N/2 transformed data on the right side to the left side
plt.plot(ffty)
plt.show()