]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/zpkdata.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / zpkdata.m
1 ## Copyright (C) 2011   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {[@var{z}, @var{p}, @var{k}, @var{tsam}] =} zpkdata (@var{sys})
20 ## @deftypefnx {Function File} {[@var{z}, @var{p}, @var{k}, @var{tsam}] =} zpkdata (@var{sys}, @var{"v"})
21 ## Access zero-pole-gain data.
22 ##
23 ## @strong{Inputs}
24 ## @table @var
25 ## @item sys
26 ## Any type of LTI model.
27 ## @item "v", "vector"
28 ## For SISO models, return @var{z} and @var{p} directly as column vectors
29 ## instead of cells containing a single column vector.
30 ## @end table
31 ##
32 ## @strong{Outputs}
33 ## @table @var
34 ## @item z
35 ## Cell of column vectors containing the zeros for each channel.
36 ## z@{i,j@} contains the zeros from input j to output i.
37 ## @item p
38 ## Cell of column vectors containing the poles for each channel.
39 ## p@{i,j@} contains the poles from input j to output i.
40 ## @item k
41 ## Matrix containing the gains for each channel.
42 ## k(i,j) contains the gain from input j to output i.
43 ## @item tsam
44 ## Sampling time in seconds.  If @var{sys} is a continuous-time model,
45 ## a zero is returned.
46 ## @end table
47 ## @end deftypefn
48
49 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
50 ## Created: September 2011
51 ## Version: 0.1
52
53 function [z, p, k, tsam] = zpkdata (sys, rtype = "cell")
54
55   [num, den, tsam] = tfdata (sys);
56
57   z = cellfun (@roots, num, "uniformoutput", false);
58   p = cellfun (@roots, den, "uniformoutput", false);
59   k = cellfun (@(n,d) n(1)/d(1), num, den);
60
61   if (strncmpi (rtype, "v", 1) && issiso (sys))
62     z = z{1};
63     p = p{1};
64   endif
65
66 endfunction