Вы находитесь на странице: 1из 24

KING ABDULAZIZ UNIVERSITY

Faculty of Engineering
Department Of Electrical And Computer Engineering

Principles of Automatic Control


Lab #2

Controller Types Experiments

Mohannad Alghamdi

0516320
2/7/2014

EE331

Introduction:

This is a second lab of principles of automatic control. In this


lab I will studying the types of controllers (P, I, PI, PD, and PID). I will
analyse the controllers by using open and closed loop analysis for each
controller exception PID controller only closed loop analysis. In closed
loop analysis I will use PT1 first order system to examine each
controller. Finally, I will discuss each situation to know the advantages
of each controller.

Body:

Procedures:
I will do in this lab five experiments talk about controller types.
Each experiment I will follow these steps:
Write the question of the experiment.
Draw the block diagram of the experiment..
Write the code of the experiment by using Matlab program
(codes in appendices).
Simulate the experiment by graphical representation from
Matlab program.
Calculate the requirements in the question of the
experiment.
Discussion about experiment results.

Results:
Experiment(1): a) Open loop analysis for proportional
action control
Write a Matlab program to simulate the open loop unit
step response of the shown P controller. For a unit step of
0.6 volt and a duration of 5 seconds examine the controller
response given that R1=4.7 kilo-ohms and R2=2.2 kilo-ohms.
The open loop analysis for proportional action control
shown below in figure3:

Mohannad Alghamdi

0516320
2/7/2014

EE331

After I wrote program of the open loop analysis for


proportional action control, I simulate it shown below in
figure4:

Figure4: Open loop response of P controller.


After I simulate of the open loop analysis for proportional
action control, I will do calculations:
Givens: R1=4.7 K; R2=2.2 K; e(t)=0.6 V; t= 5 s
Requirements: KP = ?; x(t) = ?
Solution:
a. Theoretically:
KP = R1/R2 = 4.7/2.2 = 2.14
x(t) = KP * e(t) = 2.14*0.6 = 1.282 V
b. Experimentally
x(t) = 1.284 V
Experiment(1): b) Closed loop analysis for proportional
action control
Write a Matlab program to simulate the closed loop unit step
response of the shown control system. For a
unit step of 1 volt and a duration of 10 seconds examine for
each Kp value of 1, 10 & 50:
a) Determine the delay values of T1; Ksys and eb ( the error).
b) Comment on the differences found with respect to:
* The open loop response of PT1
* Each Kp value.
Mohannad Alghamdi

0516320
2/7/2014

EE331

The closed loop analysis for proportional action control with


PT1 system shown below in figure5:

i. When KP = 1
After I wrote program of the closed loop analysis for proportional
action control, I simulate it shown below in figure6:

Figure6: Closed loop response of P controller when KP=1.


After I simulate of the closed loop analysis for proportional action
control, I will do calculations:
Givens: KP =1; Vin=1 V; t= 10 s
Requirements: T1= ?; Ksys=? ; eb= ?
Mohannad Alghamdi

0516320
2/7/2014

EE331

Solution:
T1= 0.498 s
Ksys= Vout/Vin = 0.5/1 = 0.5
eb= |(VinVout)/Vin| *100 = |(10.5)/1|*100 = 0.5*100 = 50%

ii. When KP = 10
After I wrote program of the closed loop analysis for proportional
action control, I simulate it shown below in figure7:

Figure7: Closed loop response of P controller when KP=10.


After I simulate of the closed loop analysis for proportional action
control, I will do calculations:
Givens: KP =10; Vin=1 V; t= 10 s
Requirements: T1= ?; Ksys=? ; eb= ?
Mohannad Alghamdi

0516320
2/7/2014

EE331

Solution:
T1= 0.091 s
Ksys= Vout/Vin= 0.9091/1 = 0.9091
eb= |(VinVout)/Vin | *100 = |(10.9091)/1|*100 = 0.0909*100 =
9.09%
iii. When KP = 50
After I wrote program of the closed loop analysis for proportional
action control, I simulate it shown below in figure8:

Figure8: Closed loop response of P controller when KP=50


After I simulate of the closed loop analysis for proportional action
control, I will do calculations:
Givens: KP =50; Vin=1 V; t= 10 s
Requirements: T1= ?; Ksys=? ; eb= ?
Solution:
T1= 0 s
Ksys= Vout / Vin = 0.9804/1 = 0.9804
Mohannad Alghamdi

0516320
2/7/2014

EE331

eb= |(VinVout)/Vin | *100 = |(10.9804)/1|*100 = 0.0196*100 =


1.96%

Discussion:

