1 ## Copyright (C) 2007 R.G.H. Eschauzier <reschauzier@yahoo.com>
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/>.
16 ## Adapted by Carnë Draug on 2011 <carandraug+dev@gmail.com>
18 ## This function is necessary for impinvar and invimpinvar of the signal package
20 ## Find {-zd/dz}^n*H1(z). I.e., first differentiate, then multiply by -z, then differentiate, etc.
21 ## The result is (ts^(n+1))*(b(1)*p/(z-p)^1 + b(2)*p^2/(z-p)^2 + b(n+1)*p^(n+1)/(z-p)^(n+1)).
23 function b = h1_z_deriv(n, p, ts)
25 %% Build the vector d that holds coefficients for all the derivatives of H1(z)
26 %% The results reads d(n)*z^(1)*(d/dz)^(1)*H1(z) + d(n-1)*z^(2)*(d/dz)^(2)*H1(z) +...+ d(1)*z^(n)*(d/dz)^(n)*H1(z)
27 d = (-1)^n; % Vector with the derivatives of H1(z)
29 d = [d 0]; % Shift result right (multiply by -z)
30 d += prepad(polyder(d), i+1, 0, 2); % Add the derivative
33 %% Build output vector
36 b += d(i) * prepad(h1_deriv(n-i+1), n+1, 0, 2);
39 b *= ts^(n+1)/factorial(n);
41 %% Multiply coefficients with p^i, where i is the index of the coeff.
46 ## Find (z^n)*(d/dz)^n*H1(z), where H1(z)=ts*z/(z-p), ts=sampling period,
47 ## p=exp(sm*ts) and sm is the s-domain pole with multiplicity n+1.
48 ## The result is (ts^(n+1))*(b(1)*p/(z-p)^1 + b(2)*p^2/(z-p)^2 + b(n+1)*p^(n+1)/(z-p)^(n+1)),
49 ## where b(i) is the binomial coefficient bincoeff(n,i) times n!. Works for n>0.
50 function b = h1_deriv(n)
51 b = factorial(n)*bincoeff(n,0:n); % Binomial coefficients: [1], [1 1], [1 2 1], [1 3 3 1], etc.