I have a question about the analog and digital versions of the Butterworth filter in SciPy. I tried two things to get a digital Butterworth filter:
- Getting an analog filter by
scipy.signal.butter
withanalog=True
, and then usingscipy.signal.bilinear
to transform it into a digital filter. - Directly getting from the function
scipy.signal.butter
withanalog=False
.
I got different results from the two methods. Should I expect same result from these two approaches? My code:
from scipy import signal
b1, a1 = signal.butter(1, 1, 'high', analog=True)
print("analog filter: ", [b1, a1])
fs = 100
b2, a2 = signal.bilinear(b1, a1, fs)
print("digital filter from bilinear transformation of analog filter: ", [b2, a2])
b, a = signal.butter(1, 1*2/fs, 'high', analog=False)
print("digital filter: ", [b, a])
Output:
analog filter: [array([1., 0.]), array([1., 1.])]
digital filter from bilinear transformation of analog filter: [array([ 0.99502488, -0.99502488]), array([ 1. , -0.99004975])]
digital filter: [array([ 0.96953125, -0.96953125]), array([ 1. , -0.93906251])]
I just get the answer to this question by reading some materials about digital filters a note about digital filter
The bilinear transformation between analogue filter and digital filter gives us a non-linear relationship between the analogue frequency and digital frequency as introduced in the material.
Thus, if a digital filter is needed, directly design it from
scipy.signal.butter
is better.