X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fsignal-1.1.3%2Ftf2sos.m;fp=octave_packages%2Fsignal-1.1.3%2Ftf2sos.m;h=98aaf7251f6eecc3d0592be3868b824bf3d4c73a;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/signal-1.1.3/tf2sos.m b/octave_packages/signal-1.1.3/tf2sos.m new file mode 100644 index 0000000..98aaf72 --- /dev/null +++ b/octave_packages/signal-1.1.3/tf2sos.m @@ -0,0 +1,64 @@ +%% Copyright (C) 2005 Julius O. Smith III +%% +%% This program is free software; you can redistribute it and/or modify it under +%% the terms of the GNU General Public License as published by the Free Software +%% Foundation; either version 3 of the License, or (at your option) any later +%% version. +%% +%% This program is distributed in the hope that it will be useful, but WITHOUT +%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +%% details. +%% +%% You should have received a copy of the GNU General Public License along with +%% this program; if not, see . + +%% -*- texinfo -*- +%% @deftypefn {Function File} {[@var{sos}, @var{g}] =} tf2sos (@var{B}, @var{A}) +%% Convert direct-form filter coefficients to series second-order sections. +%% +%% INPUTS: +%% @var{B} and @var{A} are vectors specifying the digital filter @math{H(z) = B(z)/A(z)}. +%% See @code{filter()} for documentation of the @var{B} and @var{A} +%% filter coefficients. +%% +%% RETURNED: +%% @var{sos} = matrix of series second-order sections, one per row:@* +%% @var{sos} = [@var{B1}.' @var{A1}.'; ...; @var{BN}.' @var{AN}.'], where@* +%% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for +%% section 1, etc.@* +%% b0 must be nonzero for each section (zeros at infinity not supported). +%% @var{Bscale} is an overall gain factor that effectively scales +%% any one of the @var{B}i vectors. +%% +%% EXAMPLE: +%% @example +%% 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 +%% +%% @end example +%% +%% @seealso{sos2tf zp2sos sos2pz zp2tf tf2zp} +%% @end deftypefn + +function [sos,g] = tf2sos (B, A) + + [z,p,g] = tf2zp(B(:)',A(:)'); + sos = zp2sos(z,p,g); + +endfunction + +%!test +%! B=[1 0 0 0 0 1]; A=[1 0 0 0 0 .9]; +%! [sos,g] = tf2sos(B,A); +%! [Bh,Ah] = sos2tf(sos,g); +%! assert({Bh,Ah},{B,A},100*eps);