Embedded Systems Martina Maggio – Lecture 04: continuous- to discrete-time 1 / 11 Continuous-Time Linear Time-Invariant System Process u (t) y (t) xΜ (t) = A x (t) + B u (t) π«βΆ{ y (t) = C x (t) + D u (t) Continuous-Time Linear Time-Invariant System Process u (t) y (t) xΜ (t) = A x (t) + B u (t) π«βΆ{ y (t) = C x (t) + D u (t) Continuous-Time Linear Time-Invariant System Process u (t) y (t) xΜ (t) = A x (t) + B u (t) π«βΆ{ y (t) = C x (t) + D u (t) Continuous-Time Linear Time-Invariant System Process u (t) y (t) xΜ (t) = A x (t) + B u (t) π«βΆ{ y (t) = C x (t) + D u (t) We measure the output every π time units (sample) Continuous-Time Linear Time-Invariant System Process u (t) y (t) xΜ (t) = A x (t) + B u (t) π«βΆ{ y (t) = C x (t) + D u (t) We apply a new input every π time units (hold) We measure the output every π time units (sample) 2 / 11 Sampling s (t) t Sampling s (t) Sampling Period π t Sampling s (t) k=0 Sampling Period π k=1 k=2 k=3 t Sampling s (t) k=0 Sampling Period π k=1 k=2 k=3 s (0) = s [0] t Sampling s (t) k=0 Sampling Period π k=1 k=2 k=3 s (π) = s [1] s (0) = s [0] t Sampling s (t) k=0 Sampling Period π k=1 k=2 k=3 s (π) = s [1] s (0) = s [0] s (2π) = s [2] t Sampling s (t) k=0 Sampling Period π k=1 k=2 k=3 s (π) = s [1] s (0) = s [0] s (2π) = s [2] s (3π) = s [3] t Sampling s (t) k=0 Sampling Period π k=1 k=2 k=3 s (k π) = s [k] s (π) = s [1] s (0) = s [0] s (2π) = s [2] s (3π) = s [3] t 3 / 11 Sampling and Modeling From continuous- to discrete-time (linear time-invariant) models We would like to take our continous-time model and transform it into a discrete-time equivalent model, that describes the behavior of the system at the sampling instants {k, k − 1, … , 0} xΜ (t) = A x (t) + B u (t) → ? βββ y (t) = C x (t) + D u (t) Discrete-Time Model ββ΄β΄β΄β΄β΄β΄β΄β΄ββ΄β΄β΄β΄β΄β΄β΄β΄β Continuous-Time Model 4 / 11 Sampling and Modeling From continuous- to discrete-time (linear time-invariant) models xΜ (t) = A x (t) + B u (t) y (t) = C x (t) + D u (t) The solution1 for this system is t x (t) = e A(t−0) x (0) + ∫ e A(t−π) B u (π) dπ 0 and this gives t y (t) = C e A(t−0) x (0) + ∫ C e A(t−π) B u (π) dπ + D u (t) 0 1 For the full derivation, see http://control.ucsd.edu/mauricio/courses/mae280a/lecture5.pdf 5 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 6 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) 6 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) B u (π) dπ kπ 6 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) B u (π) dπ kπ t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) dπ B u (k π) kπ 6 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) B u (π) dπ kπ t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) dπ B u (k π) kπ 0 x (t) = e A (t−k π) x (k π) + ∫ −e Av dv B u (k π) t−k π 6 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) B u (π) dπ kπ t x (t) = e A (t−k π) x (k π) + ∫ e A(t−π) dπ B u (k π) kπ 0 x (t) = e A (t−k π) x (k π) + ∫ −e Av dv B u (k π) t−k π t−k π x (t) = e A (t−k π) e Av dv B u (k π) x (k π) + ∫ 0 6 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t−k π A (t−k π) x (t) = e x (k π) + ∫ e Av dv B u (k π) βββ 0 Φ(t,k π) ββ΄β΄β΄ββ΄β΄β΄β Γ(t,k π) 7 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t−k π A (t−k π) x (t) = e x (k π) + ∫ e Av dv B u (k π) βββ 0 Φ(t,k π) ββ΄β΄β΄ββ΄β΄β΄β Γ(t,k π) 2. Impose periodic sampling, t = (k + 1) π 7 / 11 Sampling and Modeling Assumption: in between sampling [ ) instants, we keep the value of u constant (we hold u), i.e., ∀t ∈ k π, (k + 1) π , u (t) = u [k] 1. Solve the equation from time k π to time t (with constant u) t−k π A (t−k π) x (t) = e x (k π) + ∫ e Av dv B u (k π) βββ 0 Φ(t,k π) ββ΄β΄β΄ββ΄β΄β΄β Γ(t,k π) 2. Impose periodic sampling, t = (k + 1) π k π+π−k π ( ) A (k π+π−k π) x (k + 1) π = e x (k π) + ∫ e Av dv B u (k π) ββ΄β΄ββ΄β΄β ( ) 0 Φ (k+1) π,k π β β΄β΄β΄β΄ β β΄β΄β΄β΄ β ( ) Γ (k+1) π,k π 7 / 11 Sampling and Modeling From continuous- to discrete-time (linear time-invariant) models k π+π−k π ( ) A (k π+π−k π) x (k + 1) π = e x (k π) + ∫ e Av dv B u (k π) ββ΄β΄ββ΄β΄β ( ) 0 Φ (k+1) π,k π β β΄β΄β΄β΄ β β΄β΄β΄β΄ β ( ) Γ (k+1) π,k π 8 / 11 Sampling and Modeling From continuous- to discrete-time (linear time-invariant) models k π+π−k π ( ) A (k π+π−k π) x (k + 1) π = e x (k π) + ∫ e Av dv B u (k π) ββ΄β΄ββ΄β΄β ( ) 0 Φ (k+1) π,k π β β΄β΄β΄β΄ β β΄β΄β΄β΄ β ( ) Γ (k+1) π,k π We can rewrite this as π ( ) Aπ x (k + 1) π = e x (k π) + ∫ e Av dv B u (k π) βββ 0 Φ(π) ββ΄β΄ββ΄β΄β Γ(π) 8 / 11 Sampling and Modeling From continuous- to discrete-time (linear time-invariant) models π ( ) Aπ x (k + 1) π = e x (k π) + ∫ e Av dv B u (k π) βββ 0 Φ(π) ββ΄β΄ββ΄β΄β Γ(π) Using the discrete-time notation, we can write x [k + 1] = Φ (π) x [k] + Γ (π) u [k] π where Φ (π) = e A π and Γ (π) = ∫0 e Av dv B And calculate the output as y [k] = C x [k] + D u [k] 9 / 11 Sampling and Modeling From continuous- to discrete-time (linear time-invariant) models It is possible to compute Φ and Γ simultaneously, using the formula [ Φ Γ ] = eSπ 0 I where S = [ A B ] 0 0 The matrix exponential can be computed using the exp Julia or expm Matlab function 10 / 11 Sampling Period Choice The sampling period should be related to the physics of your system: ⨳ If your system state vector changes very fast you will need very frequent samples to properly reconstruct the changes ⨳ If the changes are very slow you can afford sampling less frequently As a rule of thumb, you would like to have between 4 and 20 samples during the rise time of your step response, or alternatively π ∈ (0.1 βπn , 0.6 βπn ) where πn is the natural frequency of your system (max absolute value of the eigenvalues of A) 11 / 11