0% found this document useful (0 votes)
3 views

22_Discretization

This lecture focuses on the discretization of continuous-time (CT) systems to discrete-time (DT) systems, emphasizing the importance of digital control in automotive engineering. It discusses the advantages of DT signals, methods of sampling, and the implications of aliasing, as well as the Nyquist theorem for signal reconstruction. Various discretization methods are introduced, including the Forward Euler method, and the process of redesigning CT controllers for DT implementation is outlined.

Uploaded by

Geri Veli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

22_Discretization

This lecture focuses on the discretization of continuous-time (CT) systems to discrete-time (DT) systems, emphasizing the importance of digital control in automotive engineering. It discusses the advantages of DT signals, methods of sampling, and the implications of aliasing, as well as the Nyquist theorem for signal reconstruction. Various discretization methods are introduced, including the Forward Euler method, and the process of redesigning CT controllers for DT implementation is outlined.

Uploaded by

Geri Veli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

04LSLLN Automatic Control

Automotive Engineering

Lecture 22. Discretization


Reminder from L21:Key Motivation – Digital Control
• Analog signals: continuous in time and amplitude.
 Example: voltage, current, temperature, mass position,…
• Digital signals: discrete both in time and magnitude (finite number of
possible values!)

• Fully accurated theory for digital signals and purely digital controllers is
complicated (finite automata, quantized controllers etc.) – now is done by
Cyber Physical Systems (CPS) community

• Discrete-time signals: discrete in time, continuous in amplitude (result


from time sampling). A sort of compromise!

• Discrete-time signals give a number of advantages:


 More convenient to control develop theory – practically same as
continuous-time.
 Good enough approximation in most practical applications.
 The effect of discrete amplitude (finite precision) can often be modeled
as disturbances and measurement noises.
Discretization (From CT to DT), or Time Sampling
• More often, DT arise from discretization of CT systems. In this case, signals
of the DT system are also discretized (sampled) CT signals.
 Simplified integration (numerical solution) of the equations (L04)
 Parameter identification is much simpler than in continuous time (L23)
 Today: the necessity of software implementation on digital platforms

• This lecture: a closer look at discretization (sampling) of signals and


approximation of continuous-time systems by discrete-time ones.
• We have already seen time sampling: L04, discretization of the pendulum!
𝐽𝐽𝑦𝑦(𝑡𝑡)
̈ = −𝐾𝐾 sin 𝑦𝑦(𝑡𝑡) − 𝛽𝛽𝑦𝑦(𝑡𝑡)
̇ + 𝑢𝑢(𝑡𝑡)

𝑦𝑦 𝑘𝑘 = −𝑎𝑎1 𝑦𝑦 𝑘𝑘 − 1 − 𝑎𝑎2 𝑦𝑦 𝑘𝑘 − 2 − 𝑎𝑎3 sin 𝑦𝑦(𝑘𝑘 − 2) + 𝑏𝑏𝑏𝑏(𝑘𝑘 − 2)


𝑇𝑇𝑇𝑇 𝑇𝑇𝑇𝑇 𝑇𝑇 2 𝐾𝐾 𝑇𝑇 2
𝑎𝑎1 = − 2, 𝑎𝑎2 = 1 − , 𝑎𝑎3 = , 𝑏𝑏 =
𝐽𝐽 𝐽𝐽 𝐽𝐽 𝐽𝐽
L21: How To Made a DT Signal from CT Signal
Sampling is a continuous-time to discrete-time conversion:

continuous time discrete time


x
t ∈ [ 0, ∞ ) t kT, =
= k 0,1,2,
x (t) x (kT )

0 1 2 3 4 5 6 7 t for simplicity of notation x (kT ) = x (k )

𝑇𝑇 is the sampling period (or sampling time) (seconds, s)


𝑓𝑓𝑠𝑠 = 1/𝑇𝑇 is the sampling frequency (Hertz, Hz)
𝜔𝜔𝑠𝑠 = 2π
𝑓𝑓𝑓𝑓 = 2π/𝑇𝑇 is the sampling frequency (rad/s)
How to choose the sampling frequency?
Typical answer in signal processing: Nyquist frequency
In control engineering – some practical recommendations.
Recollection from L21: Zero-Order Hold (ZOH) Reconstruction

