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

  1. %function out = step_tr(timedata,stepdata,tinc,lastt)
  2. %
  3. %  Creates a stairstep signal function of its INDEPENDENT
  4. %  VARIABLE. The TIMEDATA vector indicates the "times" at
  5. %  which the step changes occur, and the value of the
  6. %  stairstep is given by the vector STEPDATA. The last two
  7. %  variables, TINC and LASTT, correspond to the sample time
  8. %  and length of the step signal.
  9. %
  10. %     TINC  - time increment 
  11. %     LASTT - final time
  12. %
  13. %  See also: COS_TR, SIGGEN, and SIN_TR.
  14.  
  15. function vt = step_tr(timedata,stepdata,tinc,lastt)
  16.  if nargin == 0
  17.    disp('usage: out = step_tr(timedata,stepdata,tinc,lastt)')
  18.    return
  19.  end
  20.  
  21.  if length(timedata) ~= length(stepdata)
  22.    error('timedata and stepdata should be same length')
  23.    return
  24.  end
  25.  [m,n] = size(timedata);
  26.  if n == 1;
  27.    timedata = timedata.';
  28.  end
  29.  
  30.  iv = (0:tinc:lastt)';
  31.  u = zeros(length(iv),1);
  32.  num = length(find((0 <= iv) & (iv < timedata(1))));
  33.  pointer = num;
  34.  
  35.  for i=1:length(stepdata)-1
  36.    num = length(find((timedata(i) <= iv) & (iv < timedata(i+1))));
  37.    u(pointer+1:pointer+num) = stepdata(i)*ones(num,1);
  38.    pointer = pointer + num;
  39.  end
  40.  lu = length(u);
  41.  u(pointer+1:lu) = stepdata(length(stepdata))*ones(lu-pointer,1);
  42.  
  43.  vt = vpck(u,iv);
  44. %
  45. % Copyright MUSYN INC 1991,  All Rights Reserved
  46.