05 使用python设计模拟滤波器(2)
更新于2019年7月24日 18:3101 iirfilter的使用
butter带通
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.buttord([20, 50], [14, 60], 3, 40, analog=True)
b, a = sig.butter(N, Wn, 'bandpass', analog=True)
w, h = sig.freqs(b, a, np.logspace(1, 2, 500))
plt.plot(w, 20 * np.log10(abs(h)))
plt.xlabel('angular fre [rad/s]')
plt.ylabel('response [dB]')
plt.grid()
iirfilter带通(等效)
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.buttord([20, 50], [14, 60], 3, 40, analog=True)
b,a=sig.iirfilter(N,Wn,btype='bandpass',ftype='butter',analog=True)
w, h = sig.freqs(b, a, np.logspace(1, 2, 500))
plt.plot(w, 20 * np.log10(abs(h)),c='red')
plt.xlabel('angular fre [rad/s]')
plt.ylabel('response [dB]')
plt.grid()

ellip带通
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.ellipord([20, 50], [14, 60], 3, 40, analog=True)
b, a = sig.ellip(N,3,40,Wn, 'bandpass', analog=True)
w, h = sig.freqs(b, a, np.logspace(1, 2, 500))
plt.plot(w, 20 * np.log10(abs(h)))
plt.xlabel('angular fre [rad/s]')
plt.ylabel('response [dB]')
plt.grid()

iirfilter带通(等效)
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.ellipord([20, 50], [14, 60], 3, 40, analog=True)
b,a=sig.iirfilter(N,Wn,rp=3,rs=40,btype='bandpass',ftype='ellip',analog=True)
w, h = sig.freqs(b, a, np.logspace(1, 2, 500))
plt.plot(w, 20 * np.log10(abs(h)),c='red')
plt.xlabel('angular fre [rad/s]')
plt.ylabel('response [dB]')
plt.grid()

对于,ftype='cheby1'; 'cheby2',以及低通,高通,带阻滤波器,读者可以自行尝试
02 iirdesign的使用
iirdesign带通(等效butter)
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
b,a = sig.iirdesign([20, 50], [14, 60], 3, 40, ftype='butter',analog=True)
w, h = sig.freqs(b, a, np.logspace(1, 2, 500))
plt.plot(w, 20 * np.log10(abs(h)),c='red')
plt.xlabel('angular fre [rad/s]')
plt.ylabel('response [dB]')
plt.grid()

iirdesign带通(等效ellip)
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
b,a= sig.iirdesign([20, 50], [14, 60], 3, 40, ftype='ellip',analog=True)
w, h = sig.freqs(b, a, np.logspace(1, 2, 500))
plt.plot(w, 20 * np.log10(abs(h)),c='red')
plt.xlabel('angular fre [rad/s]')
plt.ylabel('response [dB]')

对于,ftype='cheby1'; 'cheby2',以及低通,高通,带阻滤波器,读者可以自行尝试
工程师必备
- 项目客服
- 培训客服
- 平台客服
TOP




















