Final Exam Solution, eece 413
1. + 4θ =Tc +Td θ x1 =θ, x 2 =θ = −4 x1 +Tc x 1 =θ = x 2, x 2 =θ
a)
x1 0 x 2 = −4 y = [1
1 x1 0 + Tc 0 x 2 1
x1 0 ] x 2
x = Fx + Gu , y = Hx + Ju
where
1 0 0 F = , G = 1 − 4 0 H = [1 0], J = 0
b)
s sI −F =0 = 0 s 4
0 0 − s −4
1 0
−1 = s 2 +4 =0 s
( ) c) is the estimator equation. Use either place or acker to compute the vector L. The matlab code is: ˆ = ˆ + ˆ x Fx Gu + L y − Hx
function Prob_2_9() % f = [0 1;-4 0]; g = [0;1]; h = [1 0]; j = 0; p = -[10 10]; L = acker(f',h',p)
The results are: L=
20
96
d) The matlab code is: function Prob_2_9() % f = [0 1;-4 0]; g = [0;1]; h = [1 0]; j = 0; p = -[10 10]; L = acker(f',h',p); pc = [-2+2*i,-2-2*i]; K = acker(f,g,pc)
The results are: K= e)
4
4
f) The matlab code is:
sys = ss(f,g,h,j); rsys = reg(sys,K,L); sysCL = feedback(sys*rsys,1,1); figure(1) subplot(211) t = [0:.1:10]; step(-sysCL,t) axis([0 10 0 1]) subplot(212) sysCL2 = feedback(sys,rsys,1); step(sysCL2,t) axis([0 10 0 1])
Step Response 1
Amplitude
0.8 0.6 0.4 0.2 0
0
1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
Time (sec)
Step Response 1
Amplitude
0.8 0.6 0.4 0.2 0
0
1
2
3
4
5 Time (sec)
g) The matlab code for the integrator is: function Prob_2_9() % f = [0 1;-4 0]; g = [0;1]; h = [1 0]; j = 0; p = -[10 10]; L = acker(f',h',p)'; pc = [-2+2*i,-2-2*i]; K = acker(f,g,pc);
sys = ss(f,g,h,j); rsys = reg(sys,K,L); sysCL = feedback(sys*rsys,1,1); figure(1) subplot(211) t = [0:.1:10]; step(-sysCL,t) axis([0 10 0 1]) subplot(212) sysCL2 = feedback(sys,rsys,1); step(sysCL2,t) axis([0 10 0 1]) % add integral control ai = [0 h;[0;0] f]; bi = [0;g];
ci = [0 h]; pc = [pc -4]; K = acker(ai,bi,pc) ki = K(1); ko = K(2:3); a = [ai-bi*[ki 0 0] -bi*ko;-g*ki L*h f-L*h-g*ko]; b = [-1;0;0;0;0]; c = [ci 0 0]; d = 0; syscl3 = ss(a,b,c,d); figure(2) step(syscl3,t) title(['step response, control gains are ',num2str(K)]) % disturbance response b2 = [0;g;0;0]; syscl4 = ss(a,b2,c,d); figure(3) step(syscl4,t)
The plots are:
step response, control gains are 32 20 8 1.4
1.2
Amplitude
1
0.8
0.6
0.4
0.2
0
0
1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
Time (sec)
Step Response 0.09 0.08 0.07 0.06
Amplitude
0.05 0.04 0.03 0.02 0.01 0 -0.01
0
1
2
3
4
5 Time (sec)
2. For the system
1 , s + 2s − 3 2
a) The simplest controller is a gain by inspection of the bode plot. By trial & error from the root locus plot & by inspection of the bode plot. The matlab code is: function FinalExam2() % close all sys = tf(1,[1 2 -3]); k = 4; figure(1)
margin(k*sys) figure(2) syscl = feedback(k*sys,1); step(syscl) figure(3) rlocus(sys,[3:.1:5]) damp(syscl)
Note that the damp command verifies that the damping coefficient is 1. The critical damping coefficient is 1 & occurs when the poles transition complex to real. The plots follow:
Bode Diagram Gm = 9.54 dB (at 0 rad/sec) , Pm = Inf 0
Magnitude (dB)
-20
-40
-60
Phase (deg)
-80 -150
-160
-170
-180 -2
10
-1
10
0
10
1
2
10
10
Frequency (rad/sec) Bode Diagram Gm = -2.5 dB (at 0 rad/sec) , Pm = 23.9 deg (at 0.81 rad/sec) 20
Magnitude (dB)
0 -20 -40 -60
Phase (deg)
-80 -150
-160
-170
-180 -2
10
-1
10
0
10
Frequency (rad/sec)
1
10
2
10
Step Response 4
3.5
3
Amplitude
2.5
2
1.5
1
0.5
0
0
5
10
15
Time (sec)
Root Locus 1 0.8 0.6 System: sys Gain: 4 Pole: -1 Damping: 1 Overshoot (%): 0 Frequency (rad/sec): 1
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
Real Axis
The 1st bode plot is the original system without compensation; the 2nd is with the gain of 4. From the bode plot, it is obvious that we only have to raise the magnitude by increasing the gain to achieve a stable system. By use of the step response and root locus we verify that the gain is what we want. The ‘damp’ command is used to verify the damping coefficient. The results are: Eigenvalue
Damping
Freq. (rad/s)
-1.00e+000
1.00e+000
1.00e+000
-1.00e+000
1.00e+000
1.00e+000
b) The system
1 may be written in state space form as below: s + 2s − 3
y + 2 y − 3 y = u x1 = y , x 2 = y , x 1 = y = x 2 ,
2
,
x 2 = 3 x1 − 2 x 2 + u
x 1 0 1 x1 0 x = 3 − 2 x + 1 u 2 2 x y = [1 0] 1 x2
c) The estimator poles should be placed at [-10, -10]. The matlab code is: f g h j p L
= = = = = =
[0 1;3 -2]; [0;1]; [1 0]; 0; -[10 10]; acker(f',h',p)'
The result is: L= 18 67 d) The controller gains should place the closed loop poles at [-2 -2]. The matlab code is: pc = [-2,-2]; K = acker(f,g,pc)
The result is: K=
7
2
e - f) Demonstrate the performance of the above to a step & a disturbance command. The matlab code is: function FinalExam2cd() % close all
f = [0 1;3 -2]; g = [0;1]; h = [1 0]; j = 0; p = -[10 10]; L = acker(f',h',p)'; pc = [-2,-2]; K = acker(f,g,pc); sys = ss(f,g,h,j); rsys = reg(sys,K,L); sysCL = feedback(sys*rsys,1,1); figure(1) subplot(211) t = [0:.1:10]; step(-sysCL,t) subplot(212) sysCL2 = feedback(sys,rsys,1); step(sysCL2,t)
The plots follow:
Step Response
Amplitude
3
2
1
0
0
1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
Time (sec) Step Response 0.4
Amplitude
0.3 0.2 0.1 0
0
1
2
3
4
5 Time (sec)
g) Show the effect of sampling at 20 Hz on the PM by transfer function analyses. An approximation is: δφ =
ωT 2
; the transfer function approximation given in the text is
Gh ( s) =
2/T . The step response for both the continuous and the sampled s + 2/T
approximation are then performed. The matlab code is: function FinalExam2gh() % close all T = 1/20; gh = tf(2/T,[1 2/T]); f = [0 1;3 -2]; g = [0;1]; h = [1 0]; j = 0; p = -[10 10]; L = acker(f',h',p)'; pc = [-2,-2]; K = acker(f,g,pc); sys = ss(f,g,h,j); rsys = reg(sys,K,L); sysCL = feedback(sys*rsys,1,1); figure(1) margin(sys*rsys),hold on margin(sys*rsys*gh),hold off legend('continuous','20 Hz') figure(2) step(-sysCL),hold on step(-sysCL*gh),hold off
Bode Diagram Gm = Inf dB (at Inf rad/sec) , Pm = -140 deg (at 1.59 rad/sec) 50
Magnitude (dB)
0 -50 -100 -150 -200 45 continuous Phase (deg)
0
20 Hz
-45 -90 -135 -180 -2
10
-1
0
10
1
10
2
10
3
10
10
Frequency (rad/sec)
Step Response 2.5 continuous 20 Hz 2
Amplitude
1.5
1
0.5
0
0
0.5
1
1.5
2
2.5
3
Time (sec)
3. Solve 3.8 by state space. Specs are: bandwidth = 100 Hz & PM = 50. This may be one of those problems where the specs are in conflict. We may need to increase the PM slightly to achieve the bandwidth and overshoot. The problem statement for 3.8 is: 500 . Design a s2 continuous lead compensation so that the closed-loop system has a bandwidth of 100 Hz and a phase margin of 50. Modify the matlab file fig32.m so that you can evaluate the
The read arm on a computer disk drive has the transfer function G ( s ) =
digital version of your lead compensation using Euler’s forward rectangular method. Try different sample rates and find the slowest one where the overshoot does not exceed 30%. Please note that we are replacing the lead compensator with a state space derived one. The matlab code is: function FinalExam3() % close all bw = 2*pi*100; % from problem spec z = 0.65; % damping coefficient from PM = 50 --> z>0.5 % must also be large enough to satisfy overshoot requirement. numG = 500; denG = [1 0 0]; sys = ss(tf(numG,denG)); pc = roots([1 2*z*bw bw*bw]); p = 10*pc; [f,g,h,j] = ssdata(sys); L = acker(f',h',p)'; K = acker(f,g,pc); rsys = reg(sys,K,L); sysCL = feedback(sys*rsys,1,1); figure(1) margin(sys*rsys) figure(2) tfin = 0.02; tmax = 0.1; dt = 1e-4; t = [0:dt:tfin]; tm = [0:dt:tmax]; step(-sysCL,tfin),hold on y = step(-sysCL,tmax); ymax = (max(y)/y(end)-1)*100 w = 3000; T = 1/w; gh = tf(2/T,[1 2/T]); sysCL = feedback(sys*rsys*gh,1,1); step(-sysCL,tfin),hold on y = step(-sysCL,tmax); ymax = (max(y)/y(end)-1)*100 w = 4500; T = 1/w; gh = tf(2/T,[1 2/T]); sysCL = feedback(sys*rsys*gh,1,1); step(-sysCL,tfin),hold on y = step(-sysCL,tmax); ymax = (max(y)/y(end)-1)*100 legend('cont','w=3000','w=4500')
The results are:
Bode Diagram Gm = Inf , Pm = -127 deg (at 858 rad/sec) 100
Magnitude (dB)
50 0 -50 -100 -150 90
Phase (deg)
45 0 -45 -90 1
2
10
3
10
4
10
5
10
6
10
10
Frequency (rad/sec)
Step Response 1.4 cont w =3000
System: untitled3 Time (sec): 0.00353 Amplitude: 1.3
1.2
w =6000
Amplitude
1
0.8
0.6
0.4
0.2
0
0
0.002
0.004
0.006
0.008
0.01
0.012
0.014
0.016
0.018
0.02
Time (sec)
Note that the approach is based on the approximation method of discretization as it is very difficult to get matlab to discretize otherwise. The PM is actually 180 – 127 = 53 which is close to 50. The bandwidth is ~858 > 628 rad/s which is the desired. At a sampling rate of 3000 Hz we finally get below 30% overshoot. Some trade-off studies will need to be made between bandwidth, overshoot, and phase margin. 4. Solve 3.9 by a state space method and include an estimator. The problem statement of 3.9 is:
The antenna tracker has the transfer function G ( s ) =
10 . Design a continuous lead s( s + 2)
compensation so that the closed-loop system has a rise time tr < 0.3 sec and overshoot Mp < 10%. Modify the matlab file fig32.m so that you can evaluate the digital version of your lead compensation using Eulerâ&#x20AC;&#x2122;s forward rectangular method. Try different sample rates, and find the slowest one where the overshoot does not exceed 20%. The matlab code is:
function FinalExam4() % close all bw = 6; % from problem spec tr = 0.3 --> bw = 1.8/tr = 6 rad/s z = 0.9; % damping coefficient should be large to get 10% overshoot numG = 10; denG = [1 2 0]; sys = ss(tf(numG,denG)); pc = roots([1 2*z*bw bw*bw]); p = 10*pc; [f,g,h,j] = ssdata(sys); L = acker(f',h',p)'; K = acker(f,g,pc); rsys = reg(sys,K,L); sysCL = feedback(sys*rsys,1,1); figure(1) margin(sys*rsys) figure(2) tfin = 1; tmax = 5; dt = 1e-1; t = [0:dt:tfin]; tm = [0:dt:tmax]; step(-sysCL,tfin),hold on y = step(-sysCL,tmax); ymax = (max(y)/y(end)-1)*100 w = 10; T = 1/w; gh = tf(2/T,[1 2/T]); sysCL = feedback(sys*rsys*gh,1,1); step(-sysCL,tfin),hold on y = step(-sysCL,tmax); ymax = (max(y)/y(end)-1)*100 w = 14; T = 1/w; gh = tf(2/T,[1 2/T]); sysCL = feedback(sys*rsys*gh,1,1); step(-sysCL,tfin),hold on y = step(-sysCL,tmax); ymax = (max(y)/y(end)-1)*100 legend('cont','w=10','w=14')
The plots follow:
Bode Diagram Gm = Inf , Pm = -113 deg (at 7.89 rad/sec) 50
Magnitude (dB)
0
-50
-100
-150 90
Phase (deg)
45 0 -45 -90 -1
0
10
1
10
2
10
3
10
10
10
4
Frequency (rad/sec)
Step Response 1.4 cont w =10 1.2
w =14 System: untitled3 Time (sec): 0.364 Amplitude: 1.19
Amplitude
1
0.8
0.6
0.4
0.2
0
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time (sec)
The system bandwidth is ~8 rad/s, the rise time < 0.3 s, & the continuous overshoot < 10% (9.2%). At a sampling rate of 10 Hz the overshoot is ~ 19%. 5. Do problem 6.4 in the text. The problem statement follows: The following transfer function is a lag network designed to increase Kv by a factor of 10 and have negligible phase lag at w1 = 3 rad. H ( s ) = 10
10 s +1 100 s +1
a) For each of the following design methods, compute and plot on the z-plane the zeropole patterns of the resulting discrete equivalents and give the phase lag at z1 = exp(j*w1*T) corresponding to w1 = 3. Let T = 0.25 s. Forward rectangular rule, backward rectangular rule, bilinear rule, bilinear with prewarping (use w1 = 3 rad/s as the warping frequency), zero-pole matching, zero-orderhold equivalent, & triangle-hold equivalent. b) For each case computed, plot the Bode amplitude and phase curves over the range w1 = [0.01:10] rad/s. The matlab code is: function Prob_6_4() % close all w1 = 3; H = tf(10*[10 1],[100 1]); figure(1) pzmap(H) title('H(s) continuous') [mag,ph] = bode(H,w1); T = 0.25; [a,b,c,d] = ssdata(H); [phif,gamf,hf,jf] = get_for(a,b,c,d,T); Hf = ss(phif,gamf,hf,jf,T); [mag,ph] = bode(Hf,w1); figure(2) pzmap(Hf) title('Forward rectangular rule') [phib,gamb,hb,jb] = get_back(a,b,c,d,T); Hb = ss(phib,gamb,hb,jb,T); [mag,ph] = bode(Hb,w1); figure(3) pzmap(Hb) title(['Backward rectangular rule, phase @ 3 rad/s = ',num2str(ph)]) [phibil,gambil,hbil,jbil] = get_bil(a,b,c,d,T); Hbil = ss(phibil,gambil,hbil,jbil,T); [mag,ph] = bode(Hbil,w1); figure(4) pzmap(Hbil) title(['Trapezoid (bilinear) rule, phase @ 3 rad/s = ',num2str(ph)]) Hpre = c2d(H,T,'prewarp',w1); [mag,ph] = bode(Hpre,w1); figure(5) pzmap(Hpre) title(['Trapezoid with prewarp @ 3 rule, phase @ 3 rad/s = ',num2str(ph)]) Hmat = c2d(H,T,'matched'); [mag,ph] = bode(Hmat,w1); figure(6) pzmap(Hmat) title(['Zero-pole matched rule, phase @ 3 rad/s = ',num2str(ph)]) Hzoh = c2d(H,T,'zoh'); [mag,ph] = bode(Hzoh,w1);
figure(7) pzmap(Hzoh) title(['Zero-order hold rule, phase @ 3 rad/s = ',num2str(ph)]) Hfoh = c2d(H,T,'foh'); [mag,ph] = bode(Hfoh,w1); figure(8) pzmap(Hfoh) title(['First-order hold rule, phase @ 3 rad/s = ',num2str(ph)]) figure(9) bode(H,Hf,Hb,Hbil,Hpre,Hmat,Hzoh,Hfoh,[0.1:.1:25]) legend('H','back','for','bilin','prewarp','zp','zoh','foh') function [phif,gamf,hf,jf] = get_for(a,b,c,d,T); phif = eye(size(a)) + a*T; gamf = b*T; hf = c; jf = d; function [phib,gamb,hb,jb] = get_back(a,b,c,d,T); phib = inv(eye(size(a)) - a*T); gamb = phib*b*T; hb = c*phib; jb = d + c*gamb; function [phibil,gambil,hbil,jbil] = get_bil(a,b,c,d,T); temp = inv(eye(size(a)) - a*T/2); phibil = (eye(size(a)) + a*T/2)*temp; gambil = temp*b*sqrt(T); hbil = sqrt(T)*c*temp; jbil = d + c*temp*b*T/2;
The results are plotted below.
Forw ard rectangular rule, phase @ 3 rad/s = -1.6597 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0.8
1
Real Axis
Backw ard rectangular rule, phase @ 3 rad/s = -1.6147 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0 Real Axis
0.2
0.4
0.6
Trapezoid (bilinear) rule, phase @ 3 rad/s = -1.6369 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0.8
1
Real Axis
Trapezoid w ith prew arp @ 3 rule, phase @ 3 rad/s = -1.7182 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0 Real Axis
0.2
0.4
0.6
Zero-pole matched rule, phase @ 3 rad/s = -1.6368 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Axis
Zero-order hold rule, phase @ 3 rad/s = -1.6576 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0 Real Axis
0.2
0.4
0.6
0.8
1
First-order hold rule, phase @ 3 rad/s = -1.6369 1 0.8 0.6
Imaginary Axis
0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Real Axis
All of the approximations for this network are essentially the same. b) Plot the bode diagram. All are close to the same.
1
Bode Diagram
H
20
back for
Magnitude (dB)
15
bilin prew arp
10
zp zoh
5
foh
0
Phase (deg)
-5 0
-30
-60 -2
10
-1
0
10
10 Frequency (rad/sec)
1
10