bug 11519 : Do not invert the curves order.
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / nyquist.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) ????-2010 - INRIA - Serge Steer
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- TEST WITH GRAPHIC -->
9 // <-- ENGLISH IMPOSED -->
10
11 function r=checknyquist(Args,leg)
12   if size(Args)==1 then Args($+1)=1d-3; Args($+1)=1d+3;end
13   [frq,rf,splitf]=repfreq(Args(:));repi=imag(rf);repf=real(rf);
14   [mn,n]=size(rf);
15   splitf($+1)=n+1;
16
17   ksplit=1;sel=splitf(ksplit):splitf(ksplit+1)-1;
18   R=[repf(:,sel)];  I=[repi(:,sel)];
19   for ksplit=2:size(splitf,'*')-1
20     sel=splitf(ksplit):splitf(ksplit+1)-1
21     R=[R %nan(ones(mn,1)) repf(:,sel)];
22     I=[I %nan(ones(mn,1)) repi(:,sel)];
23   end
24   //use symetry
25   R=[R R(:,$:-1:1)];
26   I=[I -I(:,$:-1:1)];
27
28   l=find(~isnan(R(1,:)))
29   fig=gcf();
30   r=0
31   a=fig.children;
32
33   if a.log_flags<>'nnn' then r=1;return,end
34   if or(a.axes_visible<>["on","on","on"]) then r=2;return,end
35
36   n=size(Args(1),1)
37   n1=size(a.children,'*')
38   if (argn(2)==1&(n<>n1))|(argn(2)==2&(n+1<>n1)) then r=3;return,end
39   for k=1:n;
40     if a.children($+1-k).type<>'Compound' then r=4;return,end
41     if size(a.children($+1-k).children,'*')<>2  then r=5;return,end
42     if a.children($+1-k).children(1).type<>'Compound'  then r=6;return, end
43     if a.children($+1-k).children(2).type<>'Polyline'  then r=7;return, end
44     if %f then //temporarily removed for 5.0
45       if a.children($+1-k).children(1).children(1).type<>'Segs' then r=8;return, end
46       ns=size(a.children($+1-k).children(1).children(1).data,1);
47       if size(a.children($+1-k).children(1).children,'*')-2<>(ns/2) then r=9;return, end
48       if or(a.children($+1-k).children(1).children(2:$).type<>'Text') then r=10;return, end
49     end
50     if or(l<>find(~isnan(a.children($+1-k).children(2).data(:,1)))) then r=11;return, end
51     if norm(a.children($+1-k).children(2).data(l,:)-[R(k,l)' I(k,l)'])> 1d-14 then r=12;return, end
52     s= a.children($+1-k).children(1).children(1);
53   end
54   if argn(2)==2 then //test the legend
55     if size(a.children,'*')<=n then r=13;return,end
56     if a.children(1).type<>'Legend' then r=14;return,end
57     if size(a.children(1).links,'*')<>n then r=15;return,end
58     if or(a.children(1).text<>leg(:)) then r=16;return,end
59   end
60 endfunction
61
62
63 s=poly(0,'s');
64 n=1+s;d=1+2*s;
65 h=syslin('c',n,d);
66 sl=tf2ss(h);
67 sld=dscr(sl,0.01);
68 hd=ss2tf(sld);
69
70 [w,rf]=repfreq(h,0.01,100);
71
72 //continuous time
73 clf();nyquist(h);
74 if checknyquist(list(h)) then pause,end
75 clf();nyquist(h,'h');
76 if checknyquist(list(h),'h') then pause,end
77
78 clf();nyquist(h,0.01,100);
79 if checknyquist(list(h,0.01,100)) then pause,end
80 clf();nyquist(h,0.01,100,'h');
81 if checknyquist(list(h,0.01,100),'h') then pause,end
82
83 clf();nyquist(h,0.01,100,0.01)
84 if checknyquist(list(h,0.01,100,0.01)) then pause,end
85 clf();nyquist(sl,0.01,100);
86 if checknyquist(list(sl,0.01,100)) then pause,end
87 clf();nyquist(sl,0.01,100,0.01)
88 if checknyquist(list(sl,0.01,100,0.01)) then pause,end
89
90 //continuous time SIMO
91 h=[h;h+1];sl=[sl;sl+1];
92 clf();nyquist(h);
93 if checknyquist(list(h)) then pause,end
94 clf();nyquist(h,['h';'h+1']);
95 if checknyquist(list(h),['h';'h+1']) then pause,end
96
97 clf();nyquist(h,0.01,100);
98 if checknyquist(list(h,0.01,100)) then pause,end
99 clf();nyquist(h,0.01,100,['h';'h+1']);
100 if checknyquist(list(h,0.01,100),['h';'h+1']) then pause,end
101
102 clf();nyquist(h,0.01,100,0.01)
103 if checknyquist(list(h,0.01,100,0.01)) then pause,end
104 clf();nyquist(sl,0.01,100);
105 if checknyquist(list(sl,0.01,100)) then pause,end
106 clf();nyquist(sl,0.01,100,0.01)
107 if checknyquist(list(sl,0.01,100,0.01)) then pause,end
108
109 //discrete case
110 clf();nyquist(hd);
111 if checknyquist(list(hd)) then pause,end
112 clf();nyquist(hd,'h');
113 if checknyquist(list(hd),'h') then pause,end
114
115 clf();nyquist(hd,0.01,100);
116 if checknyquist(list(hd,0.01,100)) then pause,end
117 clf();nyquist(hd,0.01,100,'h');
118 if checknyquist(list(hd,0.01,100),'h') then pause,end
119
120 clf();nyquist(hd,0.01,100,0.01)
121 if checknyquist(list(hd,0.01,100,0.01)) then pause,end
122 clf();nyquist(sld,0.01,100);
123 if checknyquist(list(sld,0.01,100)) then pause,end
124 clf();nyquist(sld,0.01,100,0.01)
125 if checknyquist(list(sld,0.01,100,0.01)) then pause,end
126
127 //discrete case SIMO
128 hd=[hd;hd+1];sld=[sld;sld+1];
129 clf();nyquist(hd);
130 if checknyquist(list(hd)) then pause,end
131 clf();nyquist(hd,['h';'h+1']);
132 if checknyquist(list(hd),['h';'h+1']) then pause,end
133
134 clf();nyquist(hd,0.01,100);
135 if checknyquist(list(hd,0.01,100)) then pause,end
136 clf();nyquist(hd,0.01,100,['h';'h+1']);
137 if checknyquist(list(hd,0.01,100),['h';'h+1']) then pause,end
138
139 clf();nyquist(hd,0.01,100,0.01)
140 if checknyquist(list(hd,0.01,100,0.01)) then pause,end
141 clf();nyquist(sld,0.01,100);
142 if checknyquist(list(sld,0.01,100)) then pause,end
143 clf();nyquist(sld,0.01,100,0.01)
144 if checknyquist(list(sld,0.01,100,0.01)) then pause,end
145
146 //nyquist given by precmputed freqency response
147
148 clf(); nyquist(w,rf)
149 clf(); nyquist(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)))
150
151 // check legend color
152 clf();
153 F1=syslin('c',(2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
154 F2=syslin('c',(0.88*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
155 F3=syslin('c',(100*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
156 nyquist ([F1;F2;F3],0.0 ,1000,["F1(Kr=1)";"F2(Kr=0,88)";"F3(Kr=10)"],%f)
157 a=gca();
158 assert_checkequal(a.children(1).links.foreground, [3, 2, 1]); // [green blue black]