Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Matlab Example

The following matlab example expands the filter

$\displaystyle H(z) = \frac{B(z)}{A(z)} = \frac{1+z^{-5}}{1+0.9z^{-5}}
$

into a series of second order sections:
B=[1 0 0 0 0 1];
A=[1 0 0 0 0 .9];
[sos,g] = tf2sos(B,A)
sos =
   1.00000   0.61803   1.00000   1.00000   0.60515   0.95873
   1.00000  -1.61803   1.00000   1.00000  -1.58430   0.95873
   1.00000   1.00000  -0.00000   1.00000   0.97915  -0.00000

g = 1
The g parameter is an input (or output) scale factor; for this filter, it was not needed. Thus, in this example we obtained the following filter factorization:

\begin{eqnarray*}
H(z) &\isdef & \frac{1+z^{-5}}{1+0.9z^{-5}}\\
&=&\left(\frac{1 + 0.61803z^{-1}+ z^{-2}}{1 + 0.60515z^{-1}+ 0.95873z^{-2}}\right)
\left(\frac{1 - 1.61803z^{-1}+ z^{-2}}{1 - 1.58430z^{-1}+ 0.95873z^{-2}}\right)\\
&& \left(\frac{1 + z^{-1}}{1 + 0.97915z^{-1}}\right)
\end{eqnarray*}

Note that the first two sections are second-order, while the third is first-order (when coefficients are rounded to five digits of precision after the decimal point).

In addition to tf2sos, tf2zp, and zp2sos discussed above, there are also functions sos2zp and sos2tf, which do the obvious conversion in both Matlab and Octave.10.6 The sos2tf function can be used to check that the second-order factorization is accurate:

% Numerically challenging "clustered roots" example:
[B,A] = zp2tf(ones(10,1),0.9*ones(10,1),1); 
[sos,g] = tf2sos(B,A);
[Bh,Ah] = sos2tf(sos,g);
format long;
disp(sprintf('Relative L2 numerator error: %g',...
	norm(Bh-B)/norm(B)));
% Relative L2 numerator error: 1.26558e-15
disp(sprintf('Relative L2 denominator error: %g',...
	norm(Ah-A)/norm(A)));
% Relative L2 denominator error: 1.65594e-15
Thus, in this test, the original direct-form filter is compared with one created from the second-order sections. Such checking should be done for high-order filters, or filters having many poles and/or zeros close together, because the polynomial factorization used to find the poles and zeros can fail numerically. Moreover, the stability of the factors should be checked individually.


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]

``Introduction to Digital Filters with Audio Applications'', by Julius O. Smith III, (September 2007 Edition)
Copyright © 2023-09-17 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA