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

  1. function zd=dtrend(z,o,brp)
  2. %DTREND removes trends from data sets
  3. %
  4. %    ZD = dtrend(Z)    or   ZD = dtrend(Z,O,BREAKPOINTS)
  5. %
  6. %    Z is the data set to be detrended, organized with the data records as
  7. %    column vectors. ZD is returned as the detrended data.
  8. %    
  9. %    If O = 0 (the default case) the sample means are removed from each of
  10. %    the columns.
  11. %
  12. %    If O = 1, linear trends are removed. A continuous, piecewise linear
  13. %    trend is adjusted to each of the data records, and then removed. The
  14. %    interior breakpoints for the linear trend segments are contained in
  15. %    the row vector BREAKPOINTS. The default value is that there are no
  16. %    interior breakpoints, so that one single straight line is removed from
  17. %    each of the data records.
  18.  
  19. %    L. Ljung 7-8-87
  20. %    Copyright (c), 1987-90 The MathWorks, Inc.
  21. %    All Rights Reserved
  22.  
  23. [N,nz]=size(z);
  24. if nargin<3,brp=[];end
  25. if nargin<2,o=0;end
  26. if o==1
  27.    lb=length(brp);if lb==0,brp=1;lb=1;else
  28.    if length(find(brp==1))==0,
  29.    brp(2:lb+1)=brp;brp(1)=1;end,end
  30.    lb=length(brp);if brp(lb)>=N,lb=lb-1;end
  31.    for k=1:nz
  32.     phi=zeros(lb+1,N);
  33.     phi(1,:)=ones(1,N);
  34.     for kb=1:lb
  35.     int=[brp(kb):N];
  36.     phi(kb+1,int)=10*(int-int(1))/N;
  37.     end
  38.     zd(:,k)=z(:,k)-phi'*(phi'\z(:,k));
  39.     end
  40. end
  41. if o==0
  42.     for k=1:nz
  43.     zd(:,k)=z(:,k)-mean(z(:,k));
  44.     end
  45. end
  46.