/usr/share/octave/packages/signal-1.3.2/residuez.m is in octave-signal 1.3.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | ## Copyright (C) 2005 Julius O. Smith III <jos@ccrma.stanford.edu>
##
## 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 <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{r}, @var{p}, @var{f}, @var{m}] =} residuez (@var{b}, @var{a})
## Compute the partial fraction expansion of filter @math{H(z) = B(z)/A(z)}.
##
## INPUTS:
## @var{b} and @var{a} are vectors specifying the digital filter
## @math{H(z) = B(z)/A(z)}. See @code{help filter} for documentation of the
## @var{b} and @var{a} filter coefficients.
##
## RETURNED:
## @itemize
## @item @var{r} = column vector containing the filter-pole residues
## @item @var{p} = column vector containing the filter poles
## @item @var{f} = row vector containing the FIR part, if any
## @item @var{m} = column vector of pole multiplicities
## @end itemize
##
## EXAMPLES:
## @example
## See @code{test residuez verbose} to see a number of examples.
## @end example
##
## For the theory of operation, see
## @indicateurl{http://ccrma.stanford.edu/~jos/filters/residuez.html}
##
## @seealso{residue, residued}
## @end deftypefn
function [r, p, f, m] = residuez(B, A, tol)
## RESIDUEZ - return residues, poles, and FIR part of B(z)/A(z)
##
## Let nb = length(b), na = length(a), and N=na-1 = no. of poles.
## If nb<na, then f will be empty, and the returned filter is
##
## r(1) r(N)
## H(z) = ---------------- + ... + ----------------- = R(z)
## [ 1-p(1)/z ]^m(1) [ 1-p(N)/z ]^m(N)
##
## If, on the other hand, nb >= na, the FIR part f will not be empty.
## Let M = nb-na+1 = order of f = length(f)-1). Then the returned filter is
##
## H(z) = f(1) + f(2)/z + f(3)/z^2 + ... + f(M+1)/z^M + R(z)
##
## where R(z) is the parallel one-pole filter bank defined above.
## Note, in particular, that the impulse-response of the one-pole
## filter bank is in parallel with that of the the FIR part. This can
## be wasteful when matching the initial impulse response is important,
## since F(z) can already match the first N terms of the impulse
## response. To obtain a decomposition in which the impulse response of
## the IIR part R(z) starts after that of the FIR part F(z), use RESIDUED.
##
## J.O. Smith, 9/19/05
if nargin==3
warning("tolerance ignored");
endif
NUM = B(:)'; DEN = A(:)';
## Matlab's residue does not return m (since it is implied by p):
[r,p,f,m]=residue(conj(fliplr(NUM)),conj(fliplr(DEN)));
p = 1 ./ p;
r = r .* ((-p) .^m);
if f, f = conj(fliplr(f)); endif
endfunction
%!test
%! B=[1 -2 1]; A=[1 -1];
%! [r,p,f,m] = residuez(B,A);
%! assert(r,0,100*eps);
%! assert(p,1,100*eps);
%! assert(f,[1 -1],100*eps);
%! assert(m,1,100*eps);
%!test
%! B=1; A=[1 -1j];
%! [r,p,f,m] = residuez(B,A);
%! assert(r,1,100*eps);
%! assert(p,1j,100*eps);
%! assert(f,[],100*eps);
%! assert(m,1,100*eps);
%!test
%! B=1; A=[1 -1 .25];
%! [r,p,f,m] = residuez(B,A);
%! [rs,is] = sort(r);
%! assert(rs,[0;1],1e-7);
%! assert(p(is),[0.5;0.5],1e-8);
%! assert(f,[],100*eps);
%! assert(m(is),[1;2],100*eps);
%!test
%! B=1; A=[1 -0.75 .125];
%! [r,p,f,m] = residuez(B,A);
%! [rs,is] = sort(r);
%! assert(rs,[-1;2],100*eps);
%! assert(p(is),[0.25;0.5],100*eps);
%! assert(f,[],100*eps);
%! assert(m(is),[1;1],100*eps);
%!test
%! B=[1,6,2]; A=[1,-2,1];
%! [r,p,f,m] = residuez(B,A);
%! [rs,is] = sort(r);
%! assert(rs,[-10;9],1e-7);
%! assert(p(is),[1;1],1e-8);
%! assert(f,[2],100*eps);
%! assert(m(is),[1;2],100*eps);
%!test
%! B=[6,2]; A=[1,-2,1];
%! [r,p,f,m] = residuez(B,A);
%! [rs,is] = sort(r);
%! assert(rs,[-2;8],1e-7);
%! assert(p(is),[1;1],1e-8);
%! assert(f,[],100*eps);
%! assert(m(is),[1;2],100*eps);
%!test
%! B=[1,6,6,2]; A=[1,-2,1];
%! [r,p,f,m] = residuez(B,A);
%! [rs,is] = sort(r);
%! assert(rs,[-24;15],2e-7);
%! assert(p(is),[1;1],1e-8);
%! assert(f,[10,2],100*eps);
%! assert(m(is),[1;2],100*eps);
%!test
%! B=[1,6,6,2]; A=[1,-(2+j),(1+2j),-j];
%! [r,p,f,m] = residuez(B,A);
%! [rs,is] = sort(r);
%! assert(rs,[-2+2.5j;7.5+7.5j;-4.5-12j],1E-6);
%! assert(p(is),[1j;1;1],1E-6);
%! assert(f,-2j,1E-6);
%! assert(m(is),[1;2;1],1E-6);
%!test
%! B=[1,0,1]; A=[1,0,0,0,0,-1];
%! [r,p,f,m] = residuez(B,A);
%! [as,is] = sort(angle(p));
%! rise = [ ...
%! 0.26180339887499 - 0.19021130325903i; ...
%! 0.03819660112501 + 0.11755705045849i; ...
%! 0.4; ...
%! 0.03819660112501 - 0.11755705045849i; ...
%! 0.26180339887499 + 0.19021130325903i;];
%! pise = [ ...
%! -0.80901699437495 - 0.58778525229247i; ...
%! 0.30901699437495 - 0.95105651629515i; ...
%! 1; ...
%! 0.30901699437495 + 0.95105651629515i; ...
%! -0.80901699437495 + 0.58778525229247i];
%! assert(r(is),rise,100*eps);
%! assert(p(is),pise,100*eps);
%! assert(f,[],100*eps);
%! assert(m,[1;1;1;1;1],100*eps);
|