Salta al contenuto
Note per Studenti Numerical Lab - Simulation with Noise and Quantization Report

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 H(s)=sH(s)=s. It is not physically realizable (more zeros than poles, gain growing with frequency), so two "real derivative" filters were introduced in the previous session:

H1(s)=sTs+1,H2(s)=ωc2 ss2+2δωcs+ωc2H_1(s)=\frac{s}{Ts+1},\qquad H_2(s)=\frac{\omega_c^2\,s}{s^2+2\delta\omega_c s+\omega_c^2}

with

T=12π 50,ωc=2π 50,δ=12.T=\frac{1}{2\pi\,50},\qquad \omega_c=2\pi\,50,\qquad \delta=\frac{1}{\sqrt 2}.

H1H_1 is the derivative followed by a first-order low-pass filter with time constant TT; H2H_2 is the derivative followed by a second-order low-pass (natural frequency ωc\omega_c, damping δ\delta). The cut-off is 50 Hz50\,\text{Hz} in both cases. All the work is to be done using only CST routines, with sampling time Ts=1 msT_s=1\,\text{ms}.

Tasks

  1. Ideal derivative. Discretize H(s)=sH(s)=s 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?
  2. Repeat point 1 with the real derivative H1(s)H_1(s).
  3. Repeat point 1 with the real derivative H2(s)H_2(s).
  4. NN-step backward difference. A generalization of BE is H3(z)=1−z−NN Ts.H_3(z)=\frac{1-z^{-N}}{N\,T_s}. With N=4N=4 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 H(s)H(s) obtained in point 1.
  5. Averaged incremental ratios. Another way to approximate the derivative is to average the incremental ratios computed over the last NN steps. For N=4N=4: du(kTs)dt≈14(u[k]−u∗1.5 Ts+u[k−1]−u∗0.5 Ts−u[k−2]−u∗0.5 Ts−u[k−3]−u∗1.5 Ts)\frac{du(kT_s)}{dt}\approx\frac14\left(\frac{u[k]-u^*}{1.5\,T_s}+\frac{u[k-1]-u^*}{0.5\,T_s}-\frac{u[k-2]-u^*}{0.5\,T_s}-\frac{u[k-3]-u^*}{1.5\,T_s}\right) where u∗=14(u[k]+u[k−1]+u[k−2]+u[k−3]),u[k]≜u(kTs).u^*=\frac14\big(u[k]+u[k-1]+u[k-2]+u[k-3]\big),\qquad u[k]\triangleq u(kT_s). Combining the two expressions (the terms in u∗u^* cancel because 11.5+10.5−10.5−11.5=0\tfrac{1}{1.5}+\tfrac{1}{0.5}-\tfrac{1}{0.5}-\tfrac{1}{1.5}=0, and the remaining coefficients are 14Ts⋅23, 14Ts⋅2, −14Ts⋅2, −14Ts⋅23\tfrac{1}{4T_s}\cdot\tfrac23,\ \tfrac{1}{4T_s}\cdot 2,\ -\tfrac{1}{4T_s}\cdot 2,\ -\tfrac{1}{4T_s}\cdot\tfrac23) gives du(kTs)dt≈16Ts(u[k]+3u[k−1]−3u[k−2]−u[k−3]),\frac{du(kT_s)}{dt}\approx\frac{1}{6T_s}\big(u[k]+3u[k-1]-3u[k-2]-u[k-3]\big), which is the output of the discrete-time filter H4(z)=16Ts(1+3z−1−3z−2−z−3).H_4(z)=\frac{1}{6T_s}\big(1+3z^{-1}-3z^{-2}-z^{-3}\big). Draw its Bode plot and compare it with the continuous ideal derivative.
  6. Noisy ramp. Take all the discrete filters of points 1-5 and simulate their response to u[k]=r[k]+n[k],r[k]=r(kTs)=25 kTs,u[k]=r[k]+n[k],\qquad r[k]=r(kT_s)=25\,kT_s, i.e. a linear ramp r(t)=25 tr(t)=25\,t sampled at t=kTst=kT_s, plus a noise n[k]n[k] that is a random process with uniform distribution over [−a,a][-a,a], a=0.001a=0.001. For the noise use the rand routine. 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

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 ua [V]u_a\,[\text{V}] to the shaft speed ω [rad/s]\omega\,[\text{rad/s}] and to the position ϑ [rad]\vartheta\,[\text{rad}]:

