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{z}, @var{p}, @var{g}] =} sos2zp (@var{sos}, @var{Bscale})
18 %% Convert series second-order sections to zeros, poles, and gains
25 %% @var{sos} = matrix of series second-order sections, one per row:@*
26 %% @var{sos} = [@var{B1}.' @var{A1}.'; ...; @var{BN}.' @var{AN}.'], where@*
27 %% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for
29 %% b0 must be nonzero for each section.
30 %% See @code{filter()} for documentation of the
31 %% second-order direct-form filter coefficients @var{B}i and @var{A}i.
34 %% @var{Bscale} is an overall gain factor that effectively scales
35 %% any one of the input @var{B}i vectors.
41 %% @var{z} = column-vector containing all zeros (roots of B(z))@*
43 %% @var{p} = column-vector containing all poles (roots of A(z))@*
45 %% @var{g} = overall gain = @var{B}(Inf)
50 %% [z,p,g] = sos2zp([1 0 1, 1 0 -0.81; 1 0 0, 1 0 0.49])
51 %% => z = [i; -i; 0; 0], p = [0.9, -0.9, 0.7i, -0.7i], g=1
54 %% @seealso{zp2sos sos2tf tf2sos zp2tf tf2zp}
57 function [z,p,g] = sos2zp (sos, Bscale = 1)
59 if (nargin < 1 || nargin > 2)
63 gains = sos(:,1); % All b0 coeffs
64 g = prod(gains)*Bscale; % pole-zero gain
65 if g==0, error('sos2zp: one or more section gains is zero'); end
66 sos(:,1:3) = sos(:,1:3)./ [gains gains gains];
69 if m~=6, error('sos2zp: sos matrix should be N by 6'); end
75 zi = roots(sos(i,1:3));
77 pi = roots(sos(i,4:6));
83 %! b1t=[1 2 3]; a1t=[1 .2 .3];
84 %! b2t=[4 5 6]; a2t=[1 .4 .5];
85 %! sos=[b1t a1t; b2t a2t];
86 %! z = [-1-1.41421356237310i;-1+1.41421356237310i;...
87 %! -0.625-1.05326872164704i;-0.625+1.05326872164704i];
88 %! p = [-0.2-0.678232998312527i;-0.2+0.678232998312527i;...
89 %! -0.1-0.538516480713450i;-0.1+0.538516480713450i];
91 %! [z2,p2,k2] = sos2zp(sos,1);
92 %! assert({cplxpair(z2),cplxpair(p2),k2},{z,p,k},100*eps);