1 0.8
e(t) u(k)
0.8
e(k) 0.6 u(t)
0.6
0.4
0.4
0.2
0.2

0 0
e

u
-0.2
-0.2
-0.4
-0.4
-0.6
-0.6
-0.8

-1 -0.8
0 1 2 3 4 5 0 1 2 3 4 5
t t

Discrete-time signals are often interpolated with “staircase” (piecewise-constant)


functions. Discrete instants are points where the function changes its value.
Reconstruction of Signals From Samples: Aliasing
• Let 𝑥𝑥(𝑡𝑡) = sin(𝜔𝜔𝑡𝑡) (on a sufficiently long but final interval).
• Sampled signal: 𝑥𝑥(𝑘𝑘) = sin(𝜔𝜔𝑘𝑘𝑘𝑘) = sin((𝜔𝜔 − 2𝜋𝜋/𝑇𝑇)𝑘𝑘𝑘𝑘)
𝟐𝟐𝟐𝟐 𝟒𝟒𝟒𝟒
• Frequencies 𝝎𝝎, 𝝎𝝎 − , 𝝎𝝎 − ,… give the same DT sequence!
𝑻𝑻 𝑻𝑻

• Graphically: sampling a high-frequency signal, you will see something


slowly changing as a result.

x(k)
x(t)
t (s)

• This effect is called aliasing (superposition of frequencies): two signals


2𝜋𝜋
sin 𝜔𝜔𝑡𝑡 + sin (𝜔𝜔 − )𝑡𝑡 and 2sin 𝜔𝜔𝑡𝑡 after sampling become same!
𝑇𝑇

• You have no chance to recover a polyharmonic signal from samples,


unless its frequencies are concentrated within in a band of width
2𝜋𝜋/𝑇𝑇. Usually, we work with the band [−𝜋𝜋/𝑇𝑇, 𝜋𝜋/𝑇𝑇].
Fourier Integral – Generalization of Polyharmonic Signals
• In signal processing, the signals can be defined for all 𝑡𝑡 ∈ ℝ (and this
variable need not even be time) and have finite energy

• Such signals, admit a continuous-time Fourier transform:

• The inverse transform:

 𝑥𝑥(𝑡𝑡) is written as a superposition of harmonic signals 𝑒𝑒𝑗𝑗𝜔𝜔𝑡𝑡 =


cos(𝜔𝜔𝑡𝑡) + 𝑗𝑗𝑗𝑗𝑗(𝜔𝜔𝑡𝑡) of all possible frequencies;

 𝑋𝑋(𝑗𝑗𝜔𝜔) is the weight of the harmonic component with frequency ω.

 Polyharmonic signals: degenerate case - spectrum is discrete,


integral reduces to a finite sum.
Whittaker-Nyquist-Shannon(-Kotelnikov) Theorem
Sampling Theorem
Let 𝑥𝑥(𝑡𝑡) be a continuous-time signal with 𝑿𝑿 𝒋𝒋𝒋𝒋 = 𝟎𝟎 for 𝝎𝝎 ≥ 𝑩𝑩,
where 𝑋𝑋(𝑗𝑗𝜔𝜔) is the continuous-time Fourier Transform of 𝑥𝑥(𝑡𝑡).

Let 𝑥𝑥(𝑘𝑘) = 𝑥𝑥(𝑘𝑘𝑘𝑘) be the discrete-time signal obtained from 𝑥𝑥(𝑡𝑡) using
a sampling frequency 𝝎𝝎𝒔𝒔 = 𝟐𝟐𝝅𝝅/𝑻𝑻.

Then, 𝑥𝑥(𝑡𝑡) is uniquely determined by its samples 𝑥𝑥(𝑘𝑘) if 𝝎𝝎𝒔𝒔 ≥ 𝟐𝟐𝟐𝟐

• 𝜔𝜔𝑁𝑁 = 𝜔𝜔𝑠𝑠/2 = 𝜋𝜋/𝑇𝑇 is sometimes called the Nyquist frequency.


