home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS1.DI$ / VPLOT.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  9.3 KB  |  333 lines

  1. % function vplot([axis],vmat1,vmat2,vmat3, ...)
  2. % function vplot([axis],vmat1,'linetype1',vmat2,'linetype2',...)
  3. %
  4. %   Plot one or more varying matrices.  The syntax is
  5. %   the same as the MATLAB plot command except that all data
  6. %   is contained in VMATi, and the axes are specified by AXIS.
  7. %
  8. %   The (optional) axis argument must be one of:
  9. %
  10. %      'iv,d'       matin .vs. independent variable (default option)
  11. %      'iv,m'       magnitude .vs. independent variable
  12. %      'iv,lm'      log(magnitude) .vs. independent variable
  13. %      'iv,p'       phase .vs. independent variable
  14. %      'liv,d'      matin .vs. log(independent variable)
  15. %      'liv,m'      magnitude .vs. log(independent variable)
  16. %      'liv,lm'     log(magnitude) .vs. log(independent variable)
  17. %      'liv,p'      phase .vs. log(independent variable)
  18. %      'ri'         real .vs. imaginary  (parametrized by indep variable)
  19. %      'nyq'        real .vs. imaginary  (parametrized by indep variable)
  20. %      'nic'        Nichols chart
  21. %      'bode'       Bode magnitude and phase plots
  22. %
  23. %
  24. %    See also: PLOT
  25.  
  26. %====================================================================
  27. %
  28. %    MAGNITUDE/PHASE/FREQUENCY UNIT DEFINITION
  29. %
  30. %    Choose only one of these commands to set up the
  31. %    phase units.  The others must be commented out.
  32.  
  33. function vplot(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17, ...
  34.     a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33)
  35.  
  36. phasefunc = '180/pi*angle(';        % degrees (-180 to 180)
  37. %phasefunc = 'angle(';            % radians (-pi to pi)
  38. %phasefunc = '180/pi*negangle(';    % degrees (-360 to 0)
  39. %phasefunc = 'negangle(';        % radians (-2pi to 0)
  40.  
  41. %    Choose the appropriate set of commands to setup the
  42. %    magnitude scaling for log magnitude commands. 
  43.  
  44. %magfunc = '20*log10(';        % Scale in dB
  45. %mplt1 = 'semilogx(';        % You must select all 3
  46. %mplt2 = 'plot(';        % commands here.
  47.  
  48. magfunc = 'abs(';        % Scale in log magnitude
  49. mplt1 = 'loglog(';        % Again all 3 commands are
  50. mplt2 = 'semilogy(';        % required.
  51.  
  52. %    Note that 20*log10(x) gives a complex result when x is
  53. %    complex.  The real part is equal to 20*log10(abs(x)) and
  54. %    the MATLAB plot function plots only the real part.
  55. %
  56. %    The following section customizes the 'liv,..' plots.
  57. %    In almost all cases a logarithmic independent variable
  58. %    refers to frequency -- this section chooses between displaying
  59. %    in radians/second and Hertz.  If you intend to use log independent
  60. %    variable plots for something other than frequency then you should
  61. %    select the default scaling of 1.  Note that the output
  62. %    from frsp is in radians/second.  Choosing this throughout is
  63. %    very strongly encouraged.
  64.  
  65. ivscale = 1;            % frequency in radians/sec
  66. %ivscale = 1/(2*pi);        % frequency in Hertz
  67. %ivscale = 1/pi;        % discrete normalized frequency
  68.  
  69. %    The following section customizes the Bode plot labels.
  70. %    Make sure that they agree with your choices for the
  71. %    log magnitude, phase, and frequency units.
  72.  
  73. %toplabel = 'Magnitude (dB)';
  74. toplabel = 'Log Magnitude';
  75.  
  76. bottomlabel = 'Phase (degrees)';
  77. %bottomlabel = 'Phase (radians)';
  78.  
  79. ivlabel = 'Frequency (radians/sec)';
  80. %ivlabel = 'Frequency (Hertz)';
  81. %ivlabel = 'Normalized Frequency';
  82.  
  83. %===================================================================
  84.  
  85. n = nargin;
  86. if n == 0,
  87.     disp('usage: vplot([axis],vmat1,vmat2,...)')
  88.     disp('       vplot([axis],vmat1,linetype1,...)')
  89.     return
  90.     end
  91.  
  92. if n > 33,
  93.     disp('    Sorry, vplot is limited to 33 arguments')
  94.     return
  95.     end
  96.  
  97. %    Attempt to see if the first argument is the axis string.
  98. %    If it isn't use the default axis setting.  argstart denotes
  99. %    the start of the data arguments.
  100.  
  101. if isstr(a1),
  102.     argstart = 2;
  103.     axis = a1;
  104. else
  105.     axis = 'iv,d';
  106.     argstart = 1;
  107.     end
  108.  
  109. %    Determine the required plot type and what functions have
  110. %    to be applied to the data.  Three types of plot are
  111. %    distinguished by the variable plttype:
  112. %
  113. %        1:    function(data) vs. independent variable
  114. %        2:    function(data) vs. function(data)
  115. %        3:    customized double plot (each of type 1)
  116. %
  117.  
  118. if strcmp(axis,'iv,d'),
  119.     func = '(';
  120.     ivscale = 1;
  121.     pltfunc = 'plot(';
  122.     plttype = 1;
  123. elseif strcmp(axis,'iv,lm'),
  124.     func = magfunc;
  125.     ivscale = 1;
  126.     pltfunc = mplt2;
  127.     plttype = 1;
  128. elseif strcmp(axis,'iv,m'),
  129.     func = 'abs(';
  130.     ivscale = 1;
  131.     pltfunc = 'plot(';
  132.     plttype = 1;
  133. elseif strcmp(axis,'iv,p'),
  134.     func = phasefunc;
  135.     ivscale = 1;
  136.     pltfunc = 'plot(';
  137.     plttype = 1;
  138. elseif strcmp(axis,'liv,d'),
  139.     func = '(';
  140.     pltfunc = 'semilogx(';
  141.     plttype = 1;
  142. elseif strcmp(axis,'liv,lm'),
  143.     func = magfunc;
  144.     pltfunc = mplt1;
  145.     plttype = 1;
  146. elseif strcmp(axis,'liv,m'),
  147.     func = 'abs(';
  148.     pltfunc = 'semilogx(';
  149.     plttype = 1;
  150. elseif strcmp(axis,'liv,p'),
  151.     func = phasefunc;
  152.     pltfunc = 'semilogx(';
  153.     plttype = 1;
  154. elseif strcmp(axis,'ri');
  155.     func1 = 'imag(';
  156.     func2 = 'real(';
  157.     pltfunc = 'plot(';
  158.     plttype = 2;
  159. elseif strcmp(axis,'nyq');
  160.     func1 = 'imag(';
  161.     func2 = 'real(';
  162.     pltfunc = 'plot(';
  163.     plttype = 2;
  164. elseif strcmp(axis,'nic');
  165.     func1 = '20*log10(';
  166.     func2 = '360/(2*pi)*negangle(';
  167.     pltfunc = 'plot(';
  168.     plttype = 2;
  169. elseif strcmp(axis,'bode'),
  170.     tfunc = magfunc;
  171.     bfunc = phasefunc;
  172.     tpltfunc = mplt1;
  173.     bpltfunc = 'semilogx(';
  174.     plttype = 3;
  175. else
  176.     errstr = ['    unrecognized axis specification: ',axis];
  177.     error(errstr)
  178.     end
  179.  
  180. %    For the particular plttype parse the argument list and
  181. %    create the string to pass as an argument list to a standard
  182. %    MATLAB plot routine.  The functions determined above (eg,
  183. %    abs, angle, etc) are applied to the appropriate data.
  184. %    If a string is found it is assumed to specify a line type
  185. %    and is included directly in the argument list.  Constant
  186. %    matrices are assumed to be constant over independent variables.
  187. %    The minimum and maximum independent variables are tracked so
  188. %    that constants can be plotted out over the full range of the
  189. %    graph.
  190.  
  191. if plttype == 1,
  192.     ivc = [];
  193.     for i = argstart:n,
  194.     eval(['strtest=isstr(a',num2str(i),');'])
  195.     if strtest,
  196.         str = [str,',a',num2str(i)];
  197.     else
  198.         eval(['a = a',num2str(i),';']);
  199.         [nt,nr,nc,npts] = minfo(a);
  200.         if nt == 'vary',
  201.         [dat,ptr,iv] = vunpck(a);
  202.         dat = dat.';
  203.         dat = reshape(dat,nr*nc,npts).';
  204.         if npts == 1,
  205.             dat = [dat;dat];
  206.             iv = [iv;iv];
  207.             end
  208.         eval(['dat',num2str(i),' = ',func,'dat);']);
  209.         eval(['iv',num2str(i),' = ivscale*iv;']);
  210.         if isempty(ivc),
  211.             ivc = [max(ivscale*iv); min(ivscale*iv)];
  212.         else
  213.             ivc = [max(ivc(1),max(ivscale*iv));...
  214.                 min(ivc(2),min(ivscale*iv))];
  215.             end
  216.         str = [str,',iv',num2str(i),',dat',num2str(i)];
  217.         elseif nt == 'syst',
  218.         error('cannot plot system matrix')
  219.         break
  220.         else 
  221.         dat = a.';
  222.         dat = reshape(dat,nr*nc,1).';
  223.         dat = [dat; dat];
  224.         eval(['dat',num2str(i),' = ',func,'dat);']);
  225.         str = [str,',ivc,dat',num2str(i)];
  226.         end
  227.         end
  228.     end
  229.  
  230.     str = str(2:length(str));
  231.     str = [pltfunc, str, ')'];
  232. %    disp(str)
  233.     eval(str)
  234. elseif plttype == 2,
  235.     for i = argstart:n,
  236.     eval(['strtest=isstr(a',num2str(i),');'])
  237.     if strtest,
  238.         str = [str,',a',num2str(i)];
  239.     else
  240.         eval(['a = a',num2str(i),';']);
  241.         [nt,nr,nc,npts] = minfo(a);
  242.         if nt == 'vary' | nt == 'cons',
  243.         [dat,ptr,iv] = vunpck(a);
  244.         dat = dat.';
  245.         if npts == 0,
  246.             npts = 1;
  247.             end
  248.         dat = reshape(dat,nr*nc,npts).';
  249.         if npts == 1,
  250.             dat = [dat;dat];
  251.             iv = [iv;iv];
  252.             end
  253.         eval(['dat',num2str(i),' = ',func1,'dat);']);
  254.         eval(['iv',num2str(i),' = ',func2,'dat);']);
  255.         str = [str,',iv',num2str(i),',dat',num2str(i)];
  256.         else nt == 'syst',
  257.         error('cannot plot system matrix')
  258.         break
  259.         end
  260.         end
  261.     end
  262.  
  263.     str = str(2:length(str));
  264.     str = [pltfunc, str, ')'];
  265. %    disp(str)
  266.     eval(str)
  267. else,
  268.     ivc = [];
  269.     for i = argstart:n,
  270.     eval(['strtest=isstr(a',num2str(i),');'])
  271.     if strtest,
  272.         str1 = [str1,',a',num2str(i)];
  273.         str2 = [str2,',a',num2str(i)];
  274.     else
  275.         eval(['a = a',num2str(i),';']);
  276.         [nt,nr,nc,npts] = minfo(a);
  277.         if nt == 'vary',
  278.         [dat,ptr,iv] = vunpck(a);
  279.         dat = dat.';
  280.         dat = reshape(dat,nr*nc,npts).';
  281.         if npts == 1,
  282.             dat = [dat;dat];
  283.             iv = [iv;iv];
  284.             end
  285.         eval(['tdat',num2str(i),' = ',tfunc,'dat);']);
  286.         eval(['bdat',num2str(i),' = ',bfunc,'dat);']);
  287.         eval(['iv',num2str(i),' = ivscale*iv;']); 
  288.         if isempty(ivc),
  289.             ivc = [max(ivscale*iv); min(ivscale*iv)];
  290.         else
  291.             ivc = [max(ivc(1),max(ivscale*iv));...
  292.                 min(ivc(2),min(ivscale*iv))];
  293.             end
  294.         str1 = [str1,',iv',num2str(i),',tdat',num2str(i)];
  295.         str2 = [str2,',iv',num2str(i),',bdat',num2str(i)];
  296.         elseif nt == 'syst',
  297.         error('cannot plot system matrix')
  298.         break
  299.         else 
  300.         dat = a.';
  301.         [nr,nc] = size(a);
  302.         dat = reshape(dat,nr*nc,1).';
  303.         dat = [dat; dat];
  304.         eval(['tdat',num2str(i),' = ',tfunc,'dat);']);
  305.         eval(['bdat',num2str(i),' = ',bfunc,'dat);']);
  306.         str1 = [str1,',ivc,tdat',num2str(i)];
  307.         str2 = [str2,',ivc,bdat',num2str(i)];
  308.         end
  309.         end
  310.     end
  311.  
  312.     str1 = str1(2:length(str1));
  313.     str1 = [tpltfunc, str1, ')'];
  314.     str2 = str2(2:length(str2));
  315.     str2 = [bpltfunc, str2, ')'];
  316. %    disp(str1)
  317. %    disp(str2)
  318.     subplot(211)
  319.     eval(str1)
  320.     ylabel(toplabel)
  321.     xlabel(ivlabel)
  322.     subplot(212)
  323.     eval(str2)
  324.     ylabel(bottomlabel)
  325.     xlabel(ivlabel)
  326.     subplot(111)
  327.     end
  328.  
  329. %------------------------------------------------------------------------
  330.  
  331. %
  332. % Copyright MUSYN INC 1991,  All Rights Reserved
  333.