Engee documentation
Notebook

Creating discrete time models

This example shows how to create linear models with discrete time.

Definition of discrete-time models

The ControlSystems.jl library allows you to create both continuous and discrete systems. The syntax for creating discrete time models is similar to that used for continuous systems, but you must pass the sampling step (sampling interval in seconds) as input to the function.

For example, to specify the transfer function of a discrete system: $$ H(z) = \frac{z-1}{z^2-1.85z+0.9} $$

With sampling period $Ts = 0.1$.

In [ ]:
Pkg.add(["ControlSystems"])
In [ ]:
using ControlSystems

num = [1, -1];
den = [1, -1.85, 0.9];
H = tf(num,den,0.1)
Out[0]:
TransferFunction{Discrete{Float64}, ControlSystemsBase.SisoRational{Float64}}
     1.0z - 1.0
--------------------
1.0z^2 - 1.85z + 0.9

Sample Time: 0.1 (seconds)
Discrete-time transfer function model

in the same way you can specify a model of a discrete system in the state space: $$ x[k+1]=0.5x[k]+u[k] $$ $$ y[k]=0.2x[k] $$

With sampling period $Ts = 0.1$.

In [ ]:
sys = ss(.5,1,.2,0,0.1)
Out[0]:
StateSpace{Discrete{Float64}, Float64}
A = 
 0.5
B = 
 1.0
C = 
 0.2
D = 
 0.0

Sample Time: 0.1 (seconds)
Discrete-time state-space model

Recognition of discrete-time systems

There are several ways to determine if a linear model is discrete. For example, sys.Ts or H.Ts will return a non-zero value $Ts$, if the model is discrete.

In [ ]:
H.Ts
Out[0]:
0.1

It can also be determined from the graph of the transition function. The response of the system to a single step action will have the form of a "ladder".

In [ ]:
using Plots

plot(step(H,8))
Out[0]:

Thus, it is possible to obtain a model of a discrete system. More information about building linear systems can be found in Building Systems.