Skip to content

Commit 70dd235

Browse files
committed
make some clarifications
1 parent 471cfef commit 70dd235

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

docs/src/examples/zoh.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Analysis of hybrid continuous-discrete systems
2-
In this example, we analyze the effect of ZoH sampling in continuous time and compare it to the equivalent discrete-time system
1+
# Analysis of sampled-data systems
2+
A sampled-data system contains both continuous-tiem and discrete-time components, such as a continuous-time plant and a discrete-time controller. In this example, we will look at how to analyze such systems using the ControlSystems.jl package. To learn more about the theory of sampled-data systems, consult the reference mentioned at the end of this page.
3+
4+
First, we analyze the effect of ZoH sampling in continuous time and compare it to the equivalent discrete-time system
35

46
We will consider a simple second-order system ``P``, which we define in continuous time:
57
```@example zoh
@@ -10,7 +12,7 @@ P = tf(0.1, [1, 0.1, 0.1])
1012

1113
## Continuous to discrete
1214

13-
Next, we discretize this system using the standard [`c2d`](@ref) function, which uses ZoH sampling by default. We compare the frequency response of the discretized system with the frequency response of the original continuous-time system multiplied by the transfer function of the ZoH operator
15+
Next, we discretize this system using the standard [`c2d`](@ref) function, which uses ZoH sampling by default. We compare the frequency response of the discretized system with the frequency response of the original continuous-time system multiplied by the transfer function of the ZoH operator [^CCS]
1416
```math
1517
Z(s) = \dfrac{1 - e^{-T_s s}}{s}
1618
```
@@ -56,7 +58,7 @@ With a _continuous_ input signal, the result is different,
5658
after the initial transient, the output of `Pz` matches that of `Pd` exactly
5759
(try plotting with the plotly() backend and zoom in at the end)
5860
```@example zoh
59-
Tf = 150
61+
Tf = 100
6062
ufun = (x,t)->[sin(2pi*t/5)]
6163
resP = lsim(P, ufun, Tf)
6264
resPz = lsim(Pz, ufun, 0:0.01:Tf)
@@ -67,7 +69,7 @@ plot([resP, resPz, resPd], lab=["P" "Pz" "Pd"]); lens!([Tf-10, Tf], [-0.1, 0.1],
6769

6870
## Discrete to continuous
6971

70-
Discrete-time systems can be converted to continuous-time systems formulated with delay terms in such a way that the frequency-response of the two systems match exactly, using the substiturion ``z^{-1} = e^{-sT_s}``. To this end, the function [`d2d_exact`](@ref) is used. This is useful when analyzing hybrid systems with both continuous-time and discrete-time components and accurate frequency-domain calculations are required over the entire frequency range up to the Nyquist frequency.
72+
Discrete-time systems can be converted to continuous-time systems formulated with delay terms in such a way that the frequency-response of the two systems match exactly, using the substitution ``z^{-1} = e^{-sT_s}``. To this end, the function [`d2c_exact`](@ref) is used. This is useful when analyzing hybrid systems with both continuous-time and discrete-time components and accurate frequency-domain calculations are required over the entire frequency range up to the Nyquist frequency.
7173

7274
Below, we compare the frequency response of a discrete-time system with delays to
7375
two continuous-time systems, one translated using the exact method and one using the standard `d2c` method with inverse ZoH sampling.
@@ -121,10 +123,10 @@ bodeplot!(Pd, wd, lab="\$P(z)\$ ZoH")
121123
bodeplot!(Ld, wd, lab="\$P(z)C(z)\$", legend=:bottomleft)
122124
```
123125

124-
If we instead make use of the second method above, exactly translating the discrete-time controller to continuous time, we can more easily determine that the closed-loop system will be stable by inspecting the Bode plot
126+
If we instead make use of the second method above, exactly translating the discrete-time controller to continuous time, we can more easily determine that the closed-loop system will be stable by inspecting the Bode plot. Here, we show the Bode plot of ``P`` and that of the loop-transfer function, including the ZoH operator, ``P(s)Z(s)C(s)``.
125127
```@example zoh
126128
Cc = d2c_exact(C)
127-
Lc = P*Cc
129+
Lc = P*Z*Cc
128130
129131
bodeplot(P, wd, lab="\$P(s)\$")
130132
bodeplot!(Lc, wd, lab="\$P(s)C(s)\$", legend=:bottomleft, c=3)
@@ -136,15 +138,21 @@ PS = \dfrac{P(s)}{1 + P(s)C(s)}
136138
```
137139
we can simulate the response to a continuous-time input disturbance that contains frequencies higher than the Nyquist frequency of the discrete-time system, we do this below. We also try doing this with the discretized plant, which yields a very poor result
138140
```@example zoh
139-
PS = feedback(P, Cc) # Use the continuous-time plant and continuous translation of the controller
141+
PS = feedback(P, Z*Cc) # Use the continuous-time plant and continuous translation of the controller + ZoH operator
140142
PSd = feedback(Pd, C) # Use the discretized plant and discrete controller
141143
ω = 5.53 # Frequency of input disturbance (rad/s) (Nyquist frequency is π rad/s)
142144
disturbance(x, t) = sin(ω*t) # Continuous input disturbance
143145
plot(lsim(PS, disturbance, 0:0.22:3500), lab="Continuous disturbance response")
144146
plot!(lsim(PSd, disturbance, 3500), lab="Discrete disturbance response")
145147
hline!([abs(freqresp(PS, ω)[])], l=(:black, :dash), lab="Predicted freq. response amplitude", legend=:bottomleft, fmt=:png)
146148
```
147-
The continuous-time analysis eventually settles at a periodic output that matches the amplitude predicted by the continuous-time frequency response. However, the discrete-time simulation yields, as expected, a very poor result.
149+
The continuous-time analysis eventually settles at a periodic output that matches the amplitude predicted by the continuous-time frequency response. However, the discrete-time simulation yields, as expected, a very poor result. Noticeable in the simulation is the appearance of a beat frequency, which is expected due to the modulation introduced by sampling.[^CCS]
150+
151+
## Caveats
152+
- The exact output of the system that was translated from discrete to continuous time is not going to be accurate, so transient properties of the hybrid system cannot be accurately assessed using this kind of analysis.
153+
- Interpretation of frequency-responses for sampled-data systems must be done with care. The modulation introduced by sampling implies the creating of additional frequencies in the output. For an input with frequency ``\omega``, the output will contain all frequencies ``\omega ± \omega_s k`` where ``\omega_s`` is the sampling frequency and ``k`` is an integer.[^CCS]
154+
155+
## References
156+
Learn more about sampled-data systems and zero-order hold sampling in chapter 7 of the reference below.
157+
[^CCS]: Åström, K. J., & Wittenmark, B. (1997). Computer-Controlled Systems: Theory and Design.
148158

149-
### Caveats
150-
The exact output of the system that was translated from discrete to continuous time is not going to be accurate, so transient properties of the hybrid system cannot be accurately assessed using this kind of analysis.

0 commit comments

Comments
 (0)