I want to implement Butterworth low-pass filter. Thanks to this question, I have found out that the filter coefficients can be generated using Tony Fisher web-site or using his code. But the problem arose when I had tried to verify his formulas myself.
Wikipedia says that the derivation of low-pass formulas is simple: we start with the Butterworth polynomial of order n
. I took n=1
B1(sωcutoff)=1+sωcutoff
(note that ωcutoff is angular frequency, not usual one) then do bilinear transform s=2fsampling⋅z−1z+1
(fsampling is usual frequency, not angular) and rewrite the resulting fraction in the form with non-positive powers of z.
To make the story short, my final formula for transfer function is H(z)=Y(z)X(z) where Y(z)=a1+a+a1+az−1 X(z)=1−1−a1+az−1 and a=ωcutoff2fsampling and the resulting formula is y[n]=a1+ax[n]+a1+ax[n−1]+1−a1+ay[n−1] For testing I use fcutoff=1 (which is ωcutoff=2π) and fsampling=30.
We should not worry about coefficients in front of x[] since Fisher multiplies them by gain factor anyway, but the coefficient in front of y[n−1] equals
1−a1+a=0.8104139027
while Fisher's web-page for fcutoff=1 and fsampling=30 gives 0.8097840332.
If you had a patience to finish this reading, may be you can explain, where I (or Fisher?) am wrong.
Answer
The problem is in the way you apply the bilinear transform. You have to use the appropriate (pre-)warping of the frequencies. Since the bilinear transform warps the frequency axis, you have to make sure that the corner frequency of the discrete-time filter is correct. One way to do that is as follows. The bilinear transform is defined as
s=kz−1z+1
with some constant k yet to be defined. If we denote the analog frequency by Ω, and the normalized discrete-time frequency by ω, Eq. (1) becomes for s=jΩ and z=ejω
jΩ=kejω−1ejω+1=kejω/2−e−jω/2ejω/2+e−jω/2=jktan(ω/2)
Eq. (2) describes the frequency warping caused by the bilinear transform. If we use an analog lowpass filter with a normalized corner frequency Ω0=1, we must choose the constant k such that for the desired discrete-time corner frequency ω0 the term on the right-hand side of Eq. (2) becomes 1:
k=1tan(ω0/2)
where ω0 is the desired corner frequency of the digital filter. Eq. (3) and Eq. (1) define the appropriately normalized bilinear transform that you must use.
So for your example, the normalized first-order analog Butterworth lowpass transfer function is given by
H(s)=11+s
Applying the bilinear transform gives
H(z)=11+kz−1z+1=z+1z(1+k)+1−k=11+k⋅1+z−11+1−k1+kz−1
Ignoring the gain term 1/(1+k), the corresponding difference equation is
y[n]=x[n]+x[n−1]−1−k1+ky[n−1]
With a desired corner frequency ω0=2π/30 you get from (3) k=9.5144 and (1−k)/(1+k)=−0.80978, just like on Fisher's website.
No comments:
Post a Comment