P′(s)=Ω(s)Ua(s)=kmTms+1,P(s)=Θ(s)Ua(s)=1s P′(s),km=5.2,Tm=0.03.P'(s)=\frac{\Omega(s)}{U_a(s)}=\frac{k_m}{T_m s+1},\qquad P(s)=\frac{\Theta(s)}{U_a(s)}=\frac1s\,P'(s),\qquad k_m=5.2,\quad T_m=0.03.

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]
  • C(z)C(z): transfer function of the discrete-time controller (input: tracking error e[k]e[k]; output: command u[k]u[k]).
  • H(z)H(z): discrete-time "real" derivative filter used to get a speed estimate ωm[k]\omega_m[k] from the position measurement ϑm[k]\vartheta_m[k].
  • Inputs: ω∗[k]\omega^*[k] speed reference; d[k]d[k] load disturbance (e.g. a voltage equivalent of a disturbance torque applied to the motor); n[k]n[k] output noise of the position sensor.
  • The ZOH block is a Zero-Order Hold interpolator. The sampling time of the controller is Ts=1 msT_s=1\,\text{ms}.

Task 1 - exact discretization and root locus of a P controller

Discretize P′(s)P'(s) with the exact method (c2d with 'zoh' as the discretization method) to obtain the discrete-time system of Fig. 2, where the plant becomes P(z)=P′(z) Tsz−1P(z)=P'(z)\,\frac{T_s}{z-1} (the integrator giving the position is represented by Tsz−1\frac{T_s}{z-1}).

Take a purely proportional controller with gain KPK_P and, as speed filter H(z)H(z), the FE discretization of the filter H2(s)H_2(s) (the sheet says "defined in the exercise 5", but the filter H2H_2 is the one defined in exercise 4).

Task 2 - step response with KP=KP∗/4K_P=K_P^*/4

Set KP=KP∗/4K_P=K_P^*/4 and determine the responses of the actual speed ω[k]\omega[k], the measured speed ωm[k]\omega_m[k] and the command u[k]u[k] to a 300 rpm300\,\text{rpm} speed step reference, over a 0.3 s0.3\,\text{s} time range. Show the results on a MATLAB figure and determine the step-response parameters (rise time, settling time at 5%5\%, 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

C(z)=U(z)E(z)=KP(1+100 Tsz−1)C(z)=\frac{U(z)}{E(z)}=K_P\left(1+100\,\frac{T_s}{z-1}\right)

(the sheet writes C(s)C(s) on the left, but the variable is zz). The integral action is a discrete accumulator Tsz−1\frac{T_s}{z-1} (a FE integrator) with integral gain KI=100 KPK_I=100\,K_P. 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 C(z)C(z) at z=1z=1 the loop gain is infinite at DC, so a constant reference is tracked exactly, while a P controller leaves a finite error.)

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 u(t)u(t) is generated by a Digital-to-Analog Converter with output range ±10 V\pm10\,\text{V} and 1616 bits resolution. In Simulink the chain is: Quantizer -> Saturation -> Zero-Order Hold:

  • Quantizer with step qDAC=20216−1 Vq_{\text{DAC}}=\dfrac{20}{2^{16}-1}\ \text{V} (span 20 V20\,\text{V} divided in 216−12^{16}-1 steps);
  • Saturation with levels ±10 V\pm10\,\text{V};
  • Zero-Order Hold with sampling time Ts=1 msT_s=1\,\text{ms}.
 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 ϑm[k]\vartheta_m[k] comes from an incremental encoder with 2000 ppr2000\ \text{ppr} (pulses per rotation):

  • Zero-Order Hold: ideal sampler with sampling time Ts=1 msT_s=1\,\text{ms};
  • Quantizer with step qenc=2π2000 radq_{\text{enc}}=\dfrac{2\pi}{2000}\ \text{rad} (quantizer input expressed in rad);
  • Gain equal to 20002π\dfrac{2000}{2\pi}, 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 ω∗[k]\omega^*[k] before computing the tracking error e[k]e[k], and the controllers of Exercise 5 need e[k]e[k] in rad/s\text{rad/s}. Example with the reference in rpm\text{rpm}:

  1. the encoder output (pulses) goes directly into the speed filter H(z)H(z), giving a speed in pulses/s\text{pulses/s};
  2. multiply by 602000\dfrac{60}{2000} to convert to rpm\text{rpm};
  3. subtract from the reference to get e[k]e[k] in rpm\text{rpm};
  4. multiply by 2π60\dfrac{2\pi}{60} to convert to rad/s\text{rad/s} and feed C(z)C(z).

