Simulate LTI model response to arbitrary inputs
simulates the (time) response of continuous or discrete linear systems to arbitrary inputs. When invoked without left-hand arguments,
lsim plots the response on the screen.
produces a plot of the time response of the LTI model
sys to the input time history
u. The vector
t specifies the time samples for the simulation and consists of regularly spaced time samples.
u must have as many rows as time samples (
length(t)) and as many columns as system inputs. Each row
u(i,:) specifies the input value(s) at the time sample
The LTI model
sys can be continuous or discrete, SISO or MIMO. In discrete time,
u must be sampled at the same rate as the system (
t is then redundant and can be omitted or set to the empty matrix). In continuous time, the time sampling
dt=t(2)-t(1) is used to discretize the continuous model. If
dt is too large (undersampling),
lsim issues a warning suggesting that you use a more appropriate sample time, but will use the specified sample time. See Algorithm for a discussion of sample times.
further specifies an initial condition
x0 for the system states. This syntax applies only to state-space models.
lsim(sys,u,t,x0,'foh') explicitly specifies how the input values should be interpolated between samples (zero-order hold or linear interpolation). By default,
lsim selects the interpolation method automatically based on the smoothness of the signal U.
simulates the responses of several LTI models to the same input history
u and plots these responses on a single figure. As with
plot, you can specify a particular color, linestyle, and/or marker for each system, for example,
The multisystem behavior is similar to that of
When invoked with left-hand arguments,
return the output response
y, the time vector
t used for simulation, and the state trajectories
x (for state-space models only). No plot is drawn on the screen. The matrix
y has as many rows as time samples (
length(t)) and as many columns as system outputs. The same holds for
x with "outputs" replaced by states. Note that the output
t may differ from the specified time vector when the input data is undersampled (see Algorithm).
Simulate and plot the response of the system
to a square wave with period of four seconds. First generate the square wave with
gensig. Sample every 0.1 second during 10 seconds:
Then simulate with
Discrete-time systems are simulated with
ltitr (state space) or
filter (transfer function and zero-pole-gain).
Continuous-time systems are discretized with
c2d using either the
'foh' method (
'foh' is used for smooth input signals and
'zoh' for discontinuous signals such as pulses or square waves). The sampling period is set to the spacing
dt between the user-supplied time samples
The choice of sampling period can drastically affect simulation results. To illustrate why, consider the second-order model
To simulate its response to a square wave with period 1 second, you can proceed as follows:
lsim evaluates the specified sample time, gives this warning
and produces this plot.
To improve on this response, discretize using the recommended sampling period:
This response exhibits strong oscillatory behavior hidden from the undersampled version.
Generate test input signals for
Free response to initial condition