]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/tf2sos.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / tf2sos.m
1 %% Copyright (C) 2005 Julius O. Smith III <jos@ccrma.stanford.edu>
2 %%
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
6 %% version.
7 %%
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
11 %% details.
12 %%
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/>.
15
16 %% -*- texinfo -*-
17 %% @deftypefn {Function File} {[@var{sos}, @var{g}] =} tf2sos (@var{B}, @var{A})
18 %% Convert direct-form filter coefficients to series second-order sections.
19 %%
20 %% INPUTS:
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.
24 %%
25 %% RETURNED:
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 
29 %% section 1, etc.@*
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.
33 %%
34 %% EXAMPLE:
35 %% @example
36 %% B=[1 0 0 0 0 1]; 
37 %% A=[1 0 0 0 0 .9];
38 %% [sos,g] = tf2sos(B,A)
39 %%
40 %% sos =
41 %%
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
45 %%
46 %% g = 1
47 %%
48 %% @end example
49 %%
50 %% @seealso{sos2tf zp2sos sos2pz zp2tf tf2zp}
51 %% @end deftypefn
52
53 function [sos,g] = tf2sos (B, A)
54
55   [z,p,g] = tf2zp(B(:)',A(:)');
56   sos = zp2sos(z,p,g);
57
58 endfunction
59
60 %!test
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);