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

  1. % function sys = fitmag(magdata,weight,heading,osysl_g)
  2. %
  3. %   FITMAG fits a stable, minimum phase transfer function
  4. %   to magnitude data, MAGDATA, with a supplied frequency
  5. %   domain weighting function, WEIGHT. Both these should
  6. %   be VARYING matrices, with identical INDEPENDENT
  7. %   VARIABLE values. FITMAG uses GENPHASE to generate
  8. %   phase data, and FITSYS to do the fit.  OSYSL_G (optional) 
  9. %   is the FRSP of the old fit.  If given, it will be
  10. %   displayed along with the data.
  11. %
  12. %   See also: FITSYS, GENPHASE, INVFREQS, MAGFIT, MUSYNFIT, and MUSYNFLP.
  13.  
  14. function sys = fitmag(d,wt,heading,osysl_g)
  15.  
  16.  if nargin < 2
  17.    disp(['usage: sys = fitmag(magdata,weight)']);
  18.    return
  19.  end
  20.  if nargin == 2
  21.    heading = 'CURVE FITTING';
  22.  end
  23.  
  24.  [dtype,drows,dcols,dnum] = minfo(d);
  25.  if dtype ~= 'vary'
  26.    error(['magdata should be a VARYING matrix']);
  27.    return
  28.  end
  29.  
  30.  [wtype,wrows,wcols,wnum] = minfo(wt);
  31.  if wtype ~= 'vary'
  32.    error(['weight should be a VARYING matrix']);
  33.    return
  34.  end
  35.  
  36.  code = indvcmp(d,wt);
  37.  if code ~= 1
  38.     error('inconsistent VARYING data in magdata and weight')
  39.     return
  40.  end
  41.  
  42.     clg;subplot(211);             % begin JCD CHANGE 
  43.      if nargin <= 3
  44.         vplot('liv,lm',d);
  45.          xlabel('  data ');
  46.       else
  47.         vplot('liv,lm',d,osysl_g);
  48.          xlabel('  data and old fit ');
  49.      end    
  50.     title([heading]);
  51.     subplot(212);
  52.     vplot('liv,lm',wt); 
  53.     title('wt for fit');              %  end JCD CHANGE
  54.  xlabel(['NOTE APPROXIMATE ORDER NECESSARY FOR FIT.....']);
  55.  ord = input('ENTER ORDER OF CURVE FIT      ');
  56.  while any([ isempty(ord)  (ord<0)  (floor(ord) ~= ceil(ord)) ])
  57.      ord = input('try again - a nonnegative integer..    ');
  58.  end
  59.  
  60.  resp = genphase(d);
  61.  
  62.  while ord >= 0
  63.    sysh = fitsys(resp,ord,wt,1);
  64.    sysh_g = frsp(sysh,d);
  65.    rat_data = sbs(d,sysh_g);
  66.    hhead = [',   W/ORDER = ' int2str(ord)];
  67.  
  68. %   vplot('liv,lm',rat_data)  %  replaced by the following code
  69.     clg;subplot(211);             % begin JCD CHANGE
  70.      if nargin <= 3
  71. %        vplot('liv,lm',sysh_g,resp);
  72. %         xlabel('  1) fit    2) data ');
  73.         vplot('liv,lm',resp,sysh_g);
  74.          xlabel('  1) data    2) newfit ');
  75.       else
  76. %        vplot('liv,lm',sysh_g,resp,osysl_g);
  77. %         xlabel('  1) fit    2) data   3) oldfit ');
  78.         vplot('liv,lm',resp,osysl_g,sysh_g);
  79.          xlabel('  1) data    2) oldfit   3) newfit ');
  80.      end
  81.     title([heading hhead]);
  82.     subplot(212);
  83.     vplot('liv,lm',wt); 
  84.     title('weight for fit');            % end JCD CHANGE
  85.  
  86.    xlabel('ENTER NEW ORDER, or NEGATIVE NUMBER TO STOP ');
  87.    pause;
  88.    ord = input('ENTER NEW ORDER, NEGATIVE TO STOP    ');
  89.    while any([ isempty(ord)  (floor(ord) ~= ceil(ord)) ])
  90.        ord = input('try again - an integer, negative to stop..    ');
  91.    end %while any
  92.  end %while ord
  93. sys = sysh;
  94. subplot(111);
  95. %
  96. % Copyright MUSYN INC 1991,  All Rights Reserved
  97.