* Bug #12793 fixed (proposal 2) - Cacsd: improve the bode() plots
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / bode.dia.ref
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2008 - INRIA - Serge Steer
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 //
8 // <-- TEST WITH GRAPHIC -->
9 //
10 // <-- ENGLISH IMPOSED -->
11 //
12 function r=checkbode(h,leg)
13     fig=gcf();
14     r=%t;
15     ap=fig.children(1);
16     am=fig.children(2);
17     if am.log_flags<>"lnn" then r=%f;return,end
18     if or(am.axes_visible<>["on","on","on"]) then r=%f;return,end
19     if ap.log_flags<>"lnn" then  r=%f;return,end
20     if or(ap.axes_visible<>["on","on","on"]) then r=%f;return,end
21     n=size(am.children($).children,"*");
22     if n<>size(h,1) then bugmes();quit;end
23     for k=1:n;
24         pm=am.children($).children(n+1-k);
25         pp=ap.children($).children(n+1-k);
26         if or(pm.data(:,1)<>pp.data(:,1)) then ;r=%f;return,end
27         [frq,rf]=repfreq(h(k,1),pm.data(:,1));[phi,d]=phasemag(rf);
28         if norm(d(:)-pm.data(:,2))> 1d-15 then r=%f;return,end
29     end
30     if argn(2)==2 then
31         if size(ap.children,"*")<2 then r=%f;return,end
32         if ap.children(1).type<>"Legend" then r=%f;return,end
33         if size(ap.children(1).links,"*")<>n then r=%f;return,end
34         if or(ap.children(1).text<>leg(:)) then r=%f;return,end
35     end
36 endfunction
37 s=poly(0,"s");
38 n=1+s;d=1+2*s;
39 h=syslin("c",n,d);
40 sl=tf2ss(h);
41 sld=dscr(sl,0.01);
42 hd=ss2tf(sld);
43 [w,rf]=repfreq(h,0.01,100);
44 // Continuous time
45 clf();bode(h);
46 if ~checkbode(h) then bugmes();quit;end
47 clf();bode(h,"h");
48 if ~checkbode(h,"h") then bugmes();quit;end
49 clf();bode(h,0.01,100);
50 if ~checkbode(h) then bugmes();quit;end
51 clf();bode(h,0.01,100,"h");
52 if ~checkbode(h,"h") then bugmes();quit;end
53 clf();bode(h,0.01,100,0.01);
54 if ~checkbode(h) then bugmes();quit;end
55 clf();bode(sl,0.01,100);
56 if ~checkbode(sl) then bugmes();quit;end
57 clf();bode(sl,0.01,100,0.01);
58 // Continuous time SIMO
59 h=[h;h+1];sl=[sl;sl+1];
60 clf();bode(h);
61 if ~checkbode(h) then bugmes();quit;end
62 clf();bode(h,["h";"h+1"]);
63 if ~checkbode(h,["h";"h+1"]) then bugmes();quit;end
64 clf();bode(h,0.01,100);
65 if ~checkbode(h) then bugmes();quit;end
66 clf();bode(h,0.01,100,["h";"h+1"]);
67 if ~checkbode(h,["h";"h+1"]) then bugmes();quit;end
68 clf();bode(h,0.01,100,0.01);
69 if ~checkbode(h) then bugmes();quit;end
70 clf();bode(sl,0.01,100);
71 if ~checkbode(sl) then bugmes();quit;end
72 clf();bode(sl,0.01,100,0.01);
73 // Discrete case
74 clf();bode(hd);
75 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
76 if ~checkbode(hd) then bugmes();quit;end
77 clf();bode(hd,"h");
78 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
79 if ~checkbode(hd,"h") then bugmes();quit;end
80 clf();bode(hd,0.01,100);
81 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
82 if ~checkbode(hd) then bugmes();quit;end
83 clf();bode(hd,0.01,100,"h");
84 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
85 if ~checkbode(hd,"h") then bugmes();quit;end
86 clf();bode(hd,0.01,100,0.01);
87 if ~checkbode(hd) then bugmes();quit;end
88 clf();bode(sld,0.01,100);
89 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
90 if ~checkbode(sld) then bugmes();quit;end
91 clf();bode(sl,0.01,100,0.01);
92 // Discrete case SIMO
93 hd=[hd;hd+1];sld=[sld;sld+1];
94 clf();bode(hd);
95 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
96 if ~checkbode(hd) then bugmes();quit;end
97 clf();bode(hd,["h";"h+1"]);
98 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
99 if ~checkbode(hd,["h";"h+1"]) then bugmes();quit;end
100 clf();bode(hd,0.01,100);
101 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
102 if ~checkbode(hd) then bugmes();quit;end
103 clf();bode(hd,0.01,100,["h";"h+1"]);
104 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
105 if ~checkbode(hd,["h";"h+1"]) then bugmes();quit;end
106 clf();bode(hd,0.01,100,0.01);
107 if ~checkbode(hd) then bugmes();quit;end
108 clf();bode(sld,0.01,100);
109 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
110 if ~checkbode(sld) then bugmes();quit;end
111 clf();bode(sl,0.01,100,0.01);
112 // bode given by precomputed frequency response
113 h=syslin("c",n,d);
114 clf();bode(h,0.01,100);
115 fig=gcf();
116 dp=fig.children(1).children($).children.data;
117 dm=fig.children(2).children($).children.data;
118 [w,rf]=repfreq(h,0.01,100);
119 clf(); bode(w,rf);
120 fig=gcf();
121 if norm(dp-fig.children(1).children($).children.data)>1d-13 then bugmes();quit;end
122 if norm(dm-fig.children(2).children($).children.data)>1d-13 then bugmes();quit;end
123 clf(); bode(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)))
124 fig=gcf();
125 if norm(dp-fig.children(1).children($).children.data)>1d-13 then bugmes();quit;end
126 if norm(dm-fig.children(2).children($).children.data)>1d-13 then bugmes();quit;end
127 // Bode_asymp()
128 s = %s;
129 G = (s+10)/(s*(s+100)); // A rational matrix
130 sys = syslin("c", G); // A continuous-time linear system in transfer matrix representation.
131 f_min = .0001; f_max = 1600; // Frequencies in Hz
132 clf(); bode(sys, f_min, f_max, "rad"); // The optional argument "rad" converts Hz to rad/s
133 bode_asymp(sys, 10, 1000); // Plots asymptotes in the given range of frequency (in rad/s).