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

  1. % function [sysout,pts] = drawmag(in,init_pts)
  2. %
  3. %  Interactive mouse-based loglog sketching and fitting tool
  4. %
  5. %   inputs:  in = either VARYING data which will be plotted each time
  6. %          or  CONSTANT specifying window on data [xmin xmax ymin ymax]
  7. %            init_pts = VARYING file with initial points (optional)
  8. %
  9. %   outputs: sysout = fitted SYSTEM
  10. %            pts    = VARYING file with final points
  11. %
  12. %  With the mouse in plot window the following keys are recognized
  13. %    -click mouse to add points ( may be added outside current window)
  14. %    -type 'a' to add points ( same as clicking mouse button)
  15. %    -type 'r' to remove nearest frequency point
  16. %    -enter integer (0-9) order for stable, minphase fit of points 
  17. %    -type 'w' to window and click again to specify second window coordinate
  18. %    -type 'p' to replot 
  19. %    -type 'g' to toggle grid 
  20. %
  21. %  See Also: FITMAG, GINPUT, MAGFIT, PLOT, and VPLOT.
  22.  
  23. function [sysout,pts] = drawmag(in,init_pts)
  24. %
  25.  
  26. %%%%%%%%%%%%%%%% initial setup and argument parsing %%%%%%%%%%%%
  27. usage = 'usage: [sysout,pts] = drawmag(in,init_pts)';
  28. xlab = '0-9=fit p=plot  q=quit r=remove  w=window g=grid';
  29. ylab = 'click to add';
  30.  
  31. if nargin == 0,   disp(usage);   return
  32. end %if
  33.  
  34. [dtype,drows,dcols,dnum] = minfo(in);
  35.  
  36. if dtype=='cons'
  37.     if (drows == 1) & (dcols == 4)
  38.        in = vpck(in(3:4)',in(1:2)');    insym = '.y';
  39.      else disp([usage ' in = [xmin xmax ymin ymax] ']);return;
  40.     end % if (drows
  41.  elseif dtype == 'vary',    insym = ':';
  42.  else   disp([usage ':  in must be constant or varying']);   return;
  43. end % if dtype=='cons'
  44.  
  45. if nargin ==1,    mf=[]; omega=[];clg;hold off;vplot('liv,lm',in,insym);grid;
  46.  else    [dtype,drows,dcols,dnum] = minfo(init_pts);
  47.     if (dtype ~='vary')|(drows~=1)|(dcols~=1) 
  48.       disp([usage ': init_pts must be 1x1 varying']    );  return;
  49.     end% if 
  50.     [mf,rowpoint,omega] = vunpck(init_pts);
  51.     clg; hold off; vplot('liv,lm',in,insym,init_pts,'+g');  grid;
  52. end % if nargin ==1
  53.  
  54. title('initial data');xlabel(xlab);ylabel(ylab);
  55. grid_on = 1;
  56. sysout_g = xtract(in,0); sysout_g_old = sysout_g; old_ord = ' ' ; new_ord = ' ';
  57. hold on;  [x,y,button]=ginput(1);
  58.  
  59. %%%%%%%%%%%%%%%%%%%%%%%% main loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. while button ~= abs('q')  
  61.  
  62.     if any(button == [1 2 3 abs('a')]);            % add mode
  63.         loglog(x,y,'+r'); mf = [mf ; y]; omega = [ omega ; x];
  64.     elseif button ==  abs('r');        % remove mode
  65.         [dummy,indx] = min(abs(omega - x));
  66.         loglog(omega(indx), mf(indx),'+i');
  67.         omega = [omega(1:(indx-1)); omega((indx+1):length(omega))];
  68.         mf = [mf(1:(indx-1)); mf((indx+1):length(mf))];
  69.     elseif (button >= 48)&(button <= 57)&(~isempty(omega));    % fit mode
  70.         order = button - 48; 
  71.         new_ord = ['fit order: new(solid) = ' num2str(order) '  '];
  72.         [omega,indx] = sort(omega); mf = mf(indx);
  73.         pts = vpck(mf,omega);
  74.         sysout = magfit(pts,[.26 .1 order order ]);
  75.         log_min = floor(log10(min(omega)));
  76.         log_max = ceil(log10(max(omega)));
  77.         omega_ex = sort([logspace(log_min,log_max,100) omega']);
  78.         sysout_g_old = sysout_g;
  79.         sysout_g = frsp(sysout,omega_ex);
  80.         hold off;clg; axis([0 0.001 0 0.001]); axis;
  81.         vplot('liv,lm',in,insym,sysout_g,'-r',sysout_g_old,'--b',pts,'+g');
  82.         title([ new_ord old_ord]);
  83.         if grid_on, grid; end 
  84.         hold on;xlabel(xlab);ylabel(ylab);
  85.         old_ord = ['old(dashed) = ' num2str(order) '  '];
  86.     elseif (button >= 48)&(button <= 57)&(isempty(omega));    % fit mode
  87.         disp('must have data to fit');
  88.     elseif (button == abs('w'));            % window mode
  89.         [x1,y1,button]=ginput(1);
  90.         x = [x x1]; y = [y y1];
  91.         hold off;clg; 
  92.                 axis(log10([min([x in(1)]),max([x in(2)]),...
  93.                      min([y in(3)]),max([y in(4)])]));
  94.         [omega,indx] = sort(omega); mf = mf(indx);
  95.         pts = vpck(mf,omega);
  96.         vplot('liv,lm',in,insym,sysout_g,'-r',pts,'+g');
  97.         if grid_on, grid; end 
  98.         hold on;xlabel(xlab);ylabel(ylab);
  99.         title(['window mode:  ' new_ord ]);
  100.     elseif (button == abs('p'));            % plot mode
  101.         hold off;clg; axis([0 0.0001 0 0.0001]); axis;
  102.         [omega,indx] = sort(omega); mf = mf(indx);
  103.         pts = vpck(mf,omega);
  104.         vplot('liv,lm',in,insym,sysout_g,'-r',pts,'+g');
  105.         if grid_on, grid; end 
  106.         hold on;xlabel(xlab);ylabel(ylab);
  107.         title([ new_ord ]);
  108.     elseif (button == abs('k'))
  109.         keyboard;
  110.     elseif (button == abs('g'))
  111.         grid_on = ~grid_on;
  112.     end %if 
  113.  
  114.     [x,y,button]=ginput(1);
  115.  
  116. end %while
  117. %%%%%%%%%%%%%%%%%%%%%%% clean up and return %%%%%%%%%%%%%%%%%%
  118. [omega,indx] = sort(omega); mf = mf(indx);
  119. pts = vpck(mf,omega);
  120. hold off; axis([0 0.0001 0 0.0001]); axis;
  121.  
  122. %
  123. % Copyright MUSYN INC 1991,  All Rights Reserved
  124.