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

  1. %function [freq,mag] = terpol(freqin,magin,npts)
  2. %   this function interpolates the irregularly spaced
  3. %   frequency/magnitude data FREQIN and MAGIN,
  4. %   in the following way. first, it assumes that
  5. %   FREQIN is a row vector of nonnegative frequencies,
  6. %   between 0 and pi:
  7. %   foreach 1 <= i <= NPTS
  8. %      if      pi*(i-1)/NPTS  <  FREQIN(1),
  9. %        then    FREQ(i)  :=  MAG(1)
  10. %      if      FREQIN(length(FREQIN))  <=  pi*(i-1)/NPTS
  11. %        then    MAGOUT((i) =  MAGIN(length(MAGIN)) 
  12. %      for other values of FREQIN(i), the program does
  13. %      linear interpolation between data points               
  14. %
  15.  
  16. function [freq,mag] = terpol(freqin,magin,npts)
  17.  lmagin = (1/log(10))*log(magin);  
  18.  freq = (pi/npts)*(0:npts-1);
  19.  lmag = zeros(1,npts);
  20.  topval = length(freqin);
  21.  p = find(freq<freqin(1));
  22.  lmag(p) = lmagin(1)*ones(1,length(p));
  23.  p = find(freqin(topval)<=freq);
  24.  lmag(p) = lmagin(topval)*ones(1,length(p));
  25.  for i=2:topval
  26.    p=find(freq>=freqin(i-1) & freq<freqin(i));
  27.    rat = freq(p) - freqin(i-1)*ones(1,length(p));
  28.    rat = (1/(freqin(i)-freqin(i-1)))*rat;
  29.    lmag(p)=(ones(1,length(p))-rat)*lmagin(i-1)+rat*lmagin(i);
  30.  end
  31.  mag = exp(log(10)*lmag);
  32. %
  33. % Copyright MUSYN INC 1991,  All Rights Reserved
  34.