• For a unique reconstruction, the signal should have no spectrum
outside the range −𝜔𝜔𝑁𝑁 , 𝜔𝜔𝑁𝑁 - same as for finite sums of harmonics!
Remarks To Sampling Theorem
For a finite-time signal, the spectrum can never be ideally zero
𝑿𝑿(𝒋𝒋𝒋𝒋) ≈ 𝟎𝟎 for 𝝎𝝎 ≥ 𝑩𝑩

The formula for the signal reconstruction is thus also approximate!!!

Obviously, you cannot keep all values 𝑥𝑥(𝑘𝑘) = 𝑥𝑥(𝑘𝑘𝑘𝑘) in memory, so


we make the WNS formula even less accurate

Finally, don’t forget that A/D converter also truncates data (real
numbers are transformed to float, double, long double etc.)
So, practically the ideal reconstruction is impossible, however, the
quality of signal recovery can indeed be very high!
An Illustration

 continuous-time signal

 Fourier transform

𝑟𝑟𝑟𝑟𝑟𝑟
𝐵𝐵 = 17 , 𝜔𝜔𝑠𝑠 ≥ 2𝐵𝐵, 𝑇𝑇 ≤ 2𝜋𝜋/𝜔𝜔𝑠𝑠 = 𝜋𝜋/𝐵𝐵 = 0.185 𝑠𝑠
𝑠𝑠
Applying a Naïve Reconstruction (ZOH)
B=17 rad/s, ωs ≥ 2B  T ≤ 0.185 s

In practice, we usually apply ZOH to reconstruct signals (sinc is more difficult to


compute, and, anyway we cannot compute the infinite sum). The result is nice!

Formally, full information little loss of visible loss of


maintained (for ZOH, the information information
approximation is still good)!
Choice of Sampling Time in Control System (Recommendation)
ωs ≥ 2B
• B is approximated by a cutoff
frequency (it is assumed that the
closed-loop system will filter out
sinusoids of larger frequency)

• Usually, the cutoff frequency


corresponds to (-3 dB) decrease
– tradition of electronics

• Unfortunately, sampling time is often prescribed by hardware designers – you cannot


change it.
• In this case, you need to modify your Bode plot to satisfy this condition – loop shaping
techniques (not considered in this course).
• On the other hand, remember that reconstruction of signals is not our goal of control.
 We typically want to have output of DT controller close to CT controller, but ideal
recovery is unneeded!
 Aliasing is undesirable in the sense that you may fail to distinguish high-frequency
signals (usually, noise) and low-frequency signals (references and other useful
signals), however, it can also be unimportant in some problems (e.g., stabilization).
Digital Control: How to Redesign a CT System to DT
• Discrete-time control system are often obtained via redesign of
continuous-time controller.
• Plants are typically continuous-time (vehicles, robots, chemical reactors
etc.), so it is much easier to perform a CT design first.

1. Design of a continuous-time controller 𝐶𝐶𝐶𝐶𝐶𝐶(𝑠𝑠). This is what the main


part of our course was about. Continuous-time design is often
simpler and more convenient.
2. Discretize of the controller: 𝐶𝐶𝐶𝐶𝐶𝐶 𝑠𝑠 → 𝐶𝐶(𝑧𝑧). Many different discrete-
time approximations, Euler’s forward method is the simplest.
3. Verify the design using the discrete-time analysis and/or numerical
simulation.

• The discrete-time controller is implemented on the real system


to be controlled as follows:
Discretization of Dynamical Systems – Many Methods
Discretization methods: can be time-domain or frequency-domain.
Details in the file for additional reading (lectures from IMT Lucca)

Time-domain: correspondence between the solutions of continuous-time


and discrete-time systems on some class of inputs.
Frequency-domain: a certain correspondence between TFs.
• Exact solution of ODE (with different classes of inputs):
 Sequence of pulses  impulse-invariant discretization (IMP)
 Staircase input  zero-order hold (ZOH)
 Piecewise-linear signal  first-order hold (FOH)
• Numerical approximation of ODE (allows frequency-domain formulation):
 Forward Euler
 Backward Euler
 Tustin (or trapezoidal rule)
