0
$\begingroup$

I am getting confused from the implementation regarding matlab function filter([b0,b1,b2],[a1,a2],x) and other function similar as freqz. I do not understand which sign I must put in a coefficients, since there is two different way of writing the transfer function for the same second order filter as you see on the these pic below enter image description here

when for example the besself function generate the coefficients, does it generate them as I write them $H(z)$ or I must write $1-a_0z^{-1}-a_2z^{-2}$?

$\endgroup$

2 Answers 2

2
$\begingroup$

It looks like your source us using a pretty unusual convention. Most books or courses use the "+" sign in the denominator and that's the convention Matlab follows. See for example https://ccrma.stanford.edu/~jos/filters/Z_Transform_Difference_Equations.html

The reason for that is simple: This way zeros are roots of the numerator polynomial and the poles are the roots of the denominator polynomial.

$\endgroup$
3
$\begingroup$

The filter function assumes this form (for your case):

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

where the $1$ on the bottom is from the assumption that $a_0=1$, and call it $\tilde{H}(z)$ so not to be confused with your $H(z)$. Since you have written the denominator with the signs of $a_1$ and $a_2$ inverted, then you just have to fix that before using filter.

Suppose someone wrote the transfer function from your question down $\big(H(z)\big)$, handed you the coefficients, and said use MATLAB to find the output. The only thing you need to do before is to invert $a_1$ and $a_2$: filter(..., [a0, -a1, -a2], ...).

When using besself, it returns the coefficients in the form according to the transfer function $\tilde{H}(z)$, and you can then directly use those coefficients.

$\endgroup$
2
  • $\begingroup$ vWhen using besself, it returns the coefficients in the form according to the transfer function H~(z), and you can then directly use those coefficients. so you mean if I use freqz of the b,a provided by besself, I will get the bode of the transfer function. because I have seen that using bode(tf(b,a)) wontgive me same result $\endgroup$
    – Yaakov
    Commented May 6, 2020 at 20:45
  • 1
    $\begingroup$ @Yaakov freqz is for the z-domain, bode is for the s-domain. There is also freqs which is the s-domain version and should match whatever you get on your bode plot $\endgroup$
    – Engineer
    Commented May 6, 2020 at 20:55

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.