Simulation

Use an appropriate solver (variable-step, or fixed-step with a step smaller than TsT_s). Apply a step speed reference of amplitude Aω=300 rpmA_\omega=300\,\text{rpm} at tω=0.1 st_\omega=0.1\,\text{s} and a disturbance d(t)d(t) of amplitude Ad=−3 VA_d=-3\,\text{V} at td=0.5 st_d=0.5\,\text{s}. On a MATLAB figure plot:

  • plot 1: actual speed ω(t)\omega(t), measured speed ωm[k]\omega_m[k] and reference ω∗[k]\omega^*[k], all in rpm\text{rpm};
  • plot 2: voltage command u(t)u(t) in V\text{V}.

Question: does the P controller guarantee perfect rejection of the constant disturbance d(t)d(t)?

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 u(t)u(t) 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 (Ts=1 msT_s=1\,\text{ms}, only CST routines)

  • Ideal H(s)=sH(s)=s; real derivatives H1(s)=sTs+1H_1(s)=\dfrac{s}{Ts+1}, H2(s)=ωc2ss2+2δωcs+ωc2H_2(s)=\dfrac{\omega_c^2 s}{s^2+2\delta\omega_c s+\omega_c^2} with T=12π50T=\dfrac1{2\pi50}, ωc=2π50\omega_c=2\pi50, δ=12\delta=\dfrac1{\sqrt2}.
  • Discretize with FE s=z−1Tss=\frac{z-1}{T_s}, BE s=z−1Tszs=\frac{z-1}{T_sz}, TU s=2Tsz−1z+1s=\frac2{T_s}\frac{z-1}{z+1}; compare Bode plots; FE of ss is not proper, so not implementable.
  • H3(z)=1−z−NNTsH_3(z)=\dfrac{1-z^{-N}}{NT_s} (N=4N=4) = BE derivative times a moving average: more high-frequency attenuation than BE.
  • H4(z)=16Ts(1+3z−1−3z−2−z−3)=1Ts(1−z−1)1+4z−1+z−26H_4(z)=\dfrac1{6T_s}(1+3z^{-1}-3z^{-2}-z^{-3})=\dfrac1{T_s}(1-z^{-1})\dfrac{1+4z^{-1}+z^{-2}}{6}, from averaging the incremental ratios over the last 44 steps (u∗u^* cancels).
  • Noisy ramp u[k]=25 kTs+n[k]u[k]=25\,kT_s+n[k], nn uniform on [−0.001,0.001][-0.001,0.001] (rand): compare output-noise variance after the transient.

Exercise 5 - CST (P′(s)=kmTms+1P'(s)=\dfrac{k_m}{T_ms+1}, km=5.2k_m=5.2, Tm=0.03T_m=0.03, P=P′/sP=P'/s)

  • c2d with 'zoh': exact P′(z)P'(z); position branch Tsz−1\dfrac{T_s}{z-1}; H(z)H(z) = FE of H2H_2.
  • P controller: root locus of the loop transfer function, critical KP∗K_P^*; then KP=KP∗/4K_P=K_P^*/4, 300 rpm300\,\text{rpm} step over 0.3 s0.3\,\text{s}: rise time, 5%5\% settling time, overshoot; P leaves a finite steady-state error.
  • PI: C(z)=KP(1+100Tsz−1)C(z)=K_P\left(1+100\dfrac{T_s}{z-1}\right) gives zero error to a step (pole at z=1z=1).

