05 使用python設計模擬濾波器(2)
01 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




















