From 83cc90cfd13a7115b914289f976fa325fc2da862 Mon Sep 17 00:00:00 2001 From: Serge Steer Date: Mon, 17 May 2010 18:13:48 +0200 Subject: [PATCH] bug 6394 fix + datatips custimization + revision of help pages Change-Id: I808e268c1153493733ba1c81474c4def8641f525 --- scilab/CHANGES_5.3.X | 25 ++- scilab/modules/cacsd/help/en_US/black.xml | 89 ++++++---- scilab/modules/cacsd/help/en_US/hallchart.xml | 129 ++++++++++++++ scilab/modules/cacsd/help/en_US/m_circle.xml | 9 +- scilab/modules/cacsd/help/en_US/nicholschart.xml | 112 ++++++++++++ scilab/modules/cacsd/help/images/black1.svg | 125 ++++++++++++++ scilab/modules/cacsd/help/images/black2.svg | 170 +++++++++++++++++++ scilab/modules/cacsd/help/images/hallchart.svg | 132 +++++++++++++++ scilab/modules/cacsd/help/images/nyquist2.svg | 197 ++++++++++++++++++++++ scilab/modules/cacsd/macros/black.sci | 142 +++++++++------- scilab/modules/cacsd/macros/hallchart.sci | 135 +++++++++++++++ scilab/modules/cacsd/macros/m_circle.sci | 88 +++++----- scilab/modules/cacsd/macros/nicholschart.sci | 190 +++++++++++++++++++++ 13 files changed, 1393 insertions(+), 150 deletions(-) create mode 100644 scilab/modules/cacsd/help/en_US/hallchart.xml create mode 100644 scilab/modules/cacsd/help/en_US/nicholschart.xml create mode 100644 scilab/modules/cacsd/help/images/black1.svg create mode 100644 scilab/modules/cacsd/help/images/black2.svg create mode 100644 scilab/modules/cacsd/help/images/hallchart.svg create mode 100644 scilab/modules/cacsd/help/images/nyquist2.svg create mode 100644 scilab/modules/cacsd/macros/hallchart.sci create mode 100644 scilab/modules/cacsd/macros/nicholschart.sci diff --git a/scilab/CHANGES_5.3.X b/scilab/CHANGES_5.3.X index b5dac8f..7b1323f 100644 --- a/scilab/CHANGES_5.3.X +++ b/scilab/CHANGES_5.3.X @@ -22,8 +22,8 @@ Graphics: * the set, get and uicontrol functions are now overloadable. -* Datatips tools added, the frequency response plots ("bode", "black", "nyquist", - "gainplot",...) supports cutomized datatips. +* Datatips tools added, the frequency response plots ("bode", "black", + "nyquist", "gainplot",...) supports cutomized datatips. * bug 2651 fixed - "plot2d" was not working when the x argument was not given and some optional arguments were given. @@ -31,10 +31,11 @@ Graphics: * bug 3100 fixed - The "xselect" function has been made obsolete, in accordance with its help page. -* bug 3975 fixed - The "xload" function was not able to load the contents of a previously - saved graphics figure into a different one. +* bug 3975 fixed - The "xload" function was not able to load the contents of a + previously saved graphics figure into a different one. -* bug 4531 fixed - "legend" macros was not displaying any error when no 'Polyline' exist. +* bug 4531 fixed - "legend" macros was not displaying any error when no + 'Polyline' exist. * bug 4658 fixed - When some graphic functions were called without any arguments, the error was not explicit enough. @@ -42,7 +43,14 @@ Graphics: * bug 5284 fixed - In some case function "legend" drew line segments in its box in a reverse order. -* bug 6098 fixed - It was not possible get values by clicking on point of Bode diagram +* bug 6098 fixed - It was not possible get values by clicking on point of + Bode diagram. + +* bug 6394 fixed - The "black", "m_circle", "chart" functions has been + improved for a better rendering and datatips + customization. Two new functions created: "hallchart" + (superseed "m_circle") and "nicholschart" (superseed + "chart"). * bug 6532 fixed - In some case text entity rendering order was wrong. @@ -57,7 +65,8 @@ Graphics: * bug 6848 fixed - The patterns of the lines was poorly exported. -* bug 6958 fixed - The "tics_labels" property from "axes" rejected column vector of labels. +* bug 6958 fixed - The "tics_labels" property from "axes" rejected column vector + of labels. * bug 6959 fixed - axis.tics_labels did not accept $..$ LaTeXed labels @@ -353,7 +362,7 @@ Bug fixes: * bug 1304 fixed - macr2tree now works with a Scilab expression as input. -* bug 1371 fixed - The representation of floating numbers with exponent larger +* bug 1371 fixed - The representation of floating numbers with exponent larger than 100 or smaller than -100 was incorrect. * bug 2076 fixed - pspect did not use the last data window. diff --git a/scilab/modules/cacsd/help/en_US/black.xml b/scilab/modules/cacsd/help/en_US/black.xml index b74f7e8..90acd4b 100644 --- a/scilab/modules/cacsd/help/en_US/black.xml +++ b/scilab/modules/cacsd/help/en_US/black.xml @@ -2,11 +2,11 @@ @@ -25,16 +25,18 @@ black - Black's diagram (Nichols chart) + Black-Nichols diagram of a linear dynamical system Calling Sequence - black( sl,[fmin,fmax] [,step] [,comments] ) -black( sl,frq [,comments] ) -black(frq,db,phi [,comments]) -black(frq,repf [,comments]) + + black( sl,[fmin,fmax] [,step] [,comments] ) + black( sl,frq [,comments] ) + black(frq,db,phi [,comments]) + black(frq,repf [,comments]) + @@ -45,7 +47,8 @@ black(frq,repf [,comments]) sl - list ( linear system syslin) + a continuous or discrete time SIMO linear dynamical + system ( see: syslin). @@ -102,17 +105,16 @@ black(frq,repf [,comments]) Description - Black's diagram (Nichols'chart) for a linear system - sl. sl can be a continuous-time or - discrete-time SIMO system (see syslin). In case of - multi-output the outputs are plotted with different symbols. + Black's diagram (Nichols'chart) for a linear system ( see: syslin). sl can be a continuous-time or + discrete-time SIMO system. In case of + multi-output the outputs are plotted with different colors. The frequencies are given by the bounds fmin,fmax (in Hz) or by a row-vector (or a matrix for multi-output) frq. step is the ( logarithmic ) discretization step. - (see calfrq for the choice of default value). + (see calfrq for the choice of default value). comments is a vector of character strings (captions). @@ -125,7 +127,7 @@ black(frq,repf [,comments]) To plot the grid of iso-gain and iso-phase of y/(1+y) use chart(). + linkend="nicholschart">nicolschart(). Default values for fmin and fmax are 1.d-3, @@ -137,37 +139,54 @@ black(frq,repf [,comments]) Examples - + + + + + + + + + + + + + + + + See Also + nicholschart bode - nyquist - chart - - freq - - repfreq - + syslin calfrq - - phasemag + datatips diff --git a/scilab/modules/cacsd/help/en_US/hallchart.xml b/scilab/modules/cacsd/help/en_US/hallchart.xml new file mode 100644 index 0000000..c147f1e --- /dev/null +++ b/scilab/modules/cacsd/help/en_US/hallchart.xml @@ -0,0 +1,129 @@ + + + + + $LastChangedDate: 2008-06-19 18:44:44 +0200 (jeu, 19 jun 2008) $ + + + hallchart + Draws the Hall chart + + + Calling Sequence + hallchart([ modules [,args [,colors]]]) + + + + Parameters + + + modules + + real vector ( modules (in dB)) + + + + args + + real vector (phases (in degree)) + + + + colors + + a scalar or a vector, the color indices for isogain and iso phase curves + + + + + + Description + plot the Hall'chart: iso-module and iso-argument contours of + y/(1+y) in the real(y), imag(y) plane + hallchart may be used in cunjunction with + nyquist. + The default values for modules and + args are respectively : + + [-20 -10 -6 -4 -2 2 4 6 10 20] + + [-90 -60 -45 -30 -15 15 30 45 60 90] + This function superseeds the m_circle function + + + + Graphics entities organization + The hallchart function create a single + compound object which is generaly the last child of the current + axes. This compound object contains a set of compound objects, one + for each grid curve. The first ones are the iso module curves and + the last one the iso-argument contours. Each of these compound + objects contains a Polyline object (the curve) and a Text object + (the label). The following piece of code can be used to change the color of the ith iso module curve: + + + + + Examples + + + + + + + + + + + + + + + + + + + See Also + + nyquist + nicholschart + + + diff --git a/scilab/modules/cacsd/help/en_US/m_circle.xml b/scilab/modules/cacsd/help/en_US/m_circle.xml index 8a86d2a..fd9cd7e 100644 --- a/scilab/modules/cacsd/help/en_US/m_circle.xml +++ b/scilab/modules/cacsd/help/en_US/m_circle.xml @@ -2,11 +2,11 @@ @@ -16,7 +16,7 @@ m_circle - plots the complex plane iso-gain contours of y/(1+y) + plots the complex plane iso-gain contours of y/(1+y) (obsolete) Calling Sequence @@ -52,10 +52,11 @@ m_circle(gain) [-12 -8 -6 -5 -4 -3 -2 -1.4 -1 -.5 0.25 0.5 0.7 1 1.4 2 2.3 3 4 5 6 8 12] m_circle is used with nyquist. + This function is superseeded by the hallchart function. Examples - + + + + $LastChangedDate: 2008-06-19 18:44:44 +0200 (jeu, 19 jun 2008) $ + + + nicholschart + Nichols chart + + + Calling Sequence + nicholschart([ modules [,args [,colors]]]) + + + + Parameters + + + modules + + real vector ( modules (in dB)) + + + + args + + real vector (phases (in degree)) + + + + colorss + + a scalar or a vector, the color indices for isogain and iso phase curves + + + + + + Description + plot the Nichols'chart: iso-module and iso-argument contours of + y/(1+y) in y phase/gain plane + nicholschart may be used in cunjunction with + black. + The default values for modules and + args are respectively : + + [-12 -8 -6 -5 -4 -3 -2 -1.4 -1 -.5 0.25 0.5 0.7 1 1.4 2 2.3 3 4 5 6 8 12] + + [-(1:10) , -(20:10:160)] + + + Examples + + + + + + + + + + + + + + + + + + + See Also + + + black + + + nyquist + + + hallchart + + + + diff --git a/scilab/modules/cacsd/help/images/black1.svg b/scilab/modules/cacsd/help/images/black1.svg new file mode 100644 index 0000000..0060547 --- /dev/null +++ b/scilab/modules/cacsd/help/images/black1.svg @@ -0,0 +1,125 @@ + + +Figure n°0 + +Creator: GL2PS 1.3.2, (C) 1999-2006 Christophe Geuzaine (geuz@geuz.org) +For: Scilab +CreationDate: Wed Apr 14 11:42:01 2010 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +8.8 +3.6 +2.1 +0.99 +0.16 +0.058 +0.037 + + + +-128.4° +3.512 dB +0.08733 Hz + + + + + + + + + + + + + + + + + + + + + + +-80 +-70 +-60 +-50 +-40 +-30 +-20 +-10 +0 +10 +20 + + + + + + + + + + + + + + + + + + + + + + + + + + +-300 +-250 +-200 +-150 +-100 +-50 +-0 +Phase (deg) +Magnitude (dB) + + diff --git a/scilab/modules/cacsd/help/images/black2.svg b/scilab/modules/cacsd/help/images/black2.svg new file mode 100644 index 0000000..560aff3 --- /dev/null +++ b/scilab/modules/cacsd/help/images/black2.svg @@ -0,0 +1,170 @@ + + +Graphic window number 0 + +Creator: GL2PS 1.3.2, (C) 1999-2006 Christophe Geuzaine (geuz@geuz.org) +For: Scilab +CreationDate: Wed Apr 14 17:15:54 2010 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.3dB +Plant +Plant and PID corrector + + + +1e+02 +22 +3.2 +0.26 +1e+02 +22 +3.2 +0.26 +0.01 +-84dB +-64dB +-44dB +-12dB +-6dB +-3dB +-1dB +0dB +0.25dB +0.5dB +1dB +2.3dB +4dB +6dB +12dB + + + + + + + + + + + + + + + + + + +-100 +-80 +-60 +-40 +-20 +0 +20 +40 +60 + + + + + + + + + + + + + + + + + + + + + + + + + + +-300 +-250 +-200 +-150 +-100 +-50 +-0 +Phase (deg) +Magnitude (dB) + + diff --git a/scilab/modules/cacsd/help/images/hallchart.svg b/scilab/modules/cacsd/help/images/hallchart.svg new file mode 100644 index 0000000..82ff779 --- /dev/null +++ b/scilab/modules/cacsd/help/images/hallchart.svg @@ -0,0 +1,132 @@ + + +Graphic window number 0 + +Creator: GL2PS 1.3.2, (C) 1999-2006 Christophe Geuzaine (geuz@geuz.org) +For: Scilab +CreationDate: Thu Apr 15 13:50:44 2010 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-20dB +-10dB +-6dB +-4dB +2dB +4dB +6dB +10dB +20dB +-90° +-60° +-45° +-30° +30° +45° +60° +90° + + + + + + + + + + + + + + + + + + +-2.0 +-1.5 +-1.0 +-0.5 +0.0 +0.5 +1.0 +1.5 +2.0 + + + + + + + + + + + + + + + + + + + + + + + +-4 +-3 +-2 +-1 +0 +1 +2 +3 +Hall chart +Real axis +Imaginary axis + + diff --git a/scilab/modules/cacsd/help/images/nyquist2.svg b/scilab/modules/cacsd/help/images/nyquist2.svg new file mode 100644 index 0000000..9326f8d --- /dev/null +++ b/scilab/modules/cacsd/help/images/nyquist2.svg @@ -0,0 +1,197 @@ + + +Graphic window number 0 + +Creator: GL2PS 1.3.2, (C) 1999-2006 Christophe Geuzaine (geuz@geuz.org) +For: Scilab +CreationDate: Fri Apr 16 10:34:53 2010 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Plant +Plant and PID corrector + + +100 +-1.43 +1.43 +-0.596 +0.596 +-0.5 +0.5 +100 +-1.43 +1.43 +-0.596 +0.596 +-0.5 +0.5 +-20dB +-10dB +2dB +4dB +6dB +10dB +20dB +-90° +-60° +-45° +-30° +-15° +15° +30° +45° +60° +90° + + + + + + + + + + + + + + + + + + + + + + +-5 +-4 +-3 +-2 +-1 +0 +1 +2 +3 +4 +5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2.5 +-2.0 +-1.5 +-1.0 +-0.5 +0.0 +0.5 + + + + + + + +Nyquist plot +Re(h(2iπf)) +Im(h(2iπf)) + + diff --git a/scilab/modules/cacsd/macros/black.sci b/scilab/modules/cacsd/macros/black.sci index a8d1ea3..51e752c 100644 --- a/scilab/modules/cacsd/macros/black.sci +++ b/scilab/modules/cacsd/macros/black.sci @@ -1,10 +1,10 @@ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab -// Copyright (C) INRIA - Serge Steer +// Copyright (C) 1998-2010 - INRIA - Serge Steer // Copyright (C) 2010 - DIGITEO - Yann COLLETTE // This file must be used under the terms of the CeCILL. // This source file is licensed as described in the file COPYING, which // you should have received as part of this distribution. The terms -// are also available at +// are also available at // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt @@ -16,10 +16,10 @@ function black(varargin) // black( sl,fmin,fmax [,pas] [,comments] ) // black(frq,db,phi [,comments]) // black(frq, repf [,comments]) -// +// // sl : SIMO linear system (see syslin). In case of multi-output // system the outputs are plotted with differents symbols. -// +// // fmin : minimal frequency (in Hz). // fmax : maximal frequency (in Hz). // pas : logarithmic discretization step. (see calfrq for the @@ -34,18 +34,16 @@ function black(varargin) //To plot the grid of iso-gain and iso-phase of y/(1+y) use abaque() //%Example -// s=poly(0,'s') -// h=syslin('c',(s**2+2*0.9*10*s+100)/(s**2+2*0.3*10.1*s+102.01)) +// s=poly(0,'s") +// h=syslin("c",(s**2+2*0.9*10*s+100)/(s**2+2*0.3*10.1*s+102.01)) // abaque(); -// black(h,0.01,100,'(s**2+2*0.9*10*s+100)/(s**2+2*0.3*10.1*s+102.01)') +// black(h,0.01,100,"(s**2+2*0.9*10*s+100)/(s**2+2*0.3*10.1*s+102.01)") // // -// h1=h*syslin('c',(s**2+2*0.1*15.1*s+228.01)/(s**2+2*0.9*15*s+225)) -// black([h1;h],0.01,100,['h1';'h']) +// h1=h*syslin("c",(s**2+2*0.1*15.1*s+228.01)/(s**2+2*0.9*15*s+225)) +// black([h1;h],0.01,100,["h1";"h"]) //See also: -// bode nyquist abaque freq repfreq +// bode nyquist abaque freq repfreq //! - - rhs=size(varargin) if type(varargin($))==10 then comments=varargin($),rhs=rhs-1; @@ -54,15 +52,15 @@ function black(varargin) end fname="black";//for error messages fmax=[] - if or(typeof(varargin(1))==['state-space' 'rational']) then + if or(typeof(varargin(1))==["state-space" "rational"]) then //sys,fmin,fmax [,pas] or sys,frq refdim=1 //for error message if rhs==1 then [frq,repf]=repfreq(varargin(1),1d-3,1d3) elseif rhs==2 then //sys,frq if size(varargin(2),2)<2 then - error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"),.. - fname,2,1)) + error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"),.. + fname,2,1)) end [frq,repf]=repfreq(varargin(1:rhs)) elseif or(rhs==(3:4)) then //sys,fmin,fmax [,pas] @@ -72,48 +70,48 @@ function black(varargin) end [phi,d]=phasemag(repf) if rhs>=3 then fmax=varargin(3),end - elseif type(varargin(1))==1 then + elseif type(varargin(1))==1 then //frq,db,phi [,comments] or frq, repf [,comments] refdim=2 select rhs case 2 then //frq,repf frq=varargin(1); if size(frq,2)<2 then - error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"),.. - fname,1,1)) + error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"),.. + fname,1,1)) end if size(frq,2)<>size(varargin(2),2) then - error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),.. - fname,1,2)) + error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),.. + fname,1,2)) end [phi,d]=phasemag(varargin(2)) case 3 then //frq,db,phi [frq,d,phi]=varargin(1:rhs) if size(frq,2)<>size(d,2) then - error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),.. - fname,1,2)) + error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),.. + fname,1,2)) end if size(frq,2)<>size(phi,2) then - error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),.. - fname,1,3)) + error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),.. + fname,1,3)) end - else - error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4)) + else + error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4)) end else error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1)) end; - + if size(frq,1)==1 then ilf=0 else ilf=1 end - + [mn,n]=size(phi); - if and(size(comments,'*')<>[0 mn]) then - error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"),... - fname,refdim,rhs+1)) + if and(size(comments,"*")<>[0 mn]) then + error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"),... + fname,refdim,rhs+1)) end // @@ -129,63 +127,77 @@ function black(varargin) kk=1;p0=[phi(:,kk) d(:,kk)];ks=1;dst=0; dx=max(%eps,xmx-xmn); dy=max(%eps,ymx-ymn); - dx2=max(%eps,dx^2);dy2=max(%eps,dy^2); + dx2=dx^2;dy2=dy^2 while kk0.1 then + if dst>0.2 then if mini(abs(frq(:,ks(prod(size(ks))))-frq(:,kk))./frq(:,kk))>0.2 then - ks=[ks kk] - dst=0 + ks=[ks kk] + dst=0 end end end kf=1 drawlater() ax=gca(); - if size(ax.children,'*')==0 then + if size(ax.children,"*")==0 then ax.data_bounds=[xmn ymn;xmx ymx]; + ax.x_label.text=_("Phase (deg)"); + ax.y_label.text=_("Magnitude (dB)") else ax.data_bounds=[min([xmn ymn],ax.data_bounds(1,:)); - max([xmx ymx],ax.data_bounds(2,:))]; + max([xmx ymx],ax.data_bounds(2,:))]; end - ax.axes_visible='on'; + ax.axes_visible="on"; ax.clip_state="clipgrf"; + r=xstringl(0,0,"m");r=r(3) E=[] - if ks($)1 then + if size(ks,"*") >1 then d_phi=phi(k,ks(1:last)+1)-phi(k,ks(1:last)); d_d=d(k,ks(1:last)+1)-d(k,ks(1:last)); - dd=150*sqrt((d_phi/dx).^2+(d_d/dy).^2); + dd=400*sqrt((d_phi/dx).^2+(d_d/dy).^2); if dd>0 then // we should use xarrows or xsegs here. // However their displayed arrow size depends // on the data bounds and we want to avoid this. xpolys([phi(k,ks(1:last));phi(k,ks(1:last))+d_phi./dd],.. - [d(k,ks(1:last));d(k,ks(1:last))+d_d./dd]); - //xarrows([phi(k,ks(1:last));phi(k,ks(1:last))+d_phi./dd],.. - // [d(k,ks(1:last));d(k,ks(1:last))+d_d./dd],1.5) - e2=gce();e2.children.foreground=k; - e2.children.polyline_style = 4; - e2.children.arrow_size_factor = 1.5; + [d(k,ks(1:last));d(k,ks(1:last))+d_d./dd]); + ea=gce(); + ea.children.foreground=k; + ea.children.polyline_style = 4; + ea.children.arrow_size_factor = 1.5; + + //xarrows([phi(k,ks(1:last));phi(k,ks(1:last))+d_phi./dd],.. + // [d(k,ks(1:last));d(k,ks(1:last))+d_d./dd],60) + //ea=gce();ea.segs_color=k*ones(dd); + //add a frequency label near each arrow + el=[]; + + for l=ks + xstring(phi(k,l)+r,d(k,l),msprintf("%-5.2g",frq(kf,l))) + e=gce() + e.font_foreground=k; + el=[e,el] + end + e2=glue([el ea]) end end - //add frequency values - ne=size(ax.children,'*') - xnumb(phi(k,ks),d(k,ks),frq(kf,ks),0); - nn=size(ax.children,'*')-ne - if nn>1 then e3=glue(ax.children(nn:-1:1)),else e3=ax.children(1);end + + xpoly(phi(k,:),d(k,:));e1=gce() + e1.foreground=k; + datatipInitStruct(e1,"formatfunction","formatBlackTip","freq",frq(kf,:)) + // glue entities relative to a single black curve - E=[E glue([e3 e2 e1])] + E=[E glue([e2 e1])] kf=kf+ilf end - - xtitle(" ",_("Phase (deg)"),_("Magnitude (Db)")); + + // 2.3 db curve mbf=2.3; lmda=exp(log(10)/20*mbf); @@ -196,8 +208,20 @@ function black(varargin) xpoly([180*(imag(lgmt)/%pi-ones(lgmt))],[(20/log(10)*real(lgmt))]) e=gce();e.foreground=2;e.line_style=3; if comments<>[] then - c=[];for k=1:mn,c=[c E(k).children(1)];end - legend([c e]',[comments(:);'2.3Db']) + c=[];for k=1:mn,c=[E(k).children(1),c];end + legend([c e]',["2.3"+_("dB");comments(:)]) end drawnow() endfunction +function str=formatBlackTip(curve,pt,index) +//This function is called by the datatip mechanism to format the tip +//string for black curves. + ud=datatipGetStruct(curve); + if index<>[] then + f=ud.freq(index) + else //interpolated + [d,ptp,i,c]=orthProj(curve.data,pt) + f=ud.freq(i)+(ud.freq(i+1)-ud.freq(i))*c + end + str=msprintf("%.4g"+_("°")+"\n%.4g"+_("dB")+"\n%.4g"+_("Hz"), pt,f); +endfunction diff --git a/scilab/modules/cacsd/macros/hallchart.sci b/scilab/modules/cacsd/macros/hallchart.sci new file mode 100644 index 0000000..3c0e419 --- /dev/null +++ b/scilab/modules/cacsd/macros/hallchart.sci @@ -0,0 +1,135 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2010 - INRIA - Serge STEER +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + +function hallchart(modules,args,colors) + defaultmodules=[-20 -10 -6 -4 -2 2 4 6 10 20];//in dB + defaultargs=[-90 -60 -45 -30 -15 15 30 45 60 90]; //in degree + defaultbounds=[-3.5 -2;3 2]; + if exists("modules","local")==0 then + modules=defaultmodules + else + if type(modules)|~isreal(modules)<>1 then + error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"hallchart","modules"); + end + modules=matrix(modules,1,-1) + end + if exists("args","local")==0 then + args=defaultargs + else + if type(args)<>1|~isreal(args) then + error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"hallchart","args"); + end + args=matrix(args,1,-1) + end + + if exists("colors","local")==0 then + colors=[4 12]; + else + if type(colors)<>1|~isreal(colors) then + error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"hallchart","colors"); + end + if size(colors,"*")==1 then + colors=colors*ones(1,2) + end + end + + drawlater() + ax=gca(); + nc=size(ax.children,"*") + if nc==0 then + ax.data_bounds=defaultbounds; + ax.axes_visible="on"; + ax.x_label.text=_("Real axis"); + ax.y_label.text=_("Imaginary axis"); + ax.title.text=_("Hall chart") + ax.box="on"; + end + + //iso modules circles. Circles whose center are (-M^2/(M^2-1),0) and + //radius M/(M^2-1) with M=|H(jw)| and H=G/(1+G) + + M=exp(log(10)*modules/20) + radius=M./(M.*M-ones(M)) + xc=-M.*radius + yc=0 + radius=abs(radius) + //arcs replaced by polylines to be able to use datatips + // xarcs([xc-radius;yc+radius;2*radius;2*radius;0*M;360*64*ones(M)]) + // A=gce() + // E=unglue(A); + w=linspace(0,2*%pi,200) + c=cos(w);s=sin(w) + chart_handles=[] + for i=1:size(M,"*") + xpoly(xc(i)+radius(i)*c,yc+radius(i)*s) + ec=gce(); + ec.foreground=colors(1); + ec.line_style=7; + ec.clip_state="clipgrf"; + datatipInitStruct(ec,"formatfunction","formatHallModuleTip","module",modules(i)) + if 2*int(i/2)==i then + xs=xc(i)+radius(i)*cos(%pi/6) + ys=yc+radius(i)*sin(%pi/6) + else + xs=xc(i)+radius(i)*cos(-%pi/6) + ys=yc+radius(i)*sin(-%pi/6) + + end + + xstring(xs,ys,string(modules(i))+_("dB")); + el=gce(); + + el.font_foreground=colors(1); + el.clip_state="clipgrf"; + chart_handles=[glue([el ec]) chart_handles]; + end + + //iso phase circles. Circles whose center are (-1/2, 1/(2*N)) and + //radius sqrt(1+N^2)/(2*N) with N=tan(arg(H(-jw))) + + N=tan(args*%pi/180); + radius=sqrt(1+N^2)./(2*N); + xc=-1/2; + yc=1 ./(2*N); + + // xarcs([xc-radius;yc+radius;2*radius;2*radius;0*N;360*64*ones(N)]) + // E=unglue(gce()); + for i=1:size(N,"*") + xpoly(xc+radius(i)*c,yc(i)+radius(i)*s);ec=gce(); + ec.foreground=colors(2); + ec.line_style=7; + ec.clip_state="clipgrf"; + datatipInitStruct(ec,"formatfunction","formatHallPhaseTip","phase",args(i)) + xstring(xc,yc(i)+radius(i),msprintf("%g"+_("°"),args(i))); + el=gce(); + el.font_foreground=colors(2); + el.clip_state="clipgrf"; + chart_handles=[glue([el ec]) chart_handles]; + end + chart_handles=glue(chart_handles) + //reorder axes children to make chart drawn before the previously + // drawn curves if any + for k=1:nc + swap_handles(ax.children(k),ax.children(k+1)) + end + + drawnow() +endfunction +function str=formatHallModuleTip(curve,pt,index) +//this function is called by the datatip mechanism to format the tip +//string for the Hall charts iso module curves + ud=datatipGetStruct(curve); + str=msprintf("%.2g"+_("dB"), ud.module); +endfunction +function str=formatHallPhaseTip(curve,pt,index) +//This function is called by the datatip mechanism to format the tip +//string for the Hall charts iso phase curves + ud=datatipGetStruct(curve); + str=msprintf("%.2g"+_("°"), ud.phase); +endfunction + diff --git a/scilab/modules/cacsd/macros/m_circle.sci b/scilab/modules/cacsd/macros/m_circle.sci index 64d86a3..c53dbf2 100644 --- a/scilab/modules/cacsd/macros/m_circle.sci +++ b/scilab/modules/cacsd/macros/m_circle.sci @@ -3,52 +3,52 @@ // This file must be used under the terms of the CeCILL. // This source file is licensed as described in the file COPYING, which // you should have received as part of this distribution. The terms -// are also available at +// are also available at // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt function []=m_circle(gain) -// Copyright INRIA -[lhr,rhs]=argn(0) -// -d36=11; -if rhs<1 then - gain=[-12 -8 -6 -5 -4 -3 -2 -1.4 -1 -.5 0.25 0.5 0.7 1 1.4 .. - 2 2.3 3 4 5 6 8 12] -else - gain=matrix(gain,1,prod(size(gain))) -end -// -titre='isogain contours for y/(1+y)' -l10=log(10); -// -lambda=exp(l10*gain/20) -rayon=lambda./(lambda.*lambda-ones(lambda)) -centre=-lambda.*rayon -rayon=abs(rayon) -rect=[mini(centre-rayon),mini(-rayon),maxi(centre+rayon),maxi(rayon)]; -// -drawlater() -ax=gca(); -llrect=xstringl(0,0,'1') -hx=llrect(3); -// -for i=1:prod(size(gain)) - sgn=1;if 2*int(i/2)==i then sgn=-1,end - g=string(gain(i)),ng=length(g) - if gain(i)<0 then - w=0:0.03:%pi; - xx=centre(i)+rayon(i)*sin(%pi/3)+hx - xy=sgn*cos(%pi/3)*rayon(i) - else - xx=centre(i)-sin(%pi/3)*rayon(i)-hx*ng - xy=sgn*cos(-%pi/3)*rayon(i) - w=-%pi:0.03:0; +//this function is obsolete, superseeded by hallchart. + [lhr,rhs]=argn(0) + // + d36=11; + if rhs<1 then + gain=[-12 -8 -6 -5 -4 -3 -2 -1.4 -1 -.5 0.25 0.5 0.7 1 1.4 .. + 2 2.3 3 4 5 6 8 12] + else + gain=matrix(gain,1,prod(size(gain))) + end + // + titre='isogain contours for y/(1+y)' + l10=log(10); + // + lambda=exp(l10*gain/20) + rayon=lambda./(lambda.*lambda-ones(lambda)) + centre=-lambda.*rayon + rayon=abs(rayon) + rect=[mini(centre-rayon),mini(-rayon),maxi(centre+rayon),maxi(rayon)]; + // + drawlater() + ax=gca(); + llrect=xstringl(0,0,'1') + hx=llrect(3); + // + for i=1:prod(size(gain)) + sgn=1;if 2*int(i/2)==i then sgn=-1,end + g=string(gain(i)),ng=length(g) + if gain(i)<0 then + w=0:0.03:%pi; + xx=centre(i)+rayon(i)*sin(%pi/3)+hx + xy=sgn*cos(%pi/3)*rayon(i) + else + xx=centre(i)-sin(%pi/3)*rayon(i)-hx*ng + xy=sgn*cos(-%pi/3)*rayon(i) + w=-%pi:0.03:0; + end; + n=prod(size(w)) + rf=centre(i)*ones(w)+rayon(i)*exp(%i*w); + xpoly([real(rf) real(rf($:-1:1))],[imag(rf) -imag(rf($:-1:1))]) + e=gce();e.foreground=3;e.clip_state='clipgrf' end; - n=prod(size(w)) - rf=centre(i)*ones(w)+rayon(i)*exp(%i*w); - xpoly([real(rf) real(rf($:-1:1))],[imag(rf) -imag(rf($:-1:1))]) - e=gce();e.foreground=3;e.clip_state='clipgrf' -// xstring(xx,xy,g) -drawnow(); -end; + drawnow(); + endfunction diff --git a/scilab/modules/cacsd/macros/nicholschart.sci b/scilab/modules/cacsd/macros/nicholschart.sci new file mode 100644 index 0000000..4ab1a89 --- /dev/null +++ b/scilab/modules/cacsd/macros/nicholschart.sci @@ -0,0 +1,190 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2010 - INRIA - Serge STEER +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + +function nicholschart(modules,args,colors) + + l10=log(10); + ratio=%pi/180; + + drawlater() + ax=gca(); + nc=size(ax.children,"*") + if nc==0 then + ax.data_bounds=[-360,-40;0,40]; + ax.axes_visible="on"; + ax.box="on"; + ax.tight_limits="on" + ax.title.text=_("Amplitude and phase contours of y/(1+y)") + ax.x_label.text=_("phase(y) (degree)"); + ax.y_label.text=_("magnitude(y) (dB)"); + else + ax.data_bounds(2,2)=max( ax.data_bounds(2,2),40) + end + ax.clip_state="clipgrf" + + phi_min=ax.data_bounds(1,1) + phi_max=ax.data_bounds(2,1) + mod_min=ax.data_bounds(1,2) + mod_max=ax.data_bounds(2,2) + + defaultArgs = [1 5 10 20 30 50 90 120 150 180] + defaultModules=[mod_min:20:-40 -12 -6 -3 -1 0 0.25 0.5 1 2.3 4 6 12]; + + + if exists("modules","local")==0 then + modules=defaultModules + else + if type(modules)<>1|~isreal(modules) then + error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"nicholschart","modules"); + end + modules=matrix(modules,1,-1) + end + if exists("args","local")==0 then + args=defaultArgs + else + if type(args)<>1|~isreal(args) then + error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"nicholschart","args"); + end + args=matrix(args,1,-1) + end + // + if exists("colors","local")==0 then + colors=[4 12]; + else + if type(colors)<>1|~isreal(colors) then + error(msprintf("%s: Wrong type for imput argument ""%s"": real floating point array expected\n"),"hallchart","colors"); + end + if size(colors,"*")==1 then + colors=colors*ones(1,2) + end + end + // convert args to radian + args = -args * ratio; + + //initialize handles array for chart entities + chart_handles=[] + + // Replication bounds + k1=floor(phi_min/180) + k2=ceil(phi_max/180) + + //isogain curves: y as fixed gain and varying phase + //------------------------------------------------- + if modules<>[] then + w=[linspace(-%pi,-0.1,100) linspace(-0.1,0,80) ] + nw=size(w,"*") + for i = 1:prod(size(modules)), + att=modules(i); + y=10^(att/20)*exp(%i*w); + y(y==1)=[];//remove singular point if any + rf=y./(1-y); + [module, phi]=dbphi(rf) + //use symetry and period to extend the curve on [k1*180 k2*180] + p=[];m=[]; + S=[];cut=[] + for k=k1:k2-1 + if pmodulo(k,2)==0 then + p=[p cut k*180-phi($:-1:1)] + m=[m cut module($:-1:1)] + if att>0 then + str=msprintf("%.2gdB",att) + r=xstringl(0,0,str) + xstring(k*180-phi($)-r(3)/2,module($),str,0,0), + e=gce(); + e.font_foreground=colors(1) + S=[e S] + elseif att==0 then + l=find(module>mod_max-r(4),1) + if l<>[] then + xstring(k*180-phi(l-1),module(l-1),"0dB",0,0), + e=gce(); + e.font_foreground=colors(1) + S=[e S] + end + end + else + p=[p cut ((k+1)*180)+phi] + m=[m cut module] + if att<0 then + str=msprintf("%.2gdB",att) + r=xstringl(0,0,str) + xstring(p($)-r(3),m($),str,0,0), + e=gce(); + e.font_foreground=colors(1) + S=[e S] + end + end + cut=%nan + end + xpoly(p,m) + e=gce(); + e.foreground=colors(1), + e.line_style=7; + datatipInitStruct(e,"formatfunction","formatNicholsGainTip","gain",att) + + if size(S,"*")>1 then S=glue(S),end + chart_handles=[glue([S,e]),chart_handles]; + end; + end + + //isophase curves: y as fixed phase and varying gain + //------------------------------------------------- + + if args<>[] then + + eps=10*%eps; + for teta=args, + if teta < -%pi/2 then + last=teta-eps, + else + last=teta+eps, + end; + w=[-170*ratio:0.03:last last] + n=prod(size(w)); + module=real(20*log((sin(w)*cos(teta)/sin(teta)-cos(w)))/l10) + w=w/ratio + //use symetry and period to extend the curve on [k1*180 k2*180] + p=[];m=[]; + for k=k1:k2-1 + if pmodulo(k,2)==0 then + p=[p %nan k*180-w($:-1:1)] + m=[m %nan module($:-1:1)] + else + p=[p %nan ((k+1)*180)+w] + m=[m %nan module] + end + end + xpoly(p,m) + e=gce(); + e.foreground=colors(2); + e.line_style=7; + datatipInitStruct(e,"formatfunction", ... + "formatNicholsPhaseTip","phase",teta*180/%pi) + chart_handles=[e chart_handles] + end; + end + chart_handles=glue(chart_handles) + //reorder axes children to make chart drawn before the black curves if any + for k=1:nc + swap_handles(ax.children(k),ax.children(k+1)) + end + + drawnow() ; +endfunction +function str=formatNicholsGainTip(curve,pt,index) +//This function is called by the datatip mechanism to format the tip +//string for the Nichols chart iso gain curves. + ud=datatipGetStruct(curve); + str=msprintf("%.2g"+_("dB"),ud.gain); +endfunction +function str=formatNicholsPhaseTip(curve,pt,index) +//This function is called by the datatip mechanism to format the tip +//string for the Nichols chart iso phase curves. + ud=datatipGetStruct(curve); + str=msprintf("%.2g"+_("°"),ud.phase) +endfunction -- 1.7.9.5