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

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