Home > bobstuff > detrend.m

detrend

PURPOSE ^

DETREND removes trends in u using a polynomial of order norder.

SYNOPSIS ^

function unew=detrend(u,norder)

DESCRIPTION ^

 DETREND removes trends in u using a polynomial of order norder.

 unew=DETREND(u,[norder]) removes trends in u using a polynomial
 of order norder. If u has size u(n,m), DETREND operates on n 
 vectors of length m.  norder is an optional parameter which 
 specifies the order of the polynominal used to determine the 
 least-squares fit to the trend. norder is assumed to be 1 if 
 not included in the input. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 ver. 1: 12/1/96 (RG)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001     function unew=detrend(u,norder)
0002 
0003 % DETREND removes trends in u using a polynomial of order norder.
0004 %
0005 % unew=DETREND(u,[norder]) removes trends in u using a polynomial
0006 % of order norder. If u has size u(n,m), DETREND operates on n
0007 % vectors of length m.  norder is an optional parameter which
0008 % specifies the order of the polynominal used to determine the
0009 % least-squares fit to the trend. norder is assumed to be 1 if
0010 % not included in the input.
0011 %
0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 % ver. 1: 12/1/96 (RG)
0014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0015 
0016 if nargin==1; norder=1;end;
0017 [n,m]=size(u);
0018 flip=0;
0019 if m==1;flip=1;u=u.'; [n,m]=size(u); end;
0020 for i=1:n;
0021 utrend=polyfit2(1:m,u(i,:),norder,1:m);
0022 unew(i,:)=u(i,:)-utrend;
0023 end;
0024 
0025 if flip; unew=unew'; end;

Generated on Thu 01-Dec-2005 07:46:03 by m2html © 2003