1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2010 - INRIA - Serge STEER
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution. The terms
6 // are also available at
7 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9 function nicholschart(modules,args,colors)
15 immediate_drawing=fig.immediate_drawing;
16 fig.immediate_drawing="off";
19 nc=size(ax.children,"*")
21 ax.data_bounds=[-360,-40;0,40];
25 ax.title.text=_("Amplitude and phase contours of y/(1+y)")
26 ax.x_label.text=_("phase(y) (degree)");
27 ax.y_label.text=_("magnitude(y) (dB)");
29 ax.data_bounds(2,2)=max( ax.data_bounds(2,2),40)
31 ax.clip_state="clipgrf"
33 phi_min=ax.data_bounds(1,1)
34 phi_max=ax.data_bounds(2,1)
35 mod_min=ax.data_bounds(1,2)
36 mod_max=ax.data_bounds(2,2)
38 defaultArgs = [1 2 5 10 20 30 50 70 90 120 140 160 180];
39 defaultModules=[mod_min:20:-35 -30 -25 -20 -15 -12 -9 -6 -3 -2 -1 -0.5 -0.25 -0.1 0 0.1 0.25 0.5 1 2.3 4 6 12];
42 if exists("modules","local")==0 then
43 modules=defaultModules
45 if type(modules)<>1|~isreal(modules) then
46 error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"nicholschart","modules");
48 modules=matrix(modules,1,-1)
50 if exists("args","local")==0 then
53 if type(args)<>1|~isreal(args) then
54 error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"nicholschart","args");
56 args=matrix(args,1,-1)
59 if exists("colors","local")==0 then
62 if type(colors)<>1|~isreal(colors) then
63 error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"hallchart","colors");
65 if size(colors,"*")==1 then
66 colors=colors*ones(1,2)
69 // convert args to radian and insure negative
70 args = -abs(args) * ratio;
72 //initialize handles array for chart entities
79 //isogain curves: y as fixed gain and varying phase
80 //-------------------------------------------------
82 w=[linspace(-%pi,-0.1,100) linspace(-0.1,0,80) ]
84 for i = 1:prod(size(modules)),
86 y=10^(att/20)*exp(%i*w);
87 y(y==1)=[];//remove singular point if any
89 [module, phi]=dbphi(rf)
90 //use symetry and period to extend the curve on [k1*180 k2*180]
94 if pmodulo(k,2)==0 then
95 p=[p cut k*180-phi($:-1:1)]
96 m=[m cut module($:-1:1)]
98 str=msprintf("%.2gdB",att)
100 xstring(k*180-phi($)-r(3)/2,module($),str,0,0),
102 e.font_foreground=colors(1)
105 l=find(module>mod_max-r(4),1)
107 xstring(k*180-phi(l-1),module(l-1),"0dB",0,0),
109 e.font_foreground=colors(1)
114 p=[p cut ((k+1)*180)+phi]
117 str=msprintf("%.2gdB",att)
119 xstring(p($)-r(3),m($),str,0,0),
121 e.font_foreground=colors(1)
129 e.foreground=colors(1),
131 datatipInitStruct(e,"formatfunction","formatNicholsGainTip","gain",att)
133 if size(S,"*")>1 then S=glue(S),end
134 chart_handles=[glue([S,e]),chart_handles];
138 //isophase curves: y as fixed phase and varying gain
139 //-------------------------------------------------
145 //w = teta produce a 0 gain and consequently a singularity in module
146 if teta < -%pi/2 then
151 //use logarithmic discretization to have more mesh points near low modules
152 w=real(logspace(log10(-last),log10(170*ratio),150))
156 module=real(20*log((sin(w)*cos(teta)/sin(teta)-cos(w)))/l10)
158 //use symetry and period to extend the curve on [k1*180 k2*180]
161 if pmodulo(k,2)==0 then
162 p=[p %nan k*180-w($:-1:1)]
163 m=[m %nan module($:-1:1)]
165 p=[p %nan ((k+1)*180)+w]
171 e.foreground=colors(2);
173 datatipInitStruct(e,"formatfunction", ...
174 "formatNicholsPhaseTip","phase",teta*180/%pi)
175 chart_handles=[e chart_handles]
178 chart_handles=glue(chart_handles)
179 //reorder axes children to make chart drawn before the black curves if any
181 swap_handles(ax.children(k),ax.children(k+1))
184 fig.immediate_drawing=immediate_drawing;
187 function str=formatNicholsGainTip(curve,pt,index)
188 //This function is called by the datatip mechanism to format the tip
189 //string for the Nichols chart iso gain curves.
190 ud=datatipGetStruct(curve);
191 str=msprintf("%.2g"+_("dB"),ud.gain);
194 function str=formatNicholsPhaseTip(curve,pt,index)
195 //This function is called by the datatip mechanism to format the tip
196 //string for the Nichols chart iso phase curves.
197 ud=datatipGetStruct(curve);
198 str=msprintf("%.2g°",ud.phase)