POLYDETREND detrends the input data vector with a polynomial. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: POLYDETREND detrends the input data vector with a polynomial. This function is meant to be used by other ltpda_ functions. To work with Analysis Objects, use ltpda_polydetrend which calls this function. CALL: y = polydetrend(x,order); INPUTS: x - vector of x values order - order of polynomial to fit and subtract OUTPUTS: y - detrended data VERSION: $Id: polydetrend.html,v 1.14 2008/03/31 10:27:44 hewitson Exp $ HISTORY: 30-05-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function y = polydetrend(varargin) 0002 % POLYDETREND detrends the input data vector with a polynomial. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: POLYDETREND detrends the input data vector with a polynomial. 0007 % This function is meant to be used by other ltpda_ functions. 0008 % To work with Analysis Objects, use ltpda_polydetrend which calls 0009 % this function. 0010 % 0011 % CALL: y = polydetrend(x,order); 0012 % 0013 % INPUTS: x - vector of x values 0014 % order - order of polynomial to fit and subtract 0015 % 0016 % OUTPUTS: y - detrended data 0017 % 0018 % VERSION: $Id: polydetrend.html,v 1.14 2008/03/31 10:27:44 hewitson Exp $ 0019 % 0020 % HISTORY: 30-05-07 M Hewitson 0021 % Creation 0022 % 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 0025 if nargin == 2 0026 x = varargin{1}; 0027 order = varargin{2}; 0028 t = [1:length(x)]'; 0029 elseif nargin == 3 0030 t = varargin{1}; 0031 x = varargin{2}; 0032 order = varargin{3}; 0033 else 0034 error('### incorrect inputs.'); 0035 end 0036 0037 % fit polynomial 0038 p = polyfit(t, x, order); 0039 0040 % make polynomial series 0041 py = polyval(p, t); 0042 0043 % detrend 0044 y = x - py; 0045 0046 % END