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()

05 使用python设计模拟滤波器(2)的图1iirfilter带通(等效)

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()

05 使用python设计模拟滤波器(2)的图2

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()

05 使用python设计模拟滤波器(2)的图3

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()

05 使用python设计模拟滤波器(2)的图4

对于,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()

05 使用python设计模拟滤波器(2)的图5

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]')

05 使用python设计模拟滤波器(2)的图6

对于,ftype='cheby1'; 'cheby2',以及低通,高通,带阻滤波器,读者可以自行尝试

登录后免费查看全文
立即登录
App下载
技术邻APP
工程师必备
  • 项目客服
  • 培训客服
  • 平台客服

TOP

1