I want to implement an algorithm for a second order butterworth filter on the form $ H(s) = \dfrac{Y(s)}{U(s)}= \dfrac{1}{\left(\frac{s}{w_0}\right)^2+2\zeta\frac{s}{w_0}+1} $ I want to get it on the difference equation form $ y_k = f(y_{k-1},u_k,u_{k-1},T_s) $ where $T_s$ is the sampling time of the controller. What I first was thinking was to find the Z-transformation of H(s) first (with a zero order hold (ZOH). So the transformation will be $ \left.\dfrac{Y(z)}{U(z)}= \dfrac{z-1}{z}\cdot \mathcal{Z}\left( \dfrac{H(s)}{s} \right) \right \vert_{t=T_s} $

But this got pretty overcomplicated from what i rememeber. It has sadly been a lot of years since I did any discrete analysis and filter design.

I guess this is necessary if I want to model the system and do some stability analysis on it etc. But since I dont really care about the complete system, but only want to make an algorithm for a digital filter with a predefined cutoff frequency. And the algorithm itself implements the zero order hold by updating the values and holding them at a defined sample rate, I started to believe that the solution to my problem was simpler.

Is it correct that I can just take this substitution directly: $ H(z) = \left. \dfrac{Y(z)}{U(z)}\approx \dfrac{1}{\left(\frac{s}{w_0}\right)^2+2\zeta\frac{s}{w_0}+1} \right|_{s \approx \dfrac{z-1}{T_s}} $

And then do the substitutions $z^2\cdot Y(z) = y_{k+2},\hspace{2mm}z\cdot Y(z) = y_{k+1}$ etc. and get my algorithm from this difference equation?

I hope I'm getting my problem accross somewhat decently. If you have som good beginner/reference litterature on Z-transforms, difference equation and discrete control please drop them in a comment.

Thank you for your feedback.

  • $\begingroup$ And there's also the Cookbook. Set Q to 0.7071... $\endgroup$ Commented Apr 29 at 16:26

1 Answer 1


Matlab, Octave, Python, etc. all have build in functions to design Butterworth filters, so you can just use that.

If you want to do it manually, you can use the following process.

  1. Design the prototype filter in the s-plane: the poles are equidistant on the left side the unit circle. For 2nd order you simply end up with a complex pole pair at $p = (-1 \pm j)/\sqrt{2}$
  2. Determine the sample time that warps the cutoff frequency to the desired cutoff frequency as $T = 2 \tan (\pi \frac{f_c}{f_s})$, where $f_c$ is your desired cutoff frequency and $f_s$ your sample rate
  3. Apply bilinear transform with the sample time determined in step 3 (NOT your actual sample rate). This will give you the discrete poles
  4. Add the same number of zeros at $z=1$ or $z=-1$ depending on whether you want a high pass or lowpass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.