1
## Copyright (C) 1996, 1998, 2000, 2003, 2004, 2005, 2006, 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/>.
20
## Undocumented internal function.
23
## @deftypefn {Function File} {[@var{y}, @var{t}] =} __stepimp__ (@var{sitype}, @var{sys} [, @var{inp}, @var{tstop}, @var{n}])
24
## Impulse or step response for a linear system.
25
## The system can be discrete or multivariable (or both).
26
## This m-file contains the ``common code'' of step and impulse.
28
## Produces a plot or the response data for system @var{sys}.
30
## Limited argument checking; ``do not attempt to do this at home''.
31
## Used internally in @command{impulse}, @command{step}. Use @command{step}
32
## or @command{impulse} instead.
33
## @seealso{step, impulse}
36
## Author: Kai P. Mueller <mueller@ifr.ing.tu-bs.de>
37
## Created: October 2, 1997
38
## based on lsim.m of Scottedward Hodel
40
function [y, t] = __stepimp__ (sitype, sys, inp, tstop, n)
47
error ("__stepimp__: invalid sitype argument");
49
sys = sysupdate (sys, "ss");
51
USE_DEF = 0; # default tstop and n if we have to give up
52
N_MIN = 50; # minimum number of points
53
N_MAX = 2000; # maximum number of points
54
T_DEF = 10.0; # default simulation time
56
## collect useful information about the system
57
[ncstates, ndstates, NIN, NOUT] = sysdimensions (sys);
58
TSAMPLE = sysgettsam (sys);
62
elseif (inp < 1 || inp > NIN)
63
error ("__stepimp__: argument inp out of range");
66
DIGITAL = is_digital (sys);
70
error ("__stepimp__: sampling time of discrete system too small")
76
error ("__stepimp__: pure gain block (n_states < 1), step response is trivial");
79
## we have to compute the time when the system reaches steady state
81
ev = eig (sys2ss (sys));
83
## perform bilinear transformation on poles in z
86
if (abs(pole + 1) < 1.0e-10)
89
ev(i) = 2 / TSAMPLE * (pole - 1) / (pole + 1);
93
## remove poles near zero from eigenvalue array ev
96
if (abs (real (ev(i))) < 1.0e-10)
103
## printf("##STEPIMP-DEBUG: using defaults.\n");
107
t_step = 0.2 * pi / x;
108
x = min (abs (real (ev)));
111
yy = 10^(ceil (log10 (t_sim)) - 1);
112
t_sim = yy * ceil (t_sim / yy);
113
## printf("##STEPIMP-DEBUG: nk=%d t_step=%f t_sim=%f\n",
114
## nk, t_step, t_sim);
119
## ---- sampled system
123
error ("__stepimp__: n must not be less than 2.")
129
## tstop and n are unknown
131
tstop = (N_MIN - 1) * TSAMPLE;
136
n = floor (tstop / TSAMPLE) + 1;
142
printf ("Hint: number of samples limited to %d by default.\n", \
144
printf (" ==> increase \"n\" parameter for longer simulations.\n");
147
tstop = (n - 1) * TSAMPLE;
150
## ---- continuous system
154
error("step: n must not be less than 2.")
156
t_step = tstop / (n - 1);
162
t_step = tstop / (n - 1);
164
n = floor (tstop / t_step) + 1;
167
## tstop and n are unknown
171
t_step = tstop / (n - 1);
174
n = floor (tstop / t_step) + 1;
179
t_step = tstop / (n - 1);
182
tstop = (n - 1) * t_step;
183
t_step = tstop / (N_MAX - 1);
187
tstop = (n - 1) * t_step;
188
[jnk,B] = sys2ss (sys);
190
sys = c2d (sys, t_step);
192
## printf("##STEPIMP-DEBUG: t_step=%f n=%d tstop=%f\n", t_step, n, tstop);
199
t = linspace (0, tstop, n);
202
if (! DIGITAL && D'*D > 0)
203
error ("impulse: D matrix is nonzero, impulse response infinite.")
221
x = zeros (NSTATES, 1);
230
gm = zeros (NOUT, 1);
233
ssys = ss (F, G, C, D, t_step);
237
ncols = floor (sqrt (NOUT));
238
nrows = ceil (NOUT / ncols);
240
subplot (nrows, ncols, i);
242
[ts, ys] = stairs (t, y(i,:));
246
yy = [ys; gm(i)*ones(size(ts))];
256
yy = [y(i,:); gm(i)*ones(size(t))];
265
title (sprintf ("%s: | %s -> %s", tt,
266
sysgetsignals (sys, "in", inp, 1),
267
sysgetsignals (sys, "out", i, 1)));