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

  1. function [] = ngrid(s)
  2. %NGRID    NGRID generates grid lines for a Nichols chart. The chart relates
  3. %    the complex number H/(1+H) to H, where H is any complex number.
  4. %
  5. %    NGRID generates a grid over the region -40 db to 40 db in 
  6. %    magnitude and -360 degrees to 0 degrees in phase with lines of 
  7. %    constant mag(H/(1+H)) and angle(H/(1+H)) drawn in.  NGRID plots 
  8. %    the Nichols chart grid over an existing Nichols plot such as one
  9. %    generated with NICHOLS or DNICHOLS.  
  10. %
  11. %    NGRID('new') clears the graphics screen before plotting the grid
  12. %    and sets HOLD ON so that the Nichols response can be plotted over
  13. %    the grid using
  14. %        ngrid('new')
  15. %        nichols(num,den); or nichols(a,b,c,d,iu);
  16. %
  17. %    See also: NICHOLS and DNICHOLS.
  18.  
  19. %    J.N. Little 2-23-88
  20. %    Revised: CMT 7-12-90, ACWG 6-21-92, Wes W 8-17-92.
  21. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  22.  
  23. status = ishold;
  24. limit=axis;
  25. if nargin == 1
  26.   hold off
  27. else
  28.   axis(axis)
  29.   hold on
  30.   if limit(3) >= 0,
  31.     disp('This is not a Nichols Chart. Use ngrid(''new'') for new Nichols Chart grid');
  32.     hold off
  33.     return
  34.   end;
  35. end
  36. % Define desired gain and phase curves
  37. mm = [6 3 1 .5 .25 0 -1 -3 -6 -12 -20 -40 ];
  38. mx = [6 3 2 1 .75 .5 .4 .3 .25 .2 .15 .1 .05 0 -.05 -.1 -.15 -.2 -.25 -.3 -.4 -.5 -.75 -1 -2 -3 -4 -5 -6 -9 -12 -16 -20 -30 -40 ];
  39. mm = 10 .^(mm/20);
  40. mx = 10 .^(mx/20);
  41.  
  42. pp = [-359 -355 -350 -340 -330 -300 -270 -240 -210 -180 -150 -120 -90 -60 -30 -20 -10 -5 -1];
  43. px = [-359 -358 -357 -356 -355 -352.5 -350 -345 -340 -335 -330 -315 -300 -285 -270 -255 -240 -225 -210 -195 -180 -165 -150 -135 -120 -105 -90 -75 -60 -45 -30 -25 -20 -15 -10 -5 -4 -3 -2 -1];
  44.  
  45. % --- Perform mapping and plot Nichols grid lines ---
  46.  
  47. i = sqrt(-1);
  48.  
  49. % Plot phase lines
  50. [p,m] = meshgrid(pp,mx);
  51. z = m .*exp(i*p/180*pi);
  52. g = z./(1-z);
  53. gain = 20*log10(abs(g));
  54. phase = rem(angle(g)/pi*180+360,360)-360;
  55. plot(phase,gain,'w:');
  56. hold on
  57.  
  58. % Plot Magnitude lines
  59. [p,m] = meshgrid(px,mm);
  60. z = m .*exp(i*p/180*pi);
  61. g = z./(1-z);
  62. gain = 20*log10(abs(g));
  63. phase = rem(angle(g)/pi*180+360,360)-360;
  64. plot(phase',gain','w:')
  65.  
  66. % Now put magnitude labels (in db) on the curve.
  67. [mp,np]=size(p);
  68. mm = 20*log10(mm);
  69. nm=length(mm)+1;
  70. for i=1:nm-1
  71. %  text(phase(i,np),gain(i,np),sprintf('%.3g',mm(nm-i)))
  72.   text(phase(i,np),gain(i,np),sprintf('%.3g db',mm(i)))
  73. end
  74. xlabel('Open-Loop Phase (deg)')
  75. ylabel('Open-Loop Gain (db)')
  76.  
  77. if nargin == 1 %    ngrid('new')
  78.     set(gca,'xlim',[-360, 0]);
  79.     set(gca,'ylim',[-40, 40]);
  80. end
  81.  
  82. if (nargin==0) & (~status), hold off, end        % Return hold to previous status
  83.