Details can be found in the additional file.
• Pole-zero matching (fully in frequency-domain, similarity of TFs):
 Matched pole-zero (MPZ)
 Modified matched pole-zero (modified MPZ)
Discretization of Dynamical Systems – Many Methods

• Discretization using Matlab:

>> C = c2d(CCT, T, METHOD)

METHOD:
'zoh' Zero-order hold
'foh' First-order hold
'imp' Impulse-invariant
'tustin' Tustin
'prewarp' Tustin approximation with frequency pre-warping
'matched' Matched pole-zero

The default is 'zoh' when METHOD is omitted.


The Only Method We Learn (Simplest): Euler’s Forward
• Forward Euler discretization method:
 The time derivative is approximated by the difference quotient:
𝒚𝒚 (𝒌𝒌 + 𝟏𝟏)𝑻𝑻 − 𝒚𝒚 𝒌𝒌𝒌𝒌
𝒚𝒚̇ 𝒌𝒌𝑻𝑻 ≅
𝑻𝑻

where T is the sampling period.


 Do you guess how to approximate the second derivative?
𝒚𝒚̇ (𝒌𝒌+𝟏𝟏)𝑻𝑻 −𝒚𝒚̇ 𝒌𝒌𝒌𝒌 𝒚𝒚 (𝒌𝒌+𝟐𝟐)𝑻𝑻 −𝟐𝟐𝟐𝟐 𝒌𝒌+𝟏𝟏 𝑻𝑻 +𝒚𝒚(𝒌𝒌𝒌𝒌)
𝒚𝒚̈ 𝒌𝒌𝑻𝑻 ≅ ≅
𝑻𝑻 𝑻𝑻

 And third derivative? Just apply the previous formula to the derivative (to
be discussed in relation to exercise).
 In reality, discretization can be done in frequency domain by applying a
formal rule (a bit later, based on z-transform).
 On Github, a function c2d_euler is available (not included into official
Control Systems Toolbox!), written by Dr. Tamas Kis
https://www.mathworks.com/matlabcentral/fileexchange/90267-euler-c2d-
transformation-c2d_euler
𝒚𝒚 𝒌𝒌𝑻𝑻 − 𝒚𝒚 (𝒌𝒌 − 𝟏𝟏)𝑻𝑻
• Backward Euler is sometimes used: 𝒚𝒚̇ 𝒌𝒌𝑻𝑻 ≅
𝑻𝑻
Example: Travelling Mass
Traveling mass subject to friction

y(t) : mass speed


y(t)
My (t ) = −β y(t) + u(t)
M u(t)
contribution of all (linear)
frictions acting on the mass

• This simple model is commonly used for the design of cruise control
systems.
• Assume that we measure only sampled values of the input u(k)=u(kT) and
are interested only in the sampled output y(k)=y(kT) (at other time, we have
no measurements)
• We can derive the (approximate) model of such a discretized system
(defined for k=1,2,…):
 Tβ  T
y(k) = 1 −  y(k − 1) + u(k − 1)
 M M
Euler’s Method for State Equation

x (t ) = f [x(t ), u (t ); t ] 𝒙𝒙 𝒌𝒌 + 𝟏𝟏 = 𝒙𝒙 𝒌𝒌 + 𝑻𝑻𝑻𝑻 𝒙𝒙(𝒌𝒌), 𝒖𝒖(𝒌𝒌); 𝒌𝒌


y (t ) = h[x(t ), u (t ); t ] 𝒚𝒚(𝒌𝒌) = 𝒉𝒉 𝒙𝒙(𝒌𝒌), 𝒖𝒖(𝒌𝒌); 𝒌𝒌

𝑥𝑥(𝑡𝑡)
̇ = 𝐴𝐴𝐴𝐴(𝑡𝑡) + 𝐵𝐵𝐵𝐵(𝑡𝑡) 𝒙𝒙(𝒌𝒌 + 𝟏𝟏) = (𝑰𝑰 + 𝑻𝑻𝑻𝑻)𝒙𝒙(𝒌𝒌) + 𝑻𝑻𝑩𝑩𝑩𝑩(𝒌𝒌)
𝑦𝑦(𝑡𝑡) = 𝐶𝐶𝐶𝐶(𝑡𝑡) + 𝐷𝐷𝐷𝐷(𝑡𝑡) 𝒚𝒚(𝒌𝒌) = 𝑪𝑪𝑪𝑪(𝒌𝒌) + 𝑫𝑫𝑫𝑫(𝒌𝒌)

