带阻Butterworth过滤器

我正在尝试使用python中的scipy库创建一个Bandstop Butterworth滤波器,您能告诉我我做错了吗? fc1是1750,fc2是4100,fs是30000,ft是150,我已经定义了它们。我的错误:ValueError:Wn必须为带通或带阻滤波器指定起始和终止频率。这是我到目前为止所拥有的代码:

fs = 33000 
r = 55
ft = 150
rp = 0.3
rs = 55
order = 3
a=1
fc1 = 1750
fc2 = 4100
fc=np.union1d(np.array([1,1750]),([4100,10000]))
wp = (fc1-ft/2) *2/fs

ws = (fc2 + ft/2) *2/fs

N, wn = sp.buttord(wp, ws, rp, rs)

b, a = sp.butter(N, wn , btype = "bandstop")

w,h = sp.freqz(b, a,  worN=512, plot=None)

f=(fs/2)*w/(np.pi)

plt.figure()

plt.plot(f,abs(h))
评论
上集回顾
上集回顾

Please, consider improving your question, since fc and its friends could be whatever and therefore it is not clear what are you trying to achieve.
From the point of syntax and signal processing, one needs to define a bandpass/bandstop filter you should specify 4 points, because the filter has bell-like shape. Please, refer to buttord parameters:

wp, ws : float
bandstop: wp = [0.1, 0.6], ws = [0.2, 0.5]

so wp and ws should have shape of (2,).
To make the syntax in your example correct, change

wp = (fc1-ft/2) *2/fs
ws = (fc2 + ft/2) *2/fs

wp = [(fc1-ft/2) *2/fs, (fc2 + ft) *2/fs]
ws = [(fc1+ft) *2/fs, (fc2 + ft/2) *2/fs]

The frequencies, of course, are chosen arbitrarily, but keep in mind that it must be wp_low < ws_low < ws_high < wp_high so pass range includes stop range entirely.

点赞
评论