1
## Copyright (C) 1996, 2000, 2002, 2003, 2004, 2005, 2007
2
## Auburn University. All rights reserved.
4
## This file is part of Octave.
6
## Octave is free software; you can redistribute it and/or modify it
7
## under the terms of the GNU General Public License as published by
8
## the Free Software Foundation; either version 3 of the License, or (at
9
## your option) any later version.
11
## Octave is distributed in the hope that it will be useful, but
12
## WITHOUT ANY WARRANTY; without even the implied warranty of
13
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
## General Public License for more details.
16
## You should have received a copy of the GNU General Public License
17
## along with Octave; see the file COPYING. If not, see
18
## <http://www.gnu.org/licenses/>.
21
## @deftypefn {Function File} {[@var{a}, @var{b}, @var{c}, @var{d}] =} zp2ss (@var{zer}, @var{pol}, @var{k})
22
## Conversion from zero / pole to state space.
28
## Vectors of (possibly) complex poles and zeros of a transfer
29
## function. Complex values must come in conjugate pairs
30
## (i.e., @math{x+jy} in @var{zer} means that @math{x-jy} is also in @var{zer}).
31
## The number of zeros must not exceed the number of poles.
33
## Real scalar (leading coefficient).
42
## The state space system, in the form:
45
## $$ \dot x = Ax + Bu $$
60
## Created: August 15, 1994
62
function [a, b, c, d] = zp2ss (zer, pol, k)
68
if (! (isvector (zer) || isempty (zer)))
69
error ("zer(%d,%d) should be a vector", rows (zer), columns (zer));
70
elseif (! (isvector (pol) || isempty (pol)))
71
error ("pol(%d,%d) should be a vector", rows (pol), columns (pol));
72
elseif (! isscalar(k))
73
error ("k(%d,%d) should be a scalar", rows (k), columns (k));
74
elseif (k != real (k))
75
warning ("zp2ss: k is complex")
78
zpsys = ss (zeros (0, 0), zeros (0, 1), zeros (1, 0), k);
80
## Find the number of zeros and the number of poles
85
error ("%d zeros, exceeds number of poles=%d", nzer, npol);
88
## Sort to place complex conjugate pairs together
92
## construct the system as a series connection of poles and zeros
93
## problem: poles and zeros may come in conjugate pairs, and not
96
## approach: remove poles/zeros from the list as they are included in
101
## search for complex poles, zeros
105
cpol = find (imag (pol) != 0);
108
czer = find (imag (zer) != 0);
111
if (isempty (cpol) && isempty (czer))
117
num = 1; # assume no zeros left.
120
## real pole/zero combination
123
zer = zer(2:length(zer));
126
pol = pol(2:length(pol));
128
## got a complex pole or zero, need two roots (if available)
129
if (length (zer) > 1)
130
[num, zer] = __zp2ssg2__ (zer); # get two zeros
131
elseif (length (zer) == 1)
132
num = [1, -zer]; # use last zero (better be real!)
135
[den, pol] = __zp2ssg2__ (pol); # get two poles
137
error ("pcnt = %d", pcnt);
140
## pack tf into system form and put in series with earlier realization
141
zpsys1 = tf (num, den, 0, "u", "yy");
143
## change names to avoid warning messages from sysgroup
144
zpsys = syssetsignals (zpsys, "in", "u1", 1);
145
zpsys1 = sysupdate (zpsys1, "ss");
146
nn = sysdimensions (zpsys); # working with continuous system
147
zpsys = syssetsignals (zpsys, "st", __sysdefioname__ (nn, "x"));
148
nn1 = sysdimensions (zpsys1);
149
zpsys1 = syssetsignals (zpsys1, "st", __sysdefioname__ (nn1, "xx"));
151
zpsys = sysmult (zpsys, zpsys1);
155
[a, b, c, d] = sys2ss (zpsys);