1 ## Copyright (C) 2011 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
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.
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.
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/>.
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.
33 ## LTI model to be converted to transfer function.
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.
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.
43 ## Matrix containing the gains for each channel.
44 ## k(i,j) contains the gain from input j to output i.
46 ## Sampling time in seconds. If @var{tsam} is not specified,
47 ## a continuous-time model is assumed.
49 ## Optional pairs of properties and values.
50 ## Type @command{set (tf)} for more information.
56 ## Transfer function model.
59 ## @seealso{tf, ss, dss, frd}
62 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
63 ## Created: September 2011
66 function sys = zpk (z = {}, p = {}, k = [], varargin)
73 case 1 # sys = zpk (sys), sys = zpk (k), s = zpk ("s")
74 if (isa (z, "lti") || is_real_matrix (z) || ischar (z))
81 case 2 # z = zpk ("z", tsam)
82 if (ischar (z) && issample (p, -1))
89 otherwise # sys = zpk (z, p, k, ...)
96 if (! size_equal (z, p, k))
97 error ("zpk: arguments z, p and k must have equal dimensions");
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{:});