如何得到链式IIR滤波器的b,a(分子/分母)?

2024-09-28 21:23:46 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我们一个接一个地应用了3个过滤器:

b, a = iirfilter(...)  # or bilinear(...) or anything else producing b, a
y = lfilter(b, a, x)
b, a = iirfilter(...) 
y = lfilter(b, a, y)
b, a = iirfilter(...) 
y = lfilter(b, a, y)

如何得到与3个滤波器等价的系数b2a2,这样我们只需一次lfilter就可以得到结果:

^{pr2}$


编辑:卷积似乎不起作用:

fs = 44100
b2, a2 = iirfilter(2, 2.0/fs * np.asarray([40, 60]), btype='bandstop')  # 50 hz reject
b3, a3 = iirfilter(2, 2.0/fs * np.asarray([85, 115]), btype='bandstop')  # 100 hz reject
b = np.convolve(b2, b3)
a = np.convolve(a2, a3)
w, h = signal.freqz(b, a, worN=10000)

给出:

enter image description here

我尝试使用samefullvalid参数np.卷积但他们都没能解决问题。在


Tags: ora2npfsb2卷积a3b3
1条回答
网友
1楼 · 发布于 2024-09-28 21:23:46

https://dsp.stackexchange.com/questions/38675/how-to-plot-magnitude-and-phase-response-of-2-cascaded-filters-in-matlab

你可以把分子和分母分开卷积

import scipy as sp
import scipy.signal as sig

# Individual filters
b1, a1 = sig.iirfilter(...)
b2, a2 = sig.iirfilter(...)

# Cascaded filter
a = sp.convolve(a1, a2)
b = sp.convolve(b1, b2)
y = sig.lfilter(b, a, x)

例如,您的采样率太高,并且复合滤波器的阶数不够长,无法对接近的空值给出那个么多的拒绝。降低采样率,然后向上插值44.1 kHz。在

以下是采样率降至4410赫兹的结果。在

^{pr2}$

enter image description here

然后将IIR滤波器的输出通过10x插值滤波器,使采样率恢复到44.1khz。在

或者,减少过滤顺序:

fs = 44100.0
b2, a2 = sig.iirfilter(1, 2.0/fs * sp.asarray([40, 60]), btype='bandstop')  # 50 hz reject
w2, h2 = sig.freqz(b2, a2, worN=4096)

b3, a3 = sig.iirfilter(1, 2.0/fs * sp.asarray([85, 115]), btype='bandstop')  # 100 hz reject
w3, h3 = sig.freqz(b3, a3, worN=4096)

b = sp.convolve(b2, b3, 'full')
a = sp.convolve(a2, a3, 'full')
w, h = sig.freqz(b, a, worN=4096)

以44.1 kHz的原始采样率产生

enter image description here

相关问题 更多 >