Big disadvantage of the Euler forward method: for large sampling period, the stability can
be destroyed. For instance, a system with exponentially decaying solution may acquire
unbounded solutions, as shown by the example:

𝑥𝑥̇ = −𝑥𝑥, 𝑇𝑇 = 3 𝒙𝒙 𝒌𝒌 + 𝟏𝟏 = −𝟐𝟐𝒙𝒙(𝒌𝒌)


But: for small periods, everything will be fine. How small should it be?

Simple exercise: all eigenvalues must be inside the unit disk!


Be Careful: Non-Causality!!!
In discrete-time, it is very easy to write an equation that formally has a solution
yet cannot be implemented in hardware or software to any physical or logical
system. The reason is non-causality, or dependence on the future.
• A system is causal if its output is a function of only the current and previous
samples.
• Don’t confuse 2 words: causal and casual!
• Performing discretization, check that your discrete-time system is causal
• Example
 Backward Difference: 𝑦𝑦(𝑘𝑘) = 𝑢𝑢(𝑘𝑘) − 𝑢𝑢(𝑘𝑘 − 1)
 Equivalent notation: 𝑦𝑦 𝑘𝑘 + 1 = 𝑢𝑢 𝑘𝑘 + 1 − 𝑢𝑢(𝑘𝑘)
• Counter example, non-causal system
 Forward Difference: 𝑦𝑦 𝑘𝑘 = 𝑢𝑢 𝑘𝑘 + 1 − 𝑢𝑢(𝑘𝑘)
 Can arise if you discretize derivatives via forward Euler (backward
Euler is free of this problem, see examples in the additional file). This is
illustrated by the PID controller discretization.
Be Careful: Non-Causality!!!
Discretizing a “standard” PD or PID controller by forward Euler’s method,
one gets a non-causal system because of the derivative term!

This is an additional (not the main) reason to “smoothen” the


derivative, as we discussed in the lecture on PID controller (L12)
The Correspondence Between TFs

𝑥𝑥(𝑡𝑡)
̇ = 𝐴𝐴𝐴𝐴(𝑡𝑡) + 𝐵𝐵𝐵𝐵(𝑡𝑡) 𝑥𝑥(𝑘𝑘 + 1) = (𝐼𝐼 + 𝑇𝑇𝑇𝑇)𝑥𝑥(𝑘𝑘) + 𝑇𝑇𝐵𝐵𝐵𝐵(𝑘𝑘)
𝑦𝑦(𝑡𝑡) = 𝐶𝐶𝐶𝐶(𝑡𝑡) + 𝐷𝐷𝐷𝐷(𝑡𝑡) 𝑦𝑦(𝑘𝑘) = 𝐶𝐶𝐶𝐶(𝑘𝑘) + 𝐷𝐷𝐷𝐷(𝑘𝑘)

• Same rules applies to all LTI systems!


• If you know the TF of original CT system and sampling period, the TF of
resulting DT system is found by replacing 𝑠𝑠 by (𝑧𝑧 − 1)/𝑇𝑇.
• Hence, the forward Euler method can be applied in frequency domain
without writing the time-domain equations.
• Try to apply it to PID controller’s TF and check that the discrete-time TF
will be same.
Exercise: How Does The Backward Euler Alter the TF?

𝑥𝑥(𝑡𝑡)
̇ = 𝐴𝐴𝐴𝐴(𝑡𝑡) + 𝐵𝐵𝐵𝐵(𝑡𝑡) ?
𝑦𝑦(𝑡𝑡) = 𝐶𝐶𝐶𝐶(𝑡𝑡) + 𝐷𝐷𝐷𝐷(𝑡𝑡)

• Hint: you will need to solve the linear equation to find 𝑥𝑥(𝑘𝑘) as a function
of 𝑥𝑥(𝑘𝑘 − 1) and 𝑢𝑢(𝑘𝑘).

You might also like