Exercise 6 - Simulink

  • DAC: Quantizer qDAC=20216−1 Vq_{\text{DAC}}=\dfrac{20}{2^{16}-1}\,\text{V}, Saturation ±10 V\pm10\,\text{V}, ZOH TsT_s.
  • Encoder (2000 ppr2000\,\text{ppr}): ZOH TsT_s, Quantizer qenc=2π2000 radq_{\text{enc}}=\dfrac{2\pi}{2000}\,\text{rad}, Gain 20002π\dfrac{2000}{2\pi}.
  • Units: pulses/s ×602000\times\frac{60}{2000} gives rpm; rpm error ×2π60\times\frac{2\pi}{60} gives rad/s for C(z)C(z).
  • Reference step 300 rpm300\,\text{rpm} at 0.1 s0.1\,\text{s}, disturbance −3 V-3\,\text{V} at 0.5 s0.5\,\text{s}; plots: speeds in rpm and u(t)u(t).
  • 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 60/200060/2000 or 2π/602\pi/60.

Esercizio 4, passi:

  1. Ideale H(s)=sH(s)=s discretizzato con FE, BE, TU: confronto dei diagrammi di Bode con la derivata continua; FE non è propria, quindi non è realizzabile; BE e TU sì.
  2. Stessa analisi per H1H_1 e H2H_2.
  3. H3(z)=1−z−NNTsH_3(z) = \dfrac{1-z^{-N}}{NT_s} con N=4N=4: è la derivata BE in cascata con una media mobile su NN campioni, quindi attenua di più alle alte frequenze.
  4. H4(z)=16Ts(1+3z−1−3z−2−z−3)=1Ts(1−z−1)1+4z−1+z−26H_4(z) = \dfrac{1}{6T_s}\big(1+3z^{-1}-3z^{-2}-z^{-3}\big) = \dfrac{1}{T_s}(1-z^{-1})\dfrac{1+4z^{-1}+z^{-2}}{6}: il termine u∗u^* si annulla, i coefficienti restano 23\tfrac{2}{3}, 22, −2-2, −23-\tfrac{2}{3} divisi per 4Ts4T_s.
  5. Rampa con rumore u[k]=25 kTs+n[k]u[k] = 25\,kT_s + n[k], nn uniforme su [−a,a][-a,a] con a=0.001a=0.001: la varianza del rumore di uscita si valuta dopo il transitorio. Una uniforme su [−a,a][-a,a] ha varianza a2/3a^2/3, utile come controllo.

Esercizio 6, Simulink:

  • DAC: quantizzatore con qDAC=20216−1q_{DAC} = \dfrac{20}{2^{16}-1} V, saturazione a ±10\pm10 V, ZOH con Ts=1T_s = 1 ms (catena Quantizer, Saturation, ZOH).
  • Encoder da 20002000 ppr: ZOH con TsT_s, quantizzatore con qenc=2π2000q_{enc} = \dfrac{2\pi}{2000} rad, guadagno 20002π\dfrac{2000}{2\pi} per avere impulsi.
  • Catena delle unità: impulsi/s ×602000\times\dfrac{60}{2000} = rpm; errore in rpm ×2π60\times\dfrac{2\pi}{60} = rad/s, ingresso di C(z)C(z).
  • Evento: gradino di 300300 rpm a 0.10.1 s, disturbo Ad=−3A_d = -3 V a 0.50.5 s. Figure: velocità in rpm (reale, misurata, riferimento) e u(t)u(t) in V.
  • Domande: il P respinge il disturbo costante? Il PI sì, ma uu 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 uu saturata: l'integrale si carica oltre il limite.
  • Scrivere il controllore PI in ss invece che in zz quando la variabile è zz.
  • Passo del solver a passo fisso maggiore o uguale a TsT_s.

Teoria collegata