1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 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 chart(attenu,angl,flags)
11 titre=_("Amplitude and phase contours of y/(1+y)")
14 defaultAngles = [1:10,20:10:160];
23 if type(angl)==15 then
24 // angl actually stands for flags
33 if type(attenu)==15 then
35 attenu=[-12 -8 -6 -5 -4 -3 -2 -1.4 -1 -.5 ,..
36 0.25 0.5 0.7 1 1.4 2 2.3 3 4 5 6 8 12];
43 attenu=[-12 -8 -6 -5 -4 -3 -2 -1.4 -1 -.5 ,..
44 0.25 0.5 0.7 1 1.4 2 2.3 3 4 5 6 8 12];
48 // convert angles to radian
51 c1=color('lightgrey');c2=c1
54 flags=list(0,-1,c1,c2)
56 flags=list(flags(1),-1,c1,c2)
58 flags=list(flags(1),flags(2),c1,c2)
68 ax.data_bounds=[-360,-50;0,40];
75 ax.clip_state="clipgrf"
76 // ax.data_bounds=[0,-50;360,40];
78 phi_min=ax.data_bounds(1,1)
79 phi_max=ax.data_bounds(2,1)
85 immediate_drawing=fig.immediate_drawing;
86 fig.immediate_drawing="off";
88 if flags(2) then xtitle(titre,_("phase(y) (degree)"),_("magnitude(y) (Db)")),end
89 llrect=xstringl(0,0,'1')
92 lambda=exp(l10*attenu/20)
93 rayon=lambda./(lambda.*lambda-ones(lambda))
97 for i = 1:prod(size(attenu)),
105 rf=centre(i)*ones(w)+rayon(i)*exp(%i*w);
106 phi=atan(imag(rf),real(rf))/ratio; //phi is in [-180 0]
107 module=20*log(abs(rf))/l10;
109 //use symetry and period to extend the curve on [k1*180 k2*180]
113 if pmodulo(k,2)==0 then
114 p=[p %nan k*180-phi($:-1:1)]
115 m=[m %nan module($:-1:1)]
117 xstring(p($),m($),string(att),0,0),
119 if ~flags(1) then e.clip_state='off';end
123 p=[p %nan ((k+1)*180)+phi]
126 xstring(p($),m($),string(att),0,0),
128 if ~flags(1) then e.clip_state='off';end
135 e=gce();e.foreground=flags(3);//e.line_style=3,
136 if size(S,'*')>1 then S=glue(S),end
137 S=glue([S,e]);S.user_data=att;
139 glue(ax.children(size(attenu,'*'):-1:1))
145 if teta < -%pi/2 then
150 w=[-170*ratio:0.03:last last]
152 module=real(20*log((sin(w)*cos(teta)/sin(teta)-cos(w)))/l10)
156 if pmodulo(k,2)==0 then
157 p=[p %nan k*180-w($:-1:1)]
158 m=[m %nan module($:-1:1)]
160 p=[p %nan ((k+1)*180)+w]
165 e=gce();e.foreground=flags(3);//e.line_style=3,
168 glue(ax.children(size(angl,'*'):-1:1))
170 fig.immediate_drawing=immediate_drawing;