T1

KP = 1
0.498 s

P controller
KP = 10
0.091s

KP = 50
0s

Ksys

0.5

0.9091

0.9804

eb

50

9.09

1.96

Comparison

Experiment(2): a) Open loop analysis for integral action


control
Write a Matlab program to simulate the open loop unit step
response of the shown I controller. For a unit step of 1 volt and
a duration of 1 seconds examine the controller response given
that R1=1 mega-ohms and
C=1 micro-farad.
The open loop analysis for integral action control shown below
in figure9:

After I wrote program of the loop analysis for integral action


control, I simulate it shown below in figure10:

Mohannad Alghamdi

0516320
2/7/2014

EE331

Figure10: Open loop response of I controller.


After I simulate of the open loop analysis for proportional
action control, I will do calculations:
Givens: R1=1 M; C=1 F; y0=1V; t= 1 s
Requirements: Ki = ?
Solution:
a. Theoretically:
Ki = 1 / (R1C) = 1
b. Experimentally:
x1 = 0.401 s , x2 = 0.7507 s
y1 = 0.401 V, y2 = 0.7507 V
Ki = ( y/ x) (1/y0) = [(y2y1)/(x2x1)](1/y0)
= [(0.75070.401)/(0.75070.401)]= 1
Ti = 1/Ki= 1/1=1
Experiment(2): b) Closed loop analysis for integral action control
Write a Matlab program to simulate the closed loop unit step response of the
shown control system for a unit step of 1 volt and a duration of 10 seconds.
Comment on the differences found with respect to: * The open loop response
of PT1 * The closed loop response using the P controller with Kp=1.
The closed loop analysis for integral action control with PT1 system shown
below in figure11:

Mohannad Alghamdi

0516320
2/7/2014

EE331

After I wrote program of the closed loop analysis for integral action control, I
simulate it shown below in figure12:

Figure12: Closed loop response of I controller.


After I simulate of the open loop analysis for proportional action control, I
will do calculations:
Givens: y0=1V; t= 10 s
Requirements: Ton = ? ; Toff = ?; dy0 =? ; ymax = ?
Solution:
Experimentally: Ton =2.301 s , Toff = 5.513 s , dy0 = 0.0701 ;
ymax = 0.163V
Discussion:
By comparison between PT1 open loop and I controller closed loop, I found
PT1 reach steady state faster than I controller, because I controller have
overshot that make it delay to reach steady state, but the error almost equal.
By comparison between P controller closed loop when (KP=1) and I controller
closed loop, I found the error in I controller much less than P controller when
(KP=1), but the delay is conversely.
Mohannad Alghamdi

0516320
2/7/2014

EE331

Experiment(3): a) Open loop analysis for PI controller


Write a Matlab program to simulate the open loop unit step response of the PI
controller. Given that: Kp=1, and Ki=1. The unit step is 1 volt for a duration of
2 seconds. From the response indicate and measure the value of the Reset
time, Tn.
The open loop analysis for PI controller shown below in figure13:

After I wrote program of the loop analysis for PI controller, I simulate it


shown below in figure14:

Figure14: Open loop response of PI controller.


After I simulate of the open loop analysis for PI controller, I will do
calculations:
Givens: Kp=1 ; Ki=1; y0=1V; t= 2 s
Requirements: Tn = ?
Mohannad Alghamdi

0516320
2/7/2014

EE331

Solution:
Experimentally: Tn = 1 s
Experiment(3): b) Closed loop analysis for PI controller
Write a Matlab program to simulate the closed loop unit step response of the
PI controller * For a unit step of 1 volt and a duration of 10 seconds: a)
Determine the values of T1; Ksys and eb ( the error). b) Comment on the
differences found with respect to: * The open loop response of PT1. * The I
controller closed loop response.
The closed loop analysis for PI control with PT1 system shown below in
figure15:

After I wrote program of the closed loop analysis for PI controller, I simulate
it shown below in figure16:

Figure16: Closed loop response of PI controller.


After I simulate of the open loop analysis for PI controller, I will do
calculations:

Mohannad Alghamdi

0516320
2/7/2014

EE331

