summaryrefslogtreecommitdiff
path: root/3432/CH3/EX3.4/Ex3_4.sce
blob: dacf05a5f62ef2fac5bdfb39d2dcd40da636a1c7 (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
58
59
60
61
62
63
64
65
//Example 3.4
//Frequency response

xdel(winsid())//close all graphics Windows
clear;
clc;
//------------------------------------------------------------------
//(a) Frequency response of 1/(s+k)
k=1;
fmin=1e-2;
fmax=1e2;
// Transfer function
s=poly(0,'s');
sysH=syslin('c',1/(s+k))

//Frequency response for k=1 
//Note that - magnitude plot semilog plot unlike log-log plot in the book.
bode(sysH,fmin,fmax)
title('Frequency response for k=1','fontsize',3)

//------------------------------------------------------------------
//(b) Response to u=sin(10*t);
t=0:0.02:10;
u=sin(10*t);
y=csim(u,t,sysH);
figure, plot(t,y)

//Title, labels and grid to the figure
exec .\fig_settings.sci; // custom script for setting figure properties
title('Complete transient response','fontsize',3)
xlabel('Time (sec.)','fontsize',2)
ylabel('Output','fontsize',2)

//phase lag
figure, plot(t,y)
plot(t,u,'r')
zoom_rect([9 -1 10 1])
exec .\fig_settings.sci; // custom script for setting figure properties
title('Phase lag between output and input','fontsize',3)
xlabel('Time (sec.)','fontsize',2)
ylabel('Output, Input','fontsize',2)
h=legend('y(t)','u(t)')
h.legend_location = "in_upper_right"
h.fill_mode='off'

// time lag
w=find(t>=9.4 & t<=10);
T=t(w);
Y=y(w);
U=u(w);
wu=find(U==max(U))
wy=find(Y==max(Y))

//Responses
plot2d3(T(wy),Y(wy))
plot2d3(T(wu),U(wu))
delta_t=T(wu)-T(wy); //time lag sec.
xstring(9.64,-0.1,"$\delta t$",0,0)
xarrows([9.58;9.72], [0;0], 0.7, 1)
xarrows([9.72;9.58], [0;0], 0.7, 1)
t=get("hdl") 
disp(abs(delta_t), "Time lag of output in sec. is")
disp(abs(delta_t)*10, "Phase lag of output in radians is")

//------------------------------------------------------------------