summaryrefslogtreecommitdiff
path: root/3432/CH6/EX6.17/Ex6_17.sce
blob: 22af946e44f0b515ab0390aec5b77719e4e4b7ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Example 6.17
//Lag compensation for Temperature Control System.

xdel(winsid())//close all graphics Windows
clear;
clc;
//------------------------------------------------------------------
//System transfer function 
s=poly(0,'s');
numG=1;
denG=(s/0.5+1)*(s+1)*(s/2+1);
G=numG/denG;
//Dc gain
K=3; //to set phase requirement

KGs=syslin('c',K*G);

//Lag compensator
numD=5*s+1;
denD=15*s+1;
D=3*numD/denD;
Ds=syslin('c',D);

KGDs=Ds*KGs; //compensated system

//The bode plot of the system with K
bode([KGs;KGDs],0.01/2/%pi,10/2/%pi,['KG';'KGD'],"rad");
exec .\fig_settings.sci; //custom script for setting figure properties
title('Frequency response of lag-compensation design','fontsize',3)

//------------------------------------------------------------------
//Margins of uncompensated and compensated systems
[gm1,wcg1]=g_margin(KGs);
[pm1,wcp1]=p_margin(KGs);
disp(wcp1*2*%pi,"Wcp",wcg1*2*%pi,"Wcg",pm1,"Phase margin",...
gm1,"Gain margin","Uncompensated system :")

[gm2,wcg2]=g_margin(KGDs);
[pm2,wcp2]=p_margin(KGDs);
disp(wcp2*2*%pi,"Wcp",wcg2*2*%pi,"Wcg",pm2,"Phase margin",...
gm2,"Gain margin","Compensated system :")

//------------------------------------------------------------------
//step response
//closed loop system
Gc=KGDs/(KGDs+1);
figure;
t=0:0.05:20;
v=csim('step',t,Gc);
plot2d(t,v)

//Title, labels and grid to the figure
exec .\fig_settings.sci; //custom script for setting figure properties
title('Step response for lag compensation design','fontsize',3)
xlabel('Time t (sec.)','fontsize',2)
ylabel('y','fontsize',2)
//------------------------------------------------------------------