Escolar Documentos
Profissional Documentos
Cultura Documentos
1 Solution of problem 1
Given the system
G(s) =
K0 esT0
1 + sT1
1.1
Simulate a step response for the system by using the step invariant method and a step time h = 0.1.
K0 bz 1
1 + az 1
K0 bz 6
1 + az 1
% file: problem1_1.m
% HR August 2003
clear
% system
K0=1; T0=0.5; T1=2;
% step time
h=0.1;
% discrete time system
a=-exp(-h/T1); b=1+a;
% simulation parameters
Tstop=20; Nstop=Tstop/h;
% initialize
y=zeros(1,Nstop);
U0=0;
u=zeros(1,Nstop); time=h*(1:Nstop);
for t=7:Nstop
% supervision
if (t==round(2/h)) U0=1; end
% system simulation
y(t) = -a*y(t-1)+K0*b*u(t-6);
% control
u(t) = U0;
end
plot(time,y,time,u)
xlabel(time [s]);
title(y & u)
grid
print -deps problem1_1.eps
pause
close
y&u
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
10
time [s]
12
14
16
18
20
1.2
% file: problem1_2.m
% HR August 2003
clear
% system
K0=1; T0=0.5; T1=2;
% step time
h=0.1;
% discrete time system
a=-exp(-h/T1); b=1+a;
% simulation parameters
Tstop=10; Nstop=Tstop/h;
% initialize
y=zeros(1,Nstop);
U0=0; Yr=0;
u=zeros(1,Nstop); time=h*(1:Nstop);
for t=7:Nstop
% supervision
if (t==round(2/h)) U0=1; end
% system simulation
y(t) = -a*y(t-1)+K0*b*u(t-6);
% relay control
if (y(t)>Yr) u(t)=-U0;
else
end
u(t)=U0;
end
plot(time,y,time,u)
xlabel(time [s]);
title(y & u)
grid
print -deps problem1_2.eps
pause
close
y&u
1
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
5
time [s]
1.3
4d
a
10
= 5.1 and Tu = 2
Use Tu of Ku obtained by relay feedback to compute the coeficients in a PID-regulator designed with km = 0.5 and m = 3
tan m + 1+tan2 m
K = km Ku cos m and Td =
2u
Regulator
Ziegler-Nichols
ultimate period
km = 0.5 and
m = 60 deg
1.4
Ti
Td
0.60Ku = 3.06
0.50Tu = 1.00
0.125Tu = 0.25
0.25Ku = 1.28
1.20Tu = 2.40
0.30Tu = 0.60
Td
Td +N h
bd = N ad
r1 = (1 + ad )
s0 = K(1 + bd ) s1 = K(1 + ad + 2bd bi )
t0 = Kb
t1 = K(b(1 + ad ) bi )
bi = Thi
r2 = ad
s2 = K(ad + bd bi ad )
t2 = Kad (b bi )
% file: problem1_3.m
% HR August 2003
clear
% system
K0=1; T0=0.5; T1=2;
% step time
h=0.1;
% discrete time system
a=-exp(-h/T1); b=1+a;
% simulation parameters
Tstop=20; Nstop=Tstop/h;
y =zeros(1,Nstop);
u =zeros(1,Nstop);
yr=zeros(1,Nstop);
time=h*(1:Nstop);
y & u (dot)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
10
time [s]
12
14
16
18
20
Figure 4: Step response for the regulator designed by using km = 0.5 and m = 60
1.5
1.4
1.2
0.8
0.6
0.4
0.2
10
time [s]
12
14
16
18
20
2 Solution of problem 2
The following continuous time system
G(s) =
KesT0
1 + sT1
2.1
Using the step invariant transformation method and the sampling time Ts = 0.5 gives the following second order discrete
time system
y(k) + a1 y(k 1) + a2 y(k 2) = b1 u(k 1) + b2 u(k 2)
with y(k) = ya (kTs ). Compute for this system the values for a1 ,
a2 , b1 ,b2
2.2
% problem 2_2.m
% HR August 2003
% system
T0=0.5; T1=2; K0=1; a=-exp(-h/T1); b=1+a;
% parameters for sysid
t0=20; G=zeros(4,1); R=zeros(4,4); theta=zeros(4,1);
% parameters for simulation
Tstop=40; h=0.5; Nstop=Tstop/h;
y
=zeros(1,Nstop);
u
=zeros(1,Nstop);
yr =zeros(1,Nstop);
plt =zeros(4,Nstop);
time=h*(1:Nstop);
for t=3:Nstop
% supervision
if (sin(2*pi/20*time(t))>0) Uman=1;
else
Uman=0; end
% system simulation
y(t) = -a*y(t-1)+b*u(t-2);
% control
u(t)=Uman;
% parameter update
my=1/t;
phi=[-y(t-1) -y(t-2) u(t-1) u(t-2)];
G=(1-my)*G+my*phi*y(t);
R=(1-my)*R+my*phi*phi;
if (abs(det(R))> 0.0) theta=R\G; end
plt(1,t)=theta(1);
plt(2,t)=theta(2);
plt(3,t)=theta(3);
plt(4,t)=theta(4);
end
plot(time,u,time,y)
title(u & y)
xlabel(time [s])
grid
print -deps problem2_2a.eps
pause
close
plot(time,plt(1,:),time,plt(2,:))
title(a1 & a2)
xlabel(time [s])
grid
print -deps problem2_2b.eps
pause
close
plot(time,plt(3,:),time,plt(4,:))
title(b1 & b2)
xlabel(time [s])
grid
print -deps problem2_2c.eps
pause
close
u&y
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
10
15
20
time [s]
25
30
35
40
a1 & a2
0.1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
10
15
20
time [s]
25
30
35
40
35
40
b1 & b2
0.3
0.25
0.2
0.15
0.1
0.05
0.05
10
15
20
time [s]
25
30
2.3
% problem 2_3.m
% HR August 2003
% system
T0=0.5; T1=2; K0=1; a=-exp(-h/T1); b=1+a;
% parameters for sysid
t0=20; G=zeros(4,1); R=zeros(4,4); theta=zeros(4,1);
% parameters for simulation
Tstop=200; h=0.5; Nstop=Tstop/h;
y
=zeros(1,Nstop);
u
=zeros(1,Nstop);
yr =zeros(1,Nstop);
plt =zeros(4,Nstop);
time=h*(1:Nstop);
for t=3:Nstop
% supervision
if (t==round(100/h)) K0=2; end
if (sin(2*pi/20*time(t))>0) Uman=1;
else
Uman=0; end
% system simulation
y(t) = -a*y(t-1)+K0*b*u(t-2);
% control
u(t)=Uman;
% parameter update
my=1/t;
phi=[-y(t-1) -y(t-2) u(t-1) u(t-2)];
G=(1-my)*G+my*phi*y(t);
R=(1-my)*R+my*phi*phi;
if (abs(det(R))> 0.0) theta=R\G; end
plt(1,t)=theta(1);
plt(2,t)=theta(2);
plt(3,t)=theta(3);
plt(4,t)=theta(4);
end
plot(time,u,time,y)
title(u & y)
xlabel(time [s])
grid
print -deps problem2_3a.eps
pause
close
plot(time,plt(1,:),time,plt(2,:))
title(a1 & a2)
xlabel(time [s])
grid
print -deps problem2_3b.eps
pause
close
plot(time,plt(3,:),time,plt(4,:))
title(b1 & b2)
xlabel(time [s])
grid
print -deps problem2_3c.eps
pause
close
u&y
2
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
20
40
60
80
100
time [s]
120
140
160
180
200
180
200
a1 & a2
0.6
0.4
0.2
0.2
0.4
0.6
0.8
1.2
1.4
20
40
60
80
100
time [s]
120
140
160
b1 & b2
0.3
0.25
0.2
0.15
0.1
0.05
0.05
20
40
60
80
100
time [s]
120
140
160
180
200
10
2.4
% problem 2_4.m
% HR August 2003
% system
T0=0.5; T1=2; K0=1; a=-exp(-h/T1); b=1+a;
% parameters for sysid
t0=20; G=zeros(4,1); R=zeros(4,4); theta=zeros(4,1);
% parameters for simulation
Tstop=200; h=0.5; Nstop=Tstop/h;
y
=zeros(1,Nstop);
u
=zeros(1,Nstop);
yr =zeros(1,Nstop);
plt =zeros(4,Nstop);
time=h*(1:Nstop);
for t=3:Nstop
% supervision
if (t==round(100/h)) K0=2; end
if (sin(2*pi/20*time(t))>0) Uman=1;
else
Uman=0; end
% system simulation
y(t) = -a*y(t-1)+K0*b*u(t-2);
% control
u(t)=Uman;
% parameter update
my=1/t;
if (my<1/t0) my=1/t0; end
phi=[-y(t-1) -y(t-2) u(t-1) u(t-2)];
G=(1-my)*G+my*phi*y(t);
R=(1-my)*R+my*phi*phi;
if (abs(det(R))> 0.0) theta=R\G; end
plt(1,t)=theta(1);
plt(2,t)=theta(2);
plt(3,t)=theta(3);
plt(4,t)=theta(4);
end
plot(time,u,time,y)
title(u & y)
xlabel(time [s])
grid
print -deps problem2_4a.eps
pause
close
plot(time,plt(1,:),time,plt(2,:))
title(a1 & a2)
xlabel(time [s])
grid
print -deps problem2_4b.eps
pause
close
plot(time,plt(3,:),time,plt(4,:))
title(b1 & b2)
xlabel(time [s])
grid
print -deps problem2_4c.eps
pause
close
11
u&y
2
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
20
40
60
80
100
time [s]
120
140
160
180
200
180
200
a1 & a2
0.6
0.4
0.2
0.2
0.4
0.6
0.8
1.2
1.4
20
40
60
80
100
time [s]
120
140
160
b1 & b2
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0.05
20
40
60
80
100
time [s]
120
140
160
180
200
12
In the following the small signal model developed around (y0 , u0 ) = (1, 1) is simulated
as
y(k) y0 + a(y(k 1) y0 ) = b(u(k 2) u0 )
with (y(k), u(k)) = (y0 , u0 ) for k < 3
13
plot(time,plt(3,:),time,plt(4,:))
title(b1 & b2)
xlabel(time [s])
grid
print -deps problem2_5c.eps
pause
close
u&y
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
10
20
30
time [s]
40
50
60
a1 & a2
0.1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
10
20
30
time [s]
40
50
60
b1 & b2
0.3
0.25
0.2
0.15
0.1
0.05
0.05
10
20
30
time [s]
40
50
60
14
3 Solution of problem 3
In problem 2.3 a recursive least square method without forgetting in the first 20 samples
and there after forgetting with a window equal to 20. This algorithm is now extended
with a pole placement controller with integral action going from manual to auto at time
equal to 20 sec. The reference signal yr (t) is a square wave signal equal to the input in
exercise 2.3
The specified closed loop polynomium is:
P (q 1 ) = Am (q 1 )Ao (q 1 ) = (1 + am1 q 1 + am2 q 2 )(1 + ao1 q 1 + ao2 q 2 )
where
am1
am2
ao1
ao2
= 2e0 Ts cos(0 Ts
=
e20 Ts
=
2eTs /o
=
e2Ts /o
1 2)
3.1 Do the described simulations and plot the input u(t) and output
y(t) for = 0.1, = 0.5 and = 2
% problem 3_1.m
% HR August 2003
clear
% system
T0=0.5; T1=2; K0=1; h=0.5; a=-exp(-h/T1); b=1+a;
% parameters for sysid
t0=20; G=zeros(4,1); R=zeros(4,4); theta=zeros(4,1);
% parameters for controller
auto=0;
s0=0; s1=0; s2=0; r1=0; r2=0; t0m=0;
Umin=-10; Umax=10;
% parameters for controller design
update_reg=0;
a1_=0; a2_=0; b1_=0; b2_=0;
alpha=0.5; Tu=2;
d=sqrt(3); w0=alpha*2*pi/Tu; thau0=Tu/2;
am1=-2*exp(-0.5*d*w0*h)*cos(w0*h*sqrt(1-d*d/4));
am2=exp(-d*w0*h);
ao1=-2*exp(-h/thau0);
ao2=exp(-2*h/thau0);
P=conv([1 am1 am2],[1 ao1 ao2]);
p1=P(2); p2=P(3); p3=P(4); p4=P(5);
% parameters for simulation
Tstop=120; Nstop=Tstop/h;
y
=zeros(1,Nstop);
u
=zeros(1,Nstop);
yf =zeros(1,Nstop);
uf =zeros(1,Nstop);
plt =zeros(4,Nstop);
time=h*(1:Nstop);
for t=3:Nstop
% supervision
if (t==round(50/h)) K0=2; end
if (sin(2*pi/20*time(t))>0) Uman=1; yr(t)=1;
else
Uman=0; yr(t)=0; end
if (t==round(20/h)) update_reg=1; auto=1; end
% system simulation
y(t) = -a*y(t-1)+K0*b*u(t-2);
15
% control
if (auto==1)
u(t)=-r1*u(t-1)-r2*u(t-2)-s0*y(t)-s1*y(t-1)-s2*y(t-2)+...
t0m*(yr(t)+ao1*yr(t-1)+ao2*yr(t-2));
else u(t)=Uman; end
if (u(t)<Umin) u(t)=Umin; end
if (u(t)>Umax) u(t)=Umax; end
if (update_reg==1)
a1_=theta(1); a2_=theta(2); b1_=theta(3); b2_=theta(4);
C=[b1_ 0
0
1
0 ;
b2_ b1_ 0
a1_ 1 ;
0
b2_ b1_ a2_ a1_;
0
0
b2_ 0
a2_;
0
0
0
1
1 ];
D=[p1-a1_;
p2-a2_;
p3;
p4;
-1];
X=C\D;
s0=X(1); s1=X(2); s2=X(3); r1=X(4); r2=X(5);
t0m=(s0+s1+s2)/(1+ao1+ao2);
end
% parameter update
my=1/t;
if (my<1/t0) my=1/t0; end
phi=[-y(t-1) -y(t-2) u(t-1) u(t-2)];
G=(1-my)*G+my*phi*y(t);
R=(1-my)*R+my*phi*phi;
if (abs(det(R))> 0.0) theta=R\G; end
plt(1,t)=theta(1);
plt(2,t)=theta(2);
plt(3,t)=theta(3);
plt(4,t)=theta(4);
end
plot(time,u,time,y)
title(u & y)
xlabel(time [s])
grid
print -deps problem3_1a.eps
pause
close
plot(time,plt(1,:),time,plt(2,:))
title(a1 & a2)
xlabel(time [s])
grid
print -deps problem3_1b.eps
pause
close
plot(time,plt(3,:),time,plt(4,:))
title(b1 & b2)
xlabel(time [s])
grid
print -deps problem3_1c.eps
pause
close
16
u&y
2
1.5
0.5
0.5
1.5
20
40
60
time [s]
80
100
120
a1 & a2
0.4
0.2
0.2
0.4
0.6
0.8
1.2
1.4
20
40
60
time [s]
80
100
120
b1 & b2
0.6
0.5
0.4
0.3
0.2
0.1
0.1
20
40
60
time [s]
80
100
17
120
4 Solution of problem 4
4.1 Obtain by simulation the results in example 5.2 (Adaptiv Control)
% file: problem4_1.m
% HR August 2003
clear
% system b/(s+a)
a=1; b=0.5;
% reference system bm/(s+am)
am=2; bm=2;
% simulation
Tstop=100; h=0.01; Nstop=Tstop/h;
a1 =-exp(-h*a); b1=b/a*(1+a1);
am1=-exp(-h*am); bm1=bm/am*(1+am1);
% adaptation
gamma=5;
% initialize
y
=zeros(1,Nstop); yr =zeros(1,Nstop); ym =zeros(1,Nstop);
u
=zeros(1,Nstop); x1 =zeros(1,Nstop); x2 =zeros(1,Nstop);
theta =zeros(2,Nstop); time=h*(1:Nstop);
for t=2:Nstop
if (sin(2*pi/20*t*h)>0) yr(t)=+1;
else
yr(t)=-1; end
y(t) =-a1 *y(t-1) +b1*u(t-1);
u(t) =theta(1,t-1)*yr(t)-theta(2,t-1)*y(t);
ym(t)=-am1*ym(t-1)+bm1*yr(t-1);
x1(t)=-am1*x1(t-1)+(1+am1)*yr(t);
x2(t)=-am1*x2(t-1)+(1+am1)*y(t);
theta(1,t)=theta(1,t-1)-h*gamma*x1(t)*(y(t)-ym(t));
theta(2,t)=theta(2,t-1)+h*gamma*x2(t)*(y(t)-ym(t));
end
plot(time,y,time,ym)
xlabel(time [s]);
title(y & ym)
grid
print -deps problem4_1a.eps
pause
close
plot(time,theta)
title(theta)
xlabel(time [s]);
grid
print -deps problem4_1b.eps
pause
close
18
y & ym
1.5
0.5
0.5
1.5
10
20
30
40
50
time [s]
60
70
80
90
100
3.5
2.5
1.5
0.5
0.5
10
20
30
40
50
time [s]
60
70
80
90
100
4.2 Show the effect of variation of both for the MIT rule and the
modified MIT rule
1
e
=
e
e T e
+ ( ) ( )
where > 0 to avoid division with zero
% file: problem4_2.m
% HR August 2003
clear
% system b/(s+a)
a=1; b=0.5;
% reference system bm/(s+am)
am=2; bm=2;
% simulation
Tstop=100; h=0.01; Nstop=Tstop/h;
a1 =-exp(-h*a); b1=b/a*(1+a1);
am1=-exp(-h*am); bm1=bm/am*(1+am1);
% adaptation
gamma=5; alpha=0.0001;
% initialize
y
=zeros(1,Nstop); yr =zeros(1,Nstop); ym =zeros(1,Nstop);
u
=zeros(1,Nstop); x1 =zeros(1,Nstop); x2 =zeros(1,Nstop);
theta =zeros(2,Nstop); time=h*(1:Nstop);
for t=2:Nstop
if (sin(2*pi/20*t*h)>0) yr(t)=+1;
else
yr(t)=-1; end
y(t) =-a1 *y(t-1) +b1*u(t-1);
u(t) =theta(1,t-1)*yr(t)-theta(2,t-1)*y(t);
ym(t)=-am1*ym(t-1)+bm1*yr(t-1);
19
x1(t)=-am1*x1(t-1)+(1+am1)*yr(t);
x2(t)=-am1*x2(t-1)+(1+am1)*y(t);
v=1/(alpha+x1(t)*x1(t)+x2(t)*x2(t));
theta(1,t)=theta(1,t-1)-h*gamma*v*x1(t)*(y(t)-ym(t));
theta(2,t)=theta(2,t-1)+h*gamma*v*x2(t)*(y(t)-ym(t));
end
plot(time,y,time,ym)
xlabel(time [s]);
title(y & ym)
grid
print -deps problem4_2a.eps
pause
close
plot(time,theta)
title(theta)
xlabel(time [s]);
grid
print -deps problem4_2b.eps
pause
close
y & ym
1.5
0.5
0.5
1.5
10
20
30
40
50
time [s]
60
70
80
90
100
theta
4.5
3.5
2.5
1.5
0.5
0.5
10
20
30
40
50
time [s]
60
70
80
90
100
20