Givens:
Kp=1 ; Ki=1; Vin=1V; t= 10 s
Requirements: T1= ?; Ksys=?; eb=?
Solution:
Experimentally:
T1 = 0.998 s
Ksys= Vout/Vin = 1/1 = 1
eb= |(VinVout)/Vin| *100 = |(11)/1|*100 = 0*100 = 0%
Discussion:
By comparison between PT1 open loop and PI controller closed loop, I found
delay in PT1 less than PI controller , but the error conversely. By comparison
between I controller closed loop and PI controller closed loop, I found in delay
the PI controller less than I controller. So PI controller is better than I
controller because faster to reach steady state.
Experiment(4): a) Open loop analysis for PD controller
Write a Matlab program to simulate the open loop ramp response of the PD
controller. Given that: Kp=1, and Tv=1. The input is a unit step of 1 volt for a
duration of 2 seconds. From the response indicate and measure the value of
the rate time, Tv.
The open loop analysis for PD controller shown below in figure17:

After I wrote program of the loop analysis for PD controller, I simulate it


shown below in figure18:

Mohannad Alghamdi

0516320
2/7/2014

EE331

Figure18: Closed loop response of PD controller.


After I simulate of the open loop analysis for PD controller, I will do
calculations:
Givens: Kp=1 ; Ki=1; Tv= 1s ; y0=1V; t= 2 s
Requirements: Tv = ?
Solution:
Experimentally: Tv= 1s
Experiment(4): b) Closed loop analysis for PD controller
Write a Matlab program to simulate the closed loop unit step response of the
shown control system for a unit step of 1 volt and a duration of 10 seconds. a)
Determine the values of T1; Ks and eb ( the error). b) Comment on the
differences found with respect to: * The open loop response of PT1. * The P
controller closed loop response, with Kp=1.
The closed loop analysis for PD control with PT1 system shown below in
figure19:

After I wrote program of the closed loop analysis for PD controller, I simulate
it shown below in figure20:

Mohannad Alghamdi

0516320
2/7/2014

EE331

Figure20: Closed loop response of PD controller.


After I simulate of the closed loop analysis for PD controller, I will do
calculations:
Givens: Kp=1 ; Ki=1; Vin=1V; t= 10 s
Requirements: T1= ?; Ksys=?; eb=?
Solution:
Experimentally:
T1 = 0.997 s
Ksys= Vout/Vin = 1/1 = 1
eb= |(VinVout)/Vin| *100 = |(11)/1|*100 = 0*100 = 0%
Discussion:
Comparison
T1

Controllers
P controller ,KP
I
=1
controller
0.498 s
0.997 s

Ksys

0.5

eb

50

Experiment(5): Closed loop analysis for PID controller

Mohannad Alghamdi

0516320
2/7/2014

EE331

Write a Matlab program to simulate the closed loop unit step response of the
shown control system for a unit step of 1 volt and a duration of 10 seconds.
Set the controller gains to: a) Kp=1; Ki=1 and Tv=1. b) Change the gain
values to: Kp=13; Ki=0.72 and Tv=0.0004. *Comment and compare between
the two responses.
The closed loop analysis for PID control with PT1 system shown below in
figure21:

a) Kp=1; Ki=1 and Tv=1.


After I wrote program of the closed loop analysis for PID controller, I
simulate it shown below in figure22:

Figure22: Closed loop response of PID controller.


After I simulate of the closed loop analysis for PID controller, I will do
calculations:
Givens: Kp=1 ; Ki=1; Tv=1 ; Vin=1V; t= 10 s
Requirements: Ton= ? ; Toff = ? ; ymax = ?T1= ?; Ksys=?; eb=?
Solution:
Experimentally:
Ton= 4.711s
Toff = 10 s
ymax = 0.022 V
Ksys= Vout/Vin = 1/1 = 1
Mohannad Alghamdi

0516320
2/7/2014

EE331

eb= |(VinVout)/Vin| *100 = |(11)/1|*100 = 0*100 = 0%


b) Kp=13; Ki=0.72 and Tv=0.0004.
After I wrote program of the closed loop analysis for PID controller, I
simulate it shown below in figure23:

Figure23: Closed loop response of PID controller.


After I simulate of the closed loop analysis for PID controller, I will do
calculations:
Givens: Kp=13 ; Ki=0.72 ; Tv=0.0004 ; Vin=1V; t= 10 s
Requirements: T1= ? ; Toff = ? ; ymax = ?T1= ?; Ksys=?; eb=?
Solution:
Experimentally:
T1= 0.11 s
Ksys= Vout/Vin = 1/1 = 1
eb= |(VinVout)/Vin| *100 = |(11)/1|*100 = 0*100 = 0%

Discussion:
By comparison between PID controller in two cases a and b, I found the
delay case b much less than case b, but in the error is all cases is the same
and error equal zero.
Mohannad Alghamdi

0516320
2/7/2014

EE331

Conclusion:
In the end of this lab I studied and analyzed controller types (P,I,PI,PD,
and PID) . Also, I examine closed loop analysis for each controller by
using PT1 first order system. Finally, I discuses and compare each
controller and I know it the advantage for each type.

