0001 function x=ntdetrend(x,order,w,basis)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 if nargin<2; error('!'); end
0012 if nargin<3; w=[]; end
0013 if nargin<4||isempty(basis); basis='polynomials'; end
0014
0015 dims=size(x);
0016 x=x(:,:);
0017
0018
0019 switch basis
0020 case 'polynomials'
0021 r=zeros(size(x,1),order);
0022 lin=linspace(-1,1,size(x,1));
0023 for k=1:order
0024 r(:,k)=lin.^k;
0025 end
0026 case 'sinusoids'
0027 r=zeros(size(x,1),order*2);
0028 lin=linspace(-1,1,size(x,1));
0029 for k=1:order
0030 r(:,2*k-1)=sin(2*pi*k*lin/2);
0031 r(:,2*k)=cos(2*pi*k*lin/2);
0032 end
0033 otherwise
0034 error('!');
0035 end
0036
0037 x=nt_demean(x,w);
0038 if order>0;
0039 x=nt_tsr(x,r,0,w);
0040 end
0041
0042 x=reshape (x,dims);
0043
0044
0045
0046