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)
16 nc=size(ax.children,"*")
18 ax.data_bounds=[-360,-40;0,40];
22 ax.title.text=_("Amplitude and phase contours of y/(1+y)")
23 ax.x_label.text=_("phase(y) (degree)");
24 ax.y_label.text=_("magnitude(y) (dB)");
26 ax.data_bounds(2,2)=max( ax.data_bounds(2,2),40)
28 ax.clip_state="clipgrf"
30 phi_min=ax.data_bounds(1,1)
31 phi_max=ax.data_bounds(2,1)
32 mod_min=ax.data_bounds(1,2)
33 mod_max=ax.data_bounds(2,2)
35 defaultArgs = [1 5 10 20 30 50 90 120 150 180]
36 defaultModules=[mod_min:20:-40 -12 -6 -3 -1 0 0.25 0.5 1 2.3 4 6 12];
39 if exists("modules","local")==0 then
40 modules=defaultModules
42 if type(modules)<>1|~isreal(modules) then
43 error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"nicholschart","modules");
45 modules=matrix(modules,1,-1)
47 if exists("args","local")==0 then
50 if type(args)<>1|~isreal(args) then
51 error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"nicholschart","args");
53 args=matrix(args,1,-1)
56 if exists("colors","local")==0 then
59 if type(colors)<>1|~isreal(colors) then
60 error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"hallchart","colors");
62 if size(colors,"*")==1 then
63 colors=colors*ones(1,2)
66 // convert args to radian and insure negative
67 args = -abs(args) * ratio;
69 //initialize handles array for chart entities
76 //isogain curves: y as fixed gain and varying phase
77 //-------------------------------------------------
79 w=[linspace(-%pi,-0.1,100) linspace(-0.1,0,80) ]
81 for i = 1:prod(size(modules)),
83 y=10^(att/20)*exp(%i*w);
84 y(y==1)=[];//remove singular point if any
86 [module, phi]=dbphi(rf)
87 //use symetry and period to extend the curve on [k1*180 k2*180]
91 if pmodulo(k,2)==0 then
92 p=[p cut k*180-phi($:-1:1)]
93 m=[m cut module($:-1:1)]
95 str=msprintf("%.2gdB",att)
97 xstring(k*180-phi($)-r(3)/2,module($),str,0,0),
99 e.font_foreground=colors(1)
102 l=find(module>mod_max-r(4),1)
104 xstring(k*180-phi(l-1),module(l-1),"0dB",0,0),
106 e.font_foreground=colors(1)
111 p=[p cut ((k+1)*180)+phi]
114 str=msprintf("%.2gdB",att)
116 xstring(p($)-r(3),m($),str,0,0),
118 e.font_foreground=colors(1)
126 e.foreground=colors(1),
128 datatipInitStruct(e,"formatfunction","formatNicholsGainTip","gain",att)
130 if size(S,"*")>1 then S=glue(S),end
131 chart_handles=[glue([S,e]),chart_handles];
135 //isophase curves: y as fixed phase and varying gain
136 //-------------------------------------------------
142 //w = teta produce a 0 gain and consequently a singularity in module
143 if teta < -%pi/2 then
148 //use logarithmic discretization to have more mesh points near low modules
149 w=real(logspace(log10(-last),log10(170*ratio),150))
153 module=real(20*log((sin(w)*cos(teta)/sin(teta)-cos(w)))/l10)
155 //use symetry and period to extend the curve on [k1*180 k2*180]
158 if pmodulo(k,2)==0 then
159 p=[p %nan k*180-w($:-1:1)]
160 m=[m %nan module($:-1:1)]
162 p=[p %nan ((k+1)*180)+w]
168 e.foreground=colors(2);
170 datatipInitStruct(e,"formatfunction", ...
171 "formatNicholsPhaseTip","phase",teta*180/%pi)
172 chart_handles=[e chart_handles]
175 chart_handles=glue(chart_handles)
176 //reorder axes children to make chart drawn before the black curves if any
178 swap_handles(ax.children(k),ax.children(k+1))
183 function str=formatNicholsGainTip(curve,pt,index)
184 //This function is called by the datatip mechanism to format the tip
185 //string for the Nichols chart iso gain curves.
186 ud=datatipGetStruct(curve);
187 str=msprintf("%.2g"+_("dB"),ud.gain);
189 function str=formatNicholsPhaseTip(curve,pt,index)
190 //This function is called by the datatip mechanism to format the tip
191 //string for the Nichols chart iso phase curves.
192 ud=datatipGetStruct(curve);
193 str=msprintf("%.2g"+_("°"),ud.phase)