04 使用python设计模拟滤波器

01 butterworth filter

低通滤波器:在60rad/s处衰减3dB,在80rad/s处衰减40dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.buttord(60, 80, 3, 40, analog=True) #
b, a = sig.butter(N, Wn, 'lowpass', 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]')

04 使用python设计模拟滤波器的图1

高通滤波器:在55rad/s处衰减3dB,在45rad/s处衰减40dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.buttord(55, 45, 3, 40, analog=True) #
b, a = sig.butter(N, Wn, 'highpass', 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]')

04 使用python设计模拟滤波器的图2

带通滤波器:在20-50rad/s内衰减3dB,在14rad/s以下和60rad/s以上衰减40dB;

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

04 使用python设计模拟滤波器的图3

带阻滤波器:在20-70rad/s内衰减30dB,在10rad/s以下和80rad/s以上衰减3dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.buttord([10,80], [20,70], 3, 30, analog=True) #
b, a = sig.butter(N, Wn, 'bandstop', 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]')

04 使用python设计模拟滤波器的图4

02 chebyshev filter (type one)

低通滤波器:在60rad/s处衰减3dB,在80rad/s处衰减40dB,波动3dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb1ord(60, 80, 3, 40, analog=True)
b, a = sig.cheby1(N,3, Wn, 'lowpass', 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]')

04 使用python设计模拟滤波器的图5

高通滤波器:在55rad/s处衰减3dB,在45rad/s处衰减40dB,波动3dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb1ord(55, 45, 3, 40, analog=True)
b, a = sig.cheby1(N, 3,Wn, 'highpass', 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]')
04 使用python设计模拟滤波器的图6

带通滤波器:在20-50rad/s内衰减3dB,在14rad/s以下和60rad/s以上衰减40dB,波动3dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb1ord([20, 50], [14, 60], 3, 40, analog=True)
b, a = sig.cheby1(N,3,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]')

04 使用python设计模拟滤波器的图7

带阻滤波器:在20-70rad/s内衰减30dB,在15rad/s以下和75rad/s以上衰减3dB,波动3dB;

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb1ord([15,75], [20,70], 3, 30, analog=True)
b, a = sig.cheby1(N,3,Wn, 'bandstop', 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]')

04 使用python设计模拟滤波器的图8

03 chebyshev filter (type two)

低通滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb2ord(60, 80, 3, 40, analog=True)
b, a = sig.cheby2(N,40, Wn, 'lowpass', 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()

04 使用python设计模拟滤波器的图9

高通滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb2ord(55, 45, 3, 40, analog=True)
b, a = sig.cheby2(N,40,Wn, 'highpass', 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()

04 使用python设计模拟滤波器的图10

带通滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb2ord([20, 50], [14, 60], 3, 40, analog=True)
b, a = sig.cheby2(N,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()

04 使用python设计模拟滤波器的图11

带阻滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.cheb2ord([15,75], [20,70], 3, 30, analog=True)
b, a = sig.cheby2(N,30,Wn, 'bandstop', 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()

04 使用python设计模拟滤波器的图12

04 ellipse filter

低通滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.ellipord(60, 80, 3, 40, analog=True)
b, a = sig.ellip(N,3,40, Wn, 'lowpass', 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()

04 使用python设计模拟滤波器的图13

高通滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.ellipord(55, 45, 3, 40, analog=True)
b, a = sig.ellip(N,3,40,Wn, 'highpass', 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()

04 使用python设计模拟滤波器的图14

带通滤波器

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

04 使用python设计模拟滤波器的图15

带阻滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
N, Wn = sig.ellipord([15,75], [20,70], 3, 30, analog=True)
b, a = sig.ellip(N,3,30,Wn, 'bandstop', 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()

04 使用python设计模拟滤波器的图16

05 以上函数也可以设计数字滤波器,将analog=false,查看频响用freqz,即可;

另外,数字滤波器还有两个特别类型:陷波滤波器(点阻),共振滤波器(点通)

陷波滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
b,a=sig.iirnotch(60,30,512)
w,h=sig.freqz(b,a,fs=512)
plt.plot(w,20*np.log10(abs(h)))
plt.xlabel('Hz')
plt.ylabel('dB')
plt.grid()

04 使用python设计模拟滤波器的图17

共振滤波器

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
b,a=sig.iirpeak(100,30,512)
w,h=sig.freqz(b,a,fs=512)
plt.plot(w,20*np.log10(abs(h)))
plt.xlabel('Hz')
plt.ylabel('dB')
plt.grid()

04 使用python设计模拟滤波器的图18

(3条)
默认 最新
学习
评论 点赞 1
学习到了
评论 点赞

查看更多评论 >

点赞 3 评论 4 收藏
关注