1
%% Copyright (C) 2005 Julius O. Smith III
3
%% This program is free software; you can redistribute it and/or modify
4
%% it under the terms of the GNU General Public License as published by
5
%% the Free Software Foundation; either version 2 of the License, or
6
%% (at your option) any later version.
8
%% This program is distributed in the hope that it will be useful,
9
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
10
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
%% GNU General Public License for more details.
13
%% You should have received a copy of the GNU General Public License
14
%% along with this program; If not, see <http://www.gnu.org/licenses/>.
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
17
%% @deftypefn {Function File} {[@var{B}, @var{A}] =} sos2tf (@var{sos}, @var{Bscale})
24
24
%% @var{sos} = matrix of series second-order sections, one per row:@*
25
25
%% @var{sos} = [@var{B1}.' @var{A1}.'; ...; @var{BN}.' @var{AN}.'], where@*
26
%% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for
26
%% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for
27
27
%% section 1, etc.@*
28
28
%% b0 must be nonzero for each section.@*
29
29
%% See @code{filter()} for documentation of the
33
33
%% @var{Bscale} is an overall gain factor that effectively scales
34
34
%% the output @var{B} vector (or any one of the input @var{B}i vectors).
38
38
%% @var{B} and @var{A} are vectors specifying the digital filter @math{H(z) = B(z)/A(z)}.
39
39
%% See @code{filter()} for further details.
41
41
%% @seealso{tf2sos zp2sos sos2pz zp2tf tf2zp}
44
function [B,A] = sos2tf(sos,Bscale)
46
if nargin<2, Bscale=1; end
48
if M~=6, error('sos2tf: sos matrix should be N by 6'); end
52
B = conv(B, sos(i,1:3));
53
A = conv(A, sos(i,4:6));
56
while nB & B(nB)==0, B=B(1:nB-1); nB=length(B); end
58
while nA & A(nA)==0, A=A(1:nA-1); nA=length(A); end
44
function [B,A] = sos2tf(sos, Bscale = 1)
46
if (nargin < 1 || nargin > 2)
53
error('sos2tf: sos matrix should be N by 6');
60
B = conv(B, sos(i,1:3));
61
A = conv(A, sos(i,4:6));
66
84
%! assert({Bh,Ah},{B,A},10*eps);
70
88
%! A=[1 0 0 0 0 0.9];
71
89
%! [sos,g] = tf2sos(B,A);
72
90
%! [Bh,Ah] = sos2tf(sos,g);