Home > m > sigproc > time_domain > polydetrend.m

polydetrend

PURPOSE ^

POLYDETREND detrends the input data vector with a polynomial.

SYNOPSIS ^

function y = polydetrend(varargin)

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.
 
 Usage: y = polydetrend(x,order);
 
 Inputs:
   x     - vector of x values
   order - order of polynomial to fit and subtract
 
 Outputs:
   y   - detrended data
 
 M Hewitson 30-05-07
 
 $Id: polydetrend.html,v 1.1 2007/06/08 14:15:11 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003