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$.
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$.
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.
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".
Thus, it is possible to obtain a model of a discrete system. More information about building linear systems can be found in Building Systems.
{"id": "1f6955fc-b4ca-47ea-89f9-f23ef56b5160", "data": [{"xaxis": "x", "mode": "lines", "x": [0, 0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.7, 0.8, 0.8, 0.9, 0.9, 1, 1, 1.1, 1.1, 1.2, 1.2, 1.3, 1.3, 1.4, 1.4, 1.5, 1.5, 1.6, 1.6, 1.7, 1.7, 1.8, 1.8, 1.9, 1.9, 2, 2, 2.1, 2.1, 2.2, 2.2, 2.3, 2.3, 2.4, 2.4, 2.5, 2.5, 2.6, 2.6, 2.7, 2.7, 2.8, 2.8, 2.9, 2.9, 3, 3, 3.1, 3.1, 3.2, 3.2, 3.3, 3.3, 3.4, 3.4, 3.5, 3.5, 3.6, 3.6, 3.7, 3.7, 3.8, 3.8, 3.9, 3.9, 4, 4, 4.1, 4.1, 4.2, 4.2, 4.3, 4.3, 4.4, 4.4, 4.5, 4.5, 4.6, 4.6, 4.7, 4.7, 4.8, 4.8, 4.9, 4.9, 5, 5, 5.1, 5.1, 5.2, 5.2, 5.3, 5.3, 5.4, 5.4, 5.5, 5.5, 5.6, 5.6, 5.7, 5.7, 5.8, 5.8, 5.9, 5.9, 6, 6, 6.1, 6.1, 6.2, 6.2, 6.3, 6.3, 6.4, 6.4, 6.5, 6.5, 6.6, 6.6, 6.7, 6.7, 6.8, 6.8, 6.9, 6.9, 7, 7, 7.1, 7.1, 7.2, 7.2, 7.3, 7.3, 7.4, 7.4, 7.5, 7.5, 7.6, 7.6, 7.7, 7.7, 7.8, 7.8, 7.9, 7.9, 8, 8], "showlegend": false, "name": "", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": null, "legendgroup": "", "y": [0, 0, 1, 1, 1.85, 1.85, 2.5225000000000004, 2.5225000000000004, 3.0016250000000007, 3.0016250000000007, 3.282756250000002, 3.282756250000002, 3.3716365625000027, 3.3716365625000027, 3.283047015625005, 3.283047015625005, 3.0391640726562557, 3.0391640726562557, 2.667711220351567, 2.667711220351567, 2.2000180922597714, 2.2000180922597714, 1.6690933723641663, 1.6690933723641663, 1.1078064558399134, 1.1078064558399134, 0.5472579081760891, 0.5472579081760891, 0.015401319869845054, 0.015401319869845054, -0.4640396755992704, -0.4640396755992704, -0.8723345877415092, -0.8723345877415092, -1.1961832792824474, -1.1961832792824474, -1.4278379377051706, -1.4278379377051706, -1.5649352334003659, -1.5649352334003659, -1.6100760378560217, -1.6100760378560217, -1.5701989599733075, -1.5701989599733075, -1.4557996418802013, -1.4557996418802013, -1.2800502735023969, -1.2800502735023969, -1.0578733282872541, -1.0578733282872541, -0.8050204111792603, -0.8050204111792603, -0.537201765223104, -0.537201765223104, -0.26930489560140813, -0.26930489560140813, -0.014732468161810175, -0.014732468161810175, 0.2151193399419178, 0.2151193399419178, 0.411230000238179, 0.411230000238179, 0.567168094492903, 0.567168094492903, 0.6791539745975079, 0.6791539745975079, 0.7459835679617797, 0.7459835679617797, 0.7688310235915345, 0.7688310235915345, 0.7509521824787377, 0.7509521824787377, 0.6973136163532843, 0.6973136163532843, 0.6141732260227108, 0.6141732260227108, 0.5086382134240601, 0.5086382134240601, 0.3882247914140713, 0.3882247914140713, 0.2604414720343762, 0.2604414720343762, 0.13241441099093265, 0.13241441099093265, 0.010569335502285782, 0.010569335502285782, -0.09961969921261016, -0.09961969921261016, -0.19380884549538635, -0.19380884549538635, -0.2688886348751147, -0.2688886348751147, -0.3230160135731168, -0.3230160135731168, -0.3555798537226629, -0.3555798537226629, -0.3671083171711196, -0.3671083171711196, -0.35912851841617766, -0.35912851841617766, -0.3339902736159175, -0.3339902736159175, -0.29466633961488853, -0.29466633961488853, -0.24454148203322035, -0.24454148203322035, -0.18720203610805441, -0.18720203610805441, -0.12623643297000342, -0.12623643297000342, -0.06505556849725735, -0.06505556849725735, -0.006740012046922317, -0.006740012046922317, 0.0460809893607248, 0.0460809893607248, 0.09131584115957381, 0.09131584115957381, 0.12746141572055691, 0.12746141572055691, 0.1536193620394144, 0.1536193620394144, 0.16948054562441683, 0.16948054562441683, 0.1752815835696957, 0.1752815835696957, 0.17173843854196136, 0.17173843854196136, 0.15996268608990505, 0.15996268608990505, 0.14136637457855628, 0.14136637457855628, 0.11756137548941581, 0.11756137548941581, 0.09025880753472038, 0.09025880753472038, 0.06117355599875651, 0.06117355599875651, 0.03193815181645121, 0.03193815181645121, 0.004029380461552989, 0.004029380461552989, -0.021289982780931638, -0.021289982780931638, -0.043012910560122464, -0.043012910560122464, -0.06041290003338773, -0.06041290003338773, -0.07305224555765477, -0.07305224555765477, -0.08077504425161308, -0.08077504425161308, -0.08368681086359331, -0.08368681086359331, -0.08212306027120064, -0.08212306027120064, -0.07660953172448615, -0.07660953172448615, -0.06781687944621595, -0.06781687944621595, -0.05651264842346393], "zmax": null, "line": {"shape": "linear", "color": "rgba(0, 154, 250, 1.000)", "dash": "solid", "width": 1}, "zaxis": null, "yaxis": "y", "metadata": {"smartZoomParams": {"maxCount": 161, "minCount": 25000, "currentCount": 161}, "shouldEnableSmartZoom": false}, "type": "scatter"}], "config": {"showlegend": true, "height": 400, "xaxis": {"showline": true, "showticklabels": true, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "anchor": "y", "range": [-0.2400000000000002, 8.24], "tickcolor": "rgb(0, 0, 0)", "gridwidth": 0.5, "visible": true, "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": false, "mirror": false, "domain": [0.061654272382618835, 0.9934383202099737], "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": "Time (s)"}, "ticks": "inside", "type": "linear"}, "annotations": [], "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "margin": {"t": 20, "b": 20, "r": 0, "l": 0}, "yaxis": {"showline": true, "showticklabels": true, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "anchor": "x", "range": [-1.7595274158667027, 3.5210879405106836], "tickcolor": "rgb(0, 0, 0)", "gridwidth": 0.5, "visible": true, "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": false, "mirror": false, "domain": [0.07581474190726165, 0.9901574803149606], "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": "y"}, "ticks": "inside", "type": "linear"}, "width": 1515.828125, "legend": {"x": 1, "traceorder": "normal", "yanchor": "auto", "font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "borderwidth": 1, "bordercolor": "rgba(0, 0, 0, 1)", "y": 1, "bgcolor": "rgba(255, 255, 255, 1.000)", "tracegroupgap": 0, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "xanchor": "auto"}}}