1 %% Copyright (C) 2005 Julius O. Smith III <jos@ccrma.stanford.edu>
3 %% This program is free software; you can redistribute it and/or modify it under
4 %% the terms of the GNU General Public License as published by the Free Software
5 %% Foundation; either version 3 of the License, or (at your option) any later
8 %% This program is distributed in the hope that it will be useful, but WITHOUT
9 %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 %% You should have received a copy of the GNU General Public License along with
14 %% this program; if not, see <http://www.gnu.org/licenses/>.
17 %% @deftypefn {Function File} {[@var{sos}, @var{g}] =} tf2sos (@var{B}, @var{A})
18 %% Convert direct-form filter coefficients to series second-order sections.
21 %% @var{B} and @var{A} are vectors specifying the digital filter @math{H(z) = B(z)/A(z)}.
22 %% See @code{filter()} for documentation of the @var{B} and @var{A}
23 %% filter coefficients.
26 %% @var{sos} = matrix of series second-order sections, one per row:@*
27 %% @var{sos} = [@var{B1}.' @var{A1}.'; ...; @var{BN}.' @var{AN}.'], where@*
28 %% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for
30 %% b0 must be nonzero for each section (zeros at infinity not supported).
31 %% @var{Bscale} is an overall gain factor that effectively scales
32 %% any one of the @var{B}i vectors.
38 %% [sos,g] = tf2sos(B,A)
42 %% 1.00000 0.61803 1.00000 1.00000 0.60515 0.95873
43 %% 1.00000 -1.61803 1.00000 1.00000 -1.58430 0.95873
44 %% 1.00000 1.00000 -0.00000 1.00000 0.97915 -0.00000
50 %% @seealso{sos2tf zp2sos sos2pz zp2tf tf2zp}
53 function [sos,g] = tf2sos (B, A)
55 [z,p,g] = tf2zp(B(:)',A(:)');
61 %! B=[1 0 0 0 0 1]; A=[1 0 0 0 0 .9];
62 %! [sos,g] = tf2sos(B,A);
63 %! [Bh,Ah] = sos2tf(sos,g);
64 %! assert({Bh,Ah},{B,A},100*eps);