I am trying to use the designfilt tools in MATLAB to create a bandpass filter, but to be compatible with other code I need the resultant filter in transfer function coefficient form with B and A. To start with I took an example from the filter design gallery, and just changed the sampling rate to match that of my real data.

Fstop1 = 150;
Fpass1 = 200;
Fpass2 = 300;
Fstop2 = 350;
Astop1 = 65;
Apass  = 0.5;
Astop2 = 65;
% Fs=1000;

d = designfilt('bandpassiir', ...
  'StopbandFrequency1',Fstop1,'PassbandFrequency1', Fpass1, ...
  'PassbandFrequency2',Fpass2,'StopbandFrequency2', Fstop2, ...
  'StopbandAttenuation1',Astop1,'PassbandRipple', Apass, ...
  'StopbandAttenuation2',Astop2, ...
  'DesignMethod','butter','SampleRate', Fs);

This filter seems to be behaving itself, isstable returns 1 and the $z$-plane seems acceptable:

z plane from d.tf output

However, when I try to get the coefficients using [B,A]=d.tf; the resultant filter is no longer stable and the $z$-plane looks totally different:

z plane from d.tf output

The values for B are incredibly small around e-26, so I am imaging that it might be to do with gains of the coefficients? If I set Fs back to the original $1\textrm{kHz}$, this two $z$-planes plots are the same.

Can someone help me with sorting this problem? Is the fact that the transfer function form is unstable speak to the stability of the filter when it is in the digitalfilter object form?


The documentation for the butter function even describes these errors here


Generally you should never use the Transfer Function syntax. Look how your poles are closely placed next to the unit circle. With high order Butterworth filters you will see the effect of round-off numerical errors. What is the high order? Well 5 is already high and your filter has 30.

Instead you should use SOS or Zero-Pole-Gain representation. For example try to visualise the same filter but with SOS matrix:

fvtool(d.Coefficients) % or: zplane(sos2zp(d.Coefficients))

You will see that there are no visible numerical errors.

  • $\begingroup$ Thanks very much, I guess its worth switching the other code to the other representations then! Its interesting that such differences can occur just by how you store the filter. Would they be exactly the same given enough precision in storing the coefficients? $\endgroup$
    – Jimbles
    Jul 19 '16 at 10:09
  • $\begingroup$ Given ridiculously good precision - yes, there would be a match. $\endgroup$
    – jojek
    Jul 19 '16 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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