Numerical Lab - Simulation with Noise and Quantization
In questa pagina 3
This note follows the second numerical laboratory sheet of the course. It has two parts. Exercise 4 is about discrete-time approximations of the derivative, needed to get a speed estimate from an encoder position measurement. Exercises 5 and 6 simulate the sampled-data speed control of a DC motor, first in the Control System Toolbox (CST) and then in Simulink with the non-idealities of a real digital loop (DAC, encoder, saturation). The theory of discretization is in Digital Control SystemsA digital control system replaces the analog controller with a processing unit interfaced to the plant through an A/D converter (sampling plus quantization) and a D/A converter (zero-order hold), and neglecting quantization it becomes a sampled-data system that can be designed by emulation or directly in discrete time.Digital Control Systems → and Sampled-Data Control Design - Emulation and Direct DesignA digital control system is a continuous-time plant controlled by a digital controller, and it can be designed either by emulation (design C(s) in continuous time then discretize it) or by direct digital design (exactly discretize the plant and design in discrete time), with poles mapped by z = e^{sT}.Sampled-Data Control Design - Emulation and Direct Design →; the motor model is in Modeling a DC ServomotorA permanent-magnet DC motor is modeled by an electrical equation with a back-EMF term and a mechanical equation with inertia and viscous friction, a gearbox just adds the load inertia and friction divided by N squared on the motor side, and for the laboratory servomotor (voltage driver plus gearmotor plus disc) this gives a transfer function from input voltage to load angle that reduces to a first-order lag times an integrator.Modeling a DC Servomotor →; the non-idealities are discussed in Non-Idealities in a Control Loopmodels and control consequences of the main non-idealities of a feedback loop, namely sensor bias, noise, quantization and limited bandwidth, actuator saturation and limited bandwidth, time delays with Pade approximations, disturbances and parameter or model uncertainties.Non-Idealities in a Control Loop →.
Exercise 4 - Discrete-time derivative filters
The continuous-time filters
The ideal derivative is . It is not physically realizable (more zeros than poles, gain growing with frequency), so two "real derivative" filters were introduced in the previous session:
with
is the derivative followed by a first-order low-pass filter with time constant ; is the derivative followed by a second-order low-pass (natural frequency , damping ). The cut-off is in both cases. All the work is to be done using only CST routines, with sampling time .
Tasks
- Ideal derivative. Discretize with Forward Euler (FE), Backward Euler (BE) and Tustin (TU). Compare the Bode plots of the three discrete filters with that of the continuous ideal derivative. Questions: which discretized filters are physically implementable (i.e. have a proper or strictly proper transfer function)? Which one approximates the magnitude response best? And the phase?
- Repeat point 1 with the real derivative .
- Repeat point 1 with the real derivative .
- -step backward difference. A generalization of BE is With draw the Bode plot of the discrete filter, compare it with the continuous ideal derivative, and compare its high-frequency attenuation with that of the BE discretization of obtained in point 1.
- Averaged incremental ratios. Another way to approximate the derivative is to average the incremental ratios computed over the last steps. For : where Combining the two expressions (the terms in cancel because , and the remaining coefficients are ) gives which is the output of the discrete-time filter Draw its Bode plot and compare it with the continuous ideal derivative.
- Noisy ramp. Take all the discrete filters of points 1-5 and simulate their response to
i.e. a linear ramp sampled at , plus a noise that is a random process with uniform distribution over , . For the noise use the
randroutine. Show the filter responses on one MATLAB figure and evaluate the variance of the output noise, neglecting the initial transient. Which filter produces the least noisy output?
Remarks for solving
- The exact derivative of the ramp is the constant , so after the transient every filter output should settle around and the deviation is the filtered noise. That is why the variance is evaluated after the transient has died out.
- Discretization substitutions (see Sampled-Data Control Design - Emulation and Direct DesignA digital control system is a continuous-time plant controlled by a digital controller, and it can be designed either by emulation (design C(s) in continuous time then discretize it) or by direct digital design (exactly discretize the plant and design in discrete time), with poles mapped by z = e^{sT}.Sampled-Data Control Design - Emulation and Direct Design →): FE , BE , TU . Applied to they give has one zero and no pole: it is not proper (it would need to produce the output at step ), hence not implementable. and are proper.
- Two factorizations explain the comparisons (they follow from the formulas above): , so is the BE derivative cascaded with a moving average over samples, which gives extra attenuation at high frequency; and , so is the BE derivative cascaded with the smoothing filter whose DC gain is .
- A standard property, not stated in the sheet: a uniform noise on has variance , a useful check on the numerical variance of the input noise before filtering.
- Bode plots and the meaning of magnitude and phase: Frequency Response of BIBO Stable SystemsFor a BIBO stable system W(s) driven by a sinusoid of angular frequency w, the output converges to a sinusoid of the same frequency whose amplitude is multiplied by |W(jw)| and whose phase is shifted by the angle of W(jw); the result extends to cosines and to sums of sinusoids.Frequency Response of BIBO Stable Systems →.
Exercise 5 - Discrete-time speed control with the CST
The plant and the loop
The sampled-data speed control system of Fig. 1 of the sheet contains the DC motor with transfer functions from the armature voltage to the shaft speed and to the position :
Block diagram of Fig. 1 (as described by the sheet):
d(t)
|
w*[k] e[k] v P(s)
---->(+)--> C(z) --u[k]--> ZOH --u(t)-->(+)--ua(t)--> [ P'(s) ]--w(t)--> [ 1/s ]--th(t)--+-->
^- |
| |
+---- wm[k] <---- H(z) <---- thm[k] <---(+)<---- sampler Ts <----------------------+
^
|
n[k]- : transfer function of the discrete-time controller (input: tracking error ; output: command ).
- : discrete-time "real" derivative filter used to get a speed estimate from the position measurement .
- Inputs: speed reference; load disturbance (e.g. a voltage equivalent of a disturbance torque applied to the motor); output noise of the position sensor.
- The ZOH block is a Zero-Order Hold interpolator. The sampling time of the controller is .
Task 1 - exact discretization and root locus of a P controller
Discretize with the exact method (c2d with 'zoh' as the discretization method) to obtain the discrete-time system of Fig. 2, where the plant becomes (the integrator giving the position is represented by ).
Take a purely proportional controller with gain and, as speed filter , the FE discretization of the filter (the sheet says "defined in the exercise 5", but the filter is the one defined in exercise 4).
- Draw the root locus of the control system with input and output as goes from to . Note: for the root locus the loop transfer function must be considered. See The Root LocusThe positive root locus is the set of closed-loop poles of the loop with a proportional controller C(s)=K, K>=0, as K varies; it consists of n branches that start at the poles of G(s) and end at its zeros or at infinity along asymptotes, and four sketching rules (real-axis rule, asymptotes with centroid, multiple points) let one draw it and read off stability and transient requirements.The Root Locus →.
- Identify the critical gain beyond which the control system becomes unstable.
Task 2 - step response with
Set and determine the responses of the actual speed , the measured speed and the command to a speed step reference, over a time range. Show the results on a MATLAB figure and determine the step-response parameters (rise time, settling time at , overshoot). Question: is the P controller able to reach zero steady-state tracking error for a step reference?
Task 3 - PI controller
Consider the discrete-time PI controller
(the sheet writes on the left, but the variable is ). The integral action is a discrete accumulator (a FE integrator) with integral gain . Repeat points 1 and 2. Question: is the PI controller able to reach zero steady-state tracking error? (Reasoning on the loop: with a pole of at the loop gain is infinite at DC, so a constant reference is tracked exactly, while a P controller leaves a finite error.)
Exercise 6 - Simulation in Simulink
Reconsider the loop of Fig. 1 and build it in Simulink with the discrete-time P controller of Exercise 5 point 2. To make the simulation more realistic two hardware non-idealities are modelled.
DAC model (Fig. 3a)
The continuous-time voltage command is generated by a Digital-to-Analog Converter with output range and bits resolution. In Simulink the chain is: Quantizer -> Saturation -> Zero-Order Hold:
Quantizerwith step (span divided in steps);Saturationwith levels ;Zero-Order Holdwith sampling time .
u[k] [V] --> [Quantizer1] --> [Saturation] --> [Zero-Order Hold1] --> u(t) [V]
(inside the "Digital to Analog Converter (DAC)" block)Encoder model (Fig. 3b)
The position measurement comes from an incremental encoder with (pulses per rotation):
Zero-Order Hold: ideal sampler with sampling time ;Quantizerwith step (quantizer input expressed in rad);Gainequal to , to obtain the encoder output in pulses.
th(t) [rad] --> [Zero-Order Hold] --> [Quantizer] --> [Gain -K-] --> thm[k] [pulses]
(inside the "Incremental encoder" block)Units
The encoder output must be brought to the same units as the reference before computing the tracking error , and the controllers of Exercise 5 need in . Example with the reference in :
- the encoder output (pulses) goes directly into the speed filter , giving a speed in ;
- multiply by to convert to ;
- subtract from the reference to get in ;
- multiply by to convert to and feed .
Simulation
Use an appropriate solver (variable-step, or fixed-step with a step smaller than ). Apply a step speed reference of amplitude at and a disturbance of amplitude at . On a MATLAB figure plot:
- plot 1: actual speed , measured speed and reference , all in ;
- plot 2: voltage command in .
Question: does the P controller guarantee perfect rejection of the constant disturbance ?
Point 2 - PI controller
Repeat point 1 with the PI controller of Exercise 5 point 3. Questions: does the PI controller guarantee perfect rejection of the constant disturbance? Note that the voltage command saturates during the step-response transient: compare rising and settling times with those of Exercise 5 point 3, where no saturation was considered. (The saturation is exactly the situation that anti-windup addresses: see Speed PI Control Improvements for a DC ServomotorLab activity 4 improves the speed PI control of a DC servomotor in two ways: feedforward compensation of the reference (inertia, friction and back-EMF terms computed from the motor model and a known speed profile) and anti-windup of the integrator when the actuator saturates.Speed PI Control Improvements for a DC Servomotor →.)
Versione ripasso
Exercise 4 - derivative filters (, only CST routines)
- Ideal ; real derivatives , with , , .
- Discretize with FE , BE , TU ; compare Bode plots; FE of is not proper, so not implementable.
- () = BE derivative times a moving average: more high-frequency attenuation than BE.
- , from averaging the incremental ratios over the last steps ( cancels).
- Noisy ramp , uniform on (
rand): compare output-noise variance after the transient.
Exercise 5 - CST (, , , )
c2dwith'zoh': exact ; position branch ; = FE of .- P controller: root locus of the loop transfer function, critical ; then , step over : rise time, settling time, overshoot; P leaves a finite steady-state error.
- PI: gives zero error to a step (pole at ).
Exercise 6 - Simulink
- DAC: Quantizer , Saturation , ZOH .
- Encoder (): ZOH , Quantizer , Gain .
- Units: pulses/s gives rpm; rpm error gives rad/s for .
- Reference step at , disturbance at ; plots: speeds in rpm and .
- Questions: disturbance rejection of P versus PI; with PI the command saturates, so rise and settling times get worse than without saturation.
Typical error: forgetting the unit conversions (pulses, rpm, rad/s) before the controller, so the loop gain is wrong by factors of or .
Esercizio 4, passi:
- Ideale discretizzato con FE, BE, TU: confronto dei diagrammi di Bode con la derivata continua; FE non è propria, quindi non è realizzabile; BE e TU sì.
- Stessa analisi per e .
- con : è la derivata BE in cascata con una media mobile su campioni, quindi attenua di più alle alte frequenze.
- : il termine si annulla, i coefficienti restano , , , divisi per .
- Rampa con rumore , uniforme su con : la varianza del rumore di uscita si valuta dopo il transitorio. Una uniforme su ha varianza , utile come controllo.
Esercizio 6, Simulink:
- DAC: quantizzatore con V, saturazione a V, ZOH con ms (catena Quantizer, Saturation, ZOH).
- Encoder da ppr: ZOH con , quantizzatore con rad, guadagno per avere impulsi.
- Catena delle unità: impulsi/s = rpm; errore in rpm = rad/s, ingresso di .
- Evento: gradino di rpm a s, disturbo V a s. Figure: velocità in rpm (reale, misurata, riferimento) e in V.
- Domande: il P respinge il disturbo costante? Il PI sì, ma satura nel transitorio e i tempi di salita e assestamento peggiorano rispetto al caso senza saturazione.
Errori tipici:
- Usare il PI senza anti-windup con saturata: l'integrale si carica oltre il limite.
- Scrivere il controllore PI in invece che in quando la variabile è .
- Passo del solver a passo fisso maggiore o uguale a .