%% Limitations
% Numerical Instability of Transfer Function Syntax
%
% In general, use the [z,p,k] syntax to design IIR filters. To analyze or implement your filter, you can then use the [z,p,k] output with zp2sos. If you design the filter using the [b,a] syntax, you might encounter numerical problems. These problems are due to round-off errors and can occur for n as low as 4. The following example illustrates this limitation.

n = 6; 
Rp = 0.1;
Wn = [2.5e6 29e6]/500e6;
ftype = 'bandpass';

% Transfer function design
[b,a] = cheby1(n,Rp,Wn,ftype);      % This filter is unstable

% Zero-pole-gain design
[z,p,k] = cheby1(n,Rp,Wn,ftype);
sos = zp2sos(z,p,k);

% Plot and compare the results
hfvt = fvtool(b,a,sos,'FrequencyScale','log');
legend(hfvt,'TF Design','ZPK Design')

% Copyright 2015 The MathWorks, Inc.