summaryrefslogtreecommitdiff
path: root/1202/CH13/EX13.3/13_3.sce
blob: c2dcfd28f48aaf86a61f308731ea38b13e6a149e (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
clear
clc

//Example 13.3
disp('Example 13.3')

function bodegen(num,den,w,lf,delay)
//Bode plot
//Numerator and denominator are passed as input arguments
//Both are polynomials in powers of s(say)

//This function has been modified from the original one 
//written by Prof Kannan Moudgalya, Dept of ChemE, IIT-B
G = num/den;
G1 = horner(G,%i*w);
G1p = phasemag(G1)-delay*w*180/%pi;

if LF == "normal" then 
   xset('window',0); clf();
   subplot(2,1,1)
   plot2d(w,abs(G1),logflag="nn",style = 2); 
   xtitle('Normal scale','','Magnitude'); xgrid();
   subplot(2,1,2)
   plot2d1(w,G1p,logflag="nn",style = 2);
   xgrid();
   xtitle('w(rad/sec)','','Phase(deg)');
elseif LF == "semilog" then 
   xset('window',1); clf();
   subplot(2,1,1)
   plot2d(w,20*log10(abs(G1)),logflag="ln",style = 2);
   xgrid(); 
   xtitle('Semilog','','Magnitude (dB)');
   subplot(2,1,2)
   plot2d1(w,G1p,logflag="ln",style = 2);
   xgrid();
   xtitle('w(rad/sec)','','Phase(deg)');
elseif LF == "loglog" then 
   xset('window',2); clf();
   subplot(2,1,1)
   plot2d(w,abs(G1),logflag="ll",style = 2); 
   xgrid();
   xtitle('Loglog','','Magnitude');
   subplot(2,1,2)
   plot2d1(w,G1p,logflag="ln",style = 2,rect=[0.01,-270,100,0]);//note the usage of rect for this particular example
   xgrid();
   xtitle('w(rad/sec)','','Phase(deg)');
end
endfunction;


s = %s;
num = 5*(0.5*s+1);
den = (20*s+1)*(4*s+1);
theta=1;

w = 0.001:0.002:10*%pi;
LF = "loglog" // Warning: Change this as necessary

bodegen(num,den,w,LF,theta);

//Checking using iodelay toolbox in scilab
//G=syslin('c',num/den);
//G=iodelay(G,1)
//bode(G,0.01,0.1)