a9e37f5ec1abad8349592cc90ba2dbadf583b89d
[scilab.git] / scilab / modules / cacsd / macros / show_margins.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA -  Author: Serge Steer
3 // 
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at    
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 function show_margins(h,typ)
11   if argn(2)<2 then typ='bode',end
12   if and(typ<>['nyquist','bode']) then
13     error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
14                    "show_margins",2,'""nyquist"", ""bode""'))
15   end
16   drawlater();clf();
17   if typ=="bode" then
18     bode(h)
19     f=gcf();
20     axg=f.children(2);
21     axp=f.children(1);
22     fmin=min(axg.x_ticks.locations);
23     fmax=max(axg.x_ticks.locations);
24     gmin=min(axg.y_ticks.locations);
25     gmax=max(axg.y_ticks.locations);
26     pmin=min(axp.y_ticks.locations);
27     pmax=max(axp.y_ticks.locations);
28
29     [gm,fr]=g_margin(h)
30     sca(axp);
31     xpoly([fmin;fmax],[-180;-180])
32     e=gce();e.foreground=color('red');e.line_style=4;
33     if fr<>[] then
34       xpoly([fr;fr],[pmin;pmax])
35       e=gce();e.foreground=color('red');e.line_style=4;
36       sca(axg);
37       xpoly([fr;fr],[gmin;gmax])
38       e=gce();e.foreground=color('red');e.line_style=4;
39       xpoly([fr;fr],[-gm;0])
40       e=gce();e.foreground=color('red');e.thickness=2;
41     end
42
43     [phm,fr]=p_margin(h)
44     sca(axg);
45     xpoly([fmin;fmax],[0;0])
46     e=gce();e.foreground=color('blue');e.line_style=4;
47     if fr<>[] then
48       xpoly([fr;fr],[gmin;gmax])
49       e=gce();e.foreground=color('blue');e.line_style=4;
50       sca(axp);
51       xpoly([fr;fr],[pmin;pmax])
52       e=gce();e.foreground=color('blue');e.line_style=4;
53       xpoly([fr;fr],[-180;phm-180])
54       e=gce();e.foreground=color('blue');e.thickness=2;
55     end
56   else
57     nyquist(h)
58     ax=gca();
59     [gm,fr]=g_margin(h)
60     xpoly([min(ax.x_ticks.locations);0],[0;0]);
61     e=gce();e.foreground=color('blue');e.line_style=4;
62     if fr<>[] then
63       if h.dt=='c' then
64         f=horner(h,2*%i*%pi*fr)
65       else
66         dt=h.dt;if dt=='d' then dt=1,end
67         f=horner(h,exp(2*%i*%pi*fr*dt))
68       end
69       xpoly([real(f);0],[0;0]);
70       e=gce();e.foreground=color('blue');e.thickness=2;
71     end
72     [phm,fr]=p_margin(h)
73     //unit circle
74     t=linspace(0,2*%pi,100);
75     xpoly(sin(t),cos(t))
76     e=gce();e.foreground=color('red');e.line_style=4;
77     if fr<>[] then
78       t=phm*%pi/180+%pi;
79       xpoly([cos(t);0],[sin(t);0])
80       e=gce();e.foreground=color('red');e.thickness=2;
81     end
82   end
83   
84   
85   drawnow()
86 endfunction