Python 无法将scipy.signal.filt.filt示例扩展到高通滤波器

Python 无法将scipy.signal.filt.filt示例扩展到高通滤波器,python,signals,filtering,Python,Signals,Filtering,我正在尝试使用scipy.signal.filt.filt在python中实现高通过滤器。但是,我试图修改文档()中给出的示例的尝试没有成功 定义信号: t = np.linspace(0.0, 1.0, 2001) xlow = np.sin(10.0 * t) xhigh = 10.0*np.sin(50. * t) x = xlow + xhigh 定义截止频率为20 rad/s的滤波器(以去除x的低频分量),并绘制其频率响应图: b, a = signal.iirfilter(17,

我正在尝试使用scipy.signal.filt.filt在python中实现高通过滤器。但是,我试图修改文档()中给出的示例的尝试没有成功

定义信号:

t = np.linspace(0.0, 1.0, 2001)
xlow = np.sin(10.0 * t)
xhigh = 10.0*np.sin(50. * t)
x = xlow + xhigh
定义截止频率为20 rad/s的滤波器(以去除x的低频分量),并绘制其频率响应图:

b, a = signal.iirfilter(17, 20, btype='highpass', analog=True, ftype='butter')
w, h = signal.freqs(b, a)
plt.plot(w, 20.0 * np.log10(abs(h)))
plt.xscale('log')
plt.title('Butterworth filter frequency response')
plt.xlabel('Frequency [radians / second]')
plt.ylabel('Amplitude [dB]')
plt.margins(0, 0.1)
plt.grid(which='both', axis='both')
plt.show()
plt.close()
图中显示,截止速度约为预期的20 rad/s

应用滤波器并根据原始信号绘制滤波信号:

y = signal.filtfilt(b, a, x, padtype='even', padlen=150)
fig = plt.figure(figsize = [10,10])
ax = fig.add_subplot(1,1,1)
ax.plot(t,x, 'b-', label='Original')
ax.plot(t,y.real, 'rs', label='Filtered')
ax.legend()
plt.xlabel("time (s)")
plt.ylabel("Signal")
plt.show()
plt.close()
不会返回任何错误消息,但对于所有值,过滤后的信号y为nan+nanj

有人能看出我哪里做错了吗


谢谢

请定义“未成功”。你有错误吗?你的结果是否与你的期望不符?你应该提供更多关于错误的信息。嗨@sobek,我已经添加了更多细节。你确定你的IIR过滤器是稳定的吗?