Monday 21 July 2014

Doing the Bilinear Transform for a 2nd order filter

Googling you can find this explained in lots of different places to varying degrees of completeness. I wanted to step this though in small detail mainly as a practice in using the MathJax notation for myself before getting onto some of the other more interesting bits.

This post will not go into any of the explanation, I'll leave that for another (possibly more useful) one.

Firstly, let's define the Laplacian s-plane (analog) transfer function that we're looking to design (a resonant low-pass filter):

$$H(s) = \frac {1}{s^2 + \frac {s}{Q} + 1}$$

We then need to use the bilinear transformation with frequency warping:

$$ s \leftarrow \frac {1}{tan \frac {\omega}{2}} \frac {1-z^{-1}}{1+z^{-1}} $$
Substituting this into the transfer function:

$$ H(z) = \frac {1}{ \frac {1}{tan^2 \frac {\omega}{2}} \frac {(1-z^{-1})^2}{(1+z^{-1})^2} + \frac {1}{Q tan \frac {\omega}{2}} \frac {1-z^{-1}}{1+z^{-1}} + 1} $$

This can be simplified by brining \( tan^2 \frac {\omega}{2} (1+z^{-1})^2\) to the top by multiplying top and bottom by the same amount giving:

$$ H(z) = \frac { tan^2 \frac {\omega}{2} (1+z^{-1})^2}{(1+z^{-1})^2 + \frac {1}{Q} tan \frac {\omega}{2} (1-z^{-1})(1+z^{-1})+tan^2 \frac {\omega}{2}(1+z^{-1})^2} $$

We can now make the following simplifications:
  • expand \({(1-z^{-1})^2} = (1-2z^{-1}+z^{-2})\) on the top and bottom
  • use the trig identity \(tan^2 \frac {\omega}{2} = \frac {(1-cos \omega)}{(1+cos \omega)}\)
  • simplify \( (1-z^{-1})(1+z^{-1}) = (1-z^{-2})\)

$$ H(z) = \frac {(1-cos \omega)(1-2z^{-1}+z^{-2})}{(1+cos \omega) (1-2z^{-1}+z^{-2})+ \frac {(1+cos \omega)}{Q} tan \frac {\omega}{2} (1-z^{-2}) + (1+cos \omega) tan^2 \frac {\omega}{2} (1-2z^{-1}+z^{-2})} $$

Collecting together the terms for \(z^{-2}\),\(z^{-1}\),1 terms to coefficients \(a_2\),\(a_1\),\(a_0\) on the bottom and \(b_2\),\(b_1\),\(b_0\) on the top:

  • \( b_2 = (1-cos \omega)\)
  • \( b_1 = -2(1-cos \omega)\)
  • \( b_0 = (1-cos \omega)\)
  • \( a_2 = (1+cos \omega) - \frac {(1+cos \omega)}{Q} tan \frac {\omega}{2} + (1+cos \omega)tan^2 \frac {\omega}{2}\) 
  • \( a_1 = -2(1+ cos \omega) + 2(1+cos \omega) tan^2 \frac {\omega}{2}\)
  • \( a_0 = (1+cos \omega) + \frac {(1+cos \omega)}{Q} tan \frac {\omega}{2} + (1+cos \omega)tan^2 \frac {\omega}{2}\) 

\( a_0 \) can then be simplified by the following two steps:

  • using the trig identity \(tan \frac {\omega}{2} = \frac {sin \omega}{1+cos \omega}\)
  • using the trig identity \(tan^2 \frac {\omega}{2} = \frac {(1-cos \omega)}{(1+cos \omega)}\) again

$$ a_0 = (1+cos \omega) + \frac {(1+cos \omega)}{Q} \frac {sin \omega}{1+cos \omega} + (1+cos \omega) \frac {1-cos \omega}{1+cos \omega} $$

tidying up:

$$ a_0 = (1+cos \omega) + \frac {sin \omega}{Q} + (1+cos \omega) = 2 + \frac {sin \omega}{Q} = 2 (1+ \alpha) $$
where \( \alpha = \frac {sin \omega}{2Q} \)

and similarly using the same simplifications for \( a_2 \) gives \( a_2 = 2(1- \alpha) \)

Lastly for \( a_1 \) using the trig identity for \(tan^2 \frac {\omega}{2} \) one last time:

$$ a_1 = -2(1+cos \omega) + 2(1+cos \omega) \frac {(1-cos \omega)}{(1+cos \omega)} = -2 (1+cos \omega) + 2(1-cos \omega) = 2(-2cos \omega) $$

Lining up all of the coefficients and collecting the common factors:

$$ H(z) = \frac {(1-cos \omega)}{2} \frac {b_2z^{-2}+b_1z^{-1}+b_0}{a_2z^{-2}+a_1z^{-1}+a_0} $$

  • \(b_2 = 1\)
  • \(b_1 = -2\)
  • \(b_0 = 1\)
  • \(a_2 = 1 + \alpha\)
  • \(a_1 = -2 cos \omega\)
  • \(a_0 = 1 - \alpha\)

With the \(b_n\) values multiplied by \(\frac {(1-cos \omega)}{2}\). Which can then be normalised to set \(a_0=1\) if required.

Which gives us the same coefficients in the RBJ functions for a low-pass filter.




No comments:

Post a Comment