Appendices:
Code of Experiment(1): a) Open loop analysis for proportional action control
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_p
kp=2.14;
nump=[0 kp];
denp=[0 1];
controller_p=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=5;
time=t.*duration;
amp=0.6;
system=controller_p;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+5])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(1): b) Closed loop analysis for proportional action control


(i.KP=1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
kp=1;
nump=[0 kp];
denp=[0 1];
controller_p=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t=0:0.0001:1;

Mohannad Alghamdi

0516320
2/7/2014

start code

plant pt1

controller_p

step response

EE331

duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_p;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(1): b) Closed loop analysis for proportional action control


(ii.KP=10)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_p
kp=10;
nump=[0 kp];
denp=[0 1];
controller_p=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_p;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(1): b) Closed loop analysis for proportional action control


(iii.KP=50)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc

Mohannad Alghamdi

0516320
2/7/2014

EE331

clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_p
kp=50;
nump=[0 kp];
denp=[0 1];
controller_p=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_p;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(2): a) Open loop analysis for integral action control


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=2;
time=t.*duration;
amp=1;
system=controller_I;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(2): b) Closed loop analysis for integral action control

Mohannad Alghamdi

0516320
2/7/2014

EE331

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code


clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_I;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(3): a) Open loop analysis for PI controller


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_P
kp=1;
nump=[0 kp];
denp=[0 1];
controller_P=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=2;
time=t.*duration;
amp=1;
controller_PI=controller_P+(controller_P*controller_I);
system=controller_PI;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-2 duration])
ylim([0 amp+5])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Mohannad Alghamdi

0516320
2/7/2014

EE331

Code of Experiment(3): b) Closed loop analysis for PI controller


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_P
kp=1;
nump=[0 kp];
denp=[0 1];
controller_P=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_PI
controller_PI=controller_P+(controller_P*controller_I);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_PI;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-2 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(4): a) Open loop analysis for PD controller


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
kp=1;
nump=[0 kp];
denp=[0 1];
controller_P=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Tv=1;
numd=[Tv 0];
dend=[0 1];
controller_D=tf(numd,dend);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t=0:0.0001:1;

Mohannad Alghamdi

0516320
2/7/2014

start code

controller_P

controller_I

controller_D

step response

EE331

duration=2;
time=t.*duration;
amp=1;
controller_PD=((controller_P+
(controller_P*controller_D))*controller_I);
system=controller_PD;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-2 duration])
ylim([0 amp+5])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(4): b) Closed loop analysis for PD controller


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_P
kp=1;
nump=[0 kp];
denp=[0 1];
controller_P=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_D
Tv=1;
numd=[Tv 0];
dend=[0 1];
controller_D=tf(numd,dend);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_PD
controller_PD=((controller_P+
(controller_P*controller_D))*controller_I);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_PD;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(5): a) Closed loop analysis for PID controller

Mohannad Alghamdi

0516320
2/7/2014

EE331

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code


clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1
ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_P
kp=1;
nump=[0 kp];
denp=[0 1];
controller_P=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=1;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_D
Tv=1;
numd=[Tv 0];
dend=[0 1];
controller_D=tf(numd,dend);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_PD
controller_PID=((controller_P+(controller_P*controller_D))+
(controller_P*controller_I));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_PID;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Code of Experiment(5): b) Closed loop analysis for PID controller


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start code
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plant pt1

Mohannad Alghamdi

0516320
2/7/2014

EE331

ksy=1;
t1=1;
num1=[0 ksy];
den1=[t1 1];
pt1=tf(num1,den1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_P
kp=13;
nump=[0 kp];
denp=[0 1];
controller_P=tf(nump,denp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_I
ki=0.72;
numi=[0 ki];
deni=[1 0];
controller_I=tf(numi,deni);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_D
Tv=0.0004;
numd=[Tv 0];
dend=[0 1];
controller_D=tf(numd,dend);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% controller_PD
controller_PID=((controller_P+(controller_P*controller_D))+
(controller_P*controller_I));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% step response
t=0:0.0001:1;
duration=10;
time=t.*duration;
amp=1;
fg=pt1*controller_PID;
fb=feedback(fg,1);
system=fb;
y=step(system*amp,time);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting
figure
plot(time,y,'linewidth',2)
hold on
plot(time,time.*0+amp,'r',time.*0,t*amp,'r')
xlim([-0.5 duration])
ylim([0 amp+0.2])
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code

Mohannad Alghamdi

0516320
2/7/2014

EE331

Вам также может понравиться