]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/zpk.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / zpk.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{s} =} zpk (@var{"s"})
20 ## @deftypefnx {Function File} {@var{z} =} zpk (@var{"z"}, @var{tsam})
21 ## @deftypefnx {Function File} {@var{sys} =} zpk (@var{sys})
22 ## @deftypefnx {Function File} {@var{sys} =} zpk (@var{k})
23 ## @deftypefnx {Function File} {@var{sys} =} zpk (@var{z}, @var{p}, @var{k}, @dots{})
24 ## @deftypefnx {Function File} {@var{sys} =} zpk (@var{z}, @var{p}, @var{k}, @var{tsam}, @dots{})
25 ## @deftypefnx {Function File} {@var{sys} =} zpk (@var{z}, @var{p}, @var{k}, @var{tsam}, @dots{})
26 ## Create transfer function model from zero-pole-gain data.
27 ## This is just a stop-gap compatibility wrapper since zpk
28 ## models are not yet implemented.
29 ##
30 ## @strong{Inputs}
31 ## @table @var
32 ## @item sys
33 ## LTI model to be converted to transfer function.
34 ## @item z
35 ## Cell of vectors containing the zeros for each channel.
36 ## z@{i,j@} contains the zeros from input j to output i.
37 ## In the SISO case, a single vector is accepted as well.
38 ## @item p
39 ## Cell of vectors containing the poles for each channel.
40 ## p@{i,j@} contains the poles from input j to output i.
41 ## In the SISO case, a single vector is accepted as well.
42 ## @item k
43 ## Matrix containing the gains for each channel.
44 ## k(i,j) contains the gain from input j to output i.
45 ## @item tsam
46 ## Sampling time in seconds.  If @var{tsam} is not specified,
47 ## a continuous-time model is assumed.
48 ## @item @dots{}
49 ## Optional pairs of properties and values.
50 ## Type @command{set (tf)} for more information.
51 ## @end table
52 ##
53 ## @strong{Outputs}
54 ## @table @var
55 ## @item sys
56 ## Transfer function model.
57 ## @end table
58 ##
59 ## @seealso{tf, ss, dss, frd}
60 ## @end deftypefn
61
62 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
63 ## Created: September 2011
64 ## Version: 0.1
65
66 function sys = zpk (z = {}, p = {}, k = [], varargin)
67
68   switch (nargin)
69     case 0              # sys = zpk ()
70       sys = tf ();
71       return;
72
73     case 1              # sys = zpk (sys), sys = zpk (k), s = zpk ("s")
74       if (isa (z, "lti") || is_real_matrix (z) || ischar (z))
75         sys = tf (z);
76         return;
77       else
78         print_usage ();
79       endif
80
81     case 2              # z = zpk ("z", tsam)
82       if (ischar (z) && issample (p, -1))
83         sys = tf (z, p);
84         return;
85       else
86         print_usage ();
87       endif
88
89     otherwise           # sys = zpk (z, p, k, ...)
90       if (! iscell (z))
91         z = {z};
92       endif
93       if (! iscell (p))
94         p = {p};
95       endif
96       if (! size_equal (z, p, k))
97         error ("zpk: arguments z, p and k must have equal dimensions");
98       endif
99       num = cellfun (@(zer, gain) real (gain * poly (zer)), z, num2cell (k), "uniformoutput", false);
100       den = cellfun (@(pol) real (poly (pol)), p, "uniformoutput", false);
101       sys = tf (num, den, varargin{:});
102   endswitch
103
104 endfunction
105