Home > m > sigproc > time_domain > ltpda_polydetrend.m

ltpda_polydetrend

PURPOSE ^

LTPDA_POLYDETREND detrends the input analysis object using a polynomial of degree N.

SYNOPSIS ^

function varargout = ltpda_polydetrend(varargin)

DESCRIPTION ^

 LTPDA_POLYDETREND detrends the input analysis object using a polynomial of degree N.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: LTPDA_POLYDETREND detrends the input analysis object using a
              polynomial of degree N.

 CALL:        b = ltpda_polydetrend(a1,a2,a3,..., pl)

 INPUTS:      aN  - a list of analysis objects
              pl  - a parameter list

 OUTPUTS:     b - array of analysis objects

              If the last input argument is a parameter list (plist) it is used.
              The following parameters are recognised.

 PARAMETERS:  'N' - degree of polynomial [default: 1]

 GUI CALL:    The following call returns a parameter list object that contains
              the default parameter values:

              >> pl = ltpda_xcorr('Params')

 VERSION:     $Id: ltpda_polydetrend.m,v 1.4 2007/07/16 12:52:21 ingo Exp $

 HISTORY:     01-03-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = ltpda_polydetrend(varargin)
0002 % LTPDA_POLYDETREND detrends the input analysis object using a polynomial of degree N.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: LTPDA_POLYDETREND detrends the input analysis object using a
0007 %              polynomial of degree N.
0008 %
0009 % CALL:        b = ltpda_polydetrend(a1,a2,a3,..., pl)
0010 %
0011 % INPUTS:      aN  - a list of analysis objects
0012 %              pl  - a parameter list
0013 %
0014 % OUTPUTS:     b - array of analysis objects
0015 %
0016 %              If the last input argument is a parameter list (plist) it is used.
0017 %              The following parameters are recognised.
0018 %
0019 % PARAMETERS:  'N' - degree of polynomial [default: 1]
0020 %
0021 % GUI CALL:    The following call returns a parameter list object that contains
0022 %              the default parameter values:
0023 %
0024 %              >> pl = ltpda_xcorr('Params')
0025 %
0026 % VERSION:     $Id: ltpda_polydetrend.m,v 1.4 2007/07/16 12:52:21 ingo Exp $
0027 %
0028 % HISTORY:     01-03-2007 M Hewitson
0029 %                 Creation
0030 %
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 % Check if this is a call for parameters
0034 if nargin == 1
0035   in = char(varargin{1});
0036   if strcmp(in, 'Params')
0037     varargout{1} = getDefaultPL();
0038     return
0039   end
0040 end
0041 
0042 % capture input variable names
0043 invars = {};
0044 as     = [];
0045 ps     = [];
0046 for j=1:nargin
0047   invars = [invars cellstr(inputname(j))];
0048   if isa(varargin{j}, 'ao')
0049     as = [as varargin{j}];
0050   end
0051   if isa(varargin{j}, 'plist')
0052     ps = [ps varargin{j}];
0053   end
0054 end
0055 
0056 ALGONAME = mfilename;
0057 VERSION  = '$Id: ltpda_polydetrend.m,v 1.4 2007/07/16 12:52:21 ingo Exp $';
0058 
0059 % Look at inputs
0060 if nargin < 1
0061   error('### Incorrect number of inputs.')
0062 end
0063 
0064 na = length(as);
0065 
0066 % Combine plists
0067 if ~isempty(ps)
0068   pl = combine(ps, getDefaultPL());
0069 else
0070   pl = getDefaultPL();
0071 end
0072 
0073 % Initialise output
0074 bo = [];
0075 
0076 % Unpack parameter list
0077 N = find(pl, 'N');
0078 
0079 % Loop over analysis objects
0080 for i=1:na
0081 
0082   % get data out
0083   a = as(i);
0084   d = a.data;
0085   dinfo = whos('d');
0086   if ~isa(d, 'tsdata')
0087     error('### I only work with time-series at the moment.');
0088   end
0089   if ~isreal(d.x)
0090     error('### I only work with real time-series at the moment.');
0091   end
0092 
0093   y = polydetrend(d.x, N);
0094 
0095   % Make output analysis object
0096   nameStr = sprintf('poly_detrend(%s)', d.name);
0097 
0098   % create new output data
0099   data = tsdata(y, d.fs);
0100   data = set(data, 'name', nameStr);
0101   data = set(data, 'xunits', d.xunits);
0102   data = set(data, 'yunits', d.yunits);
0103 
0104   % create new output history
0105   h = history(ALGONAME, VERSION, pl, a.hist);
0106   h = set(h, 'invars', invars);
0107 
0108   % make output analysis object
0109   b = ao(data, h);
0110 
0111   % set name
0112   % name for this object
0113   if isempty(invars{i})
0114     n1 = a.name;
0115   else
0116     n1 = invars{i};
0117   end
0118 
0119   nameStr = sprintf('poly_detrend(%s)', n1);
0120   b = set(b, 'name', nameStr);
0121 
0122   % Add to output array
0123   bo = [bo b];
0124 
0125 end
0126 
0127 varargout{1} = bo;
0128 
0129 %--------------------------------------------------------------------------
0130 % Get default params
0131 function plo = getDefaultPL()
0132 
0133 disp('* creating default plist...');
0134 plo = plist();
0135 plo = append(plo, param('N', 1));
0136 disp('* done.');
0137 
0138 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003