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