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.9 2008/03/25 15:28:13 mauro Exp $

 HISTORY:     01-03-2007 M Hewitson
                 Creation

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

 >> pl = ltpda_polydetrend('Params')
 
 The following call returns a string that contains the routine CVS version:

 >> version = ltpda_polydetrend('Version')

 The following call returns a string that contains the routine category:

 >> category = ltpda_polydetrend('Category')

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

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.9 2008/03/25 15:28:13 mauro Exp $
0027 %
0028 % HISTORY:     01-03-2007 M Hewitson
0029 %                 Creation
0030 %
0031 % The following call returns a parameter list object that contains the
0032 % default parameter values:
0033 %
0034 % >> pl = ltpda_polydetrend('Params')
0035 %
0036 % The following call returns a string that contains the routine CVS version:
0037 %
0038 % >> version = ltpda_polydetrend('Version')
0039 %
0040 % The following call returns a string that contains the routine category:
0041 %
0042 % >> category = ltpda_polydetrend('Category')
0043 %
0044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0045 
0046 ALGONAME = mfilename;
0047 VERSION  = '$Id: ltpda_polydetrend.m,v 1.9 2008/03/25 15:28:13 mauro Exp $';
0048 CATEGORY = 'Signal Processing';
0049 
0050 %% Check if this is a call for parameters, the CVS version string
0051 % or the function category
0052 if nargin == 1 && ischar(varargin{1})
0053   in = char(varargin{1});
0054   if strcmp(in, 'Params')
0055     varargout{1} = getDefaultPL();
0056     return
0057   elseif strcmp(in, 'Version')
0058     varargout{1} = VERSION;
0059     return
0060   elseif strcmp(in, 'Category')
0061     varargout{1} = CATEGORY;
0062     return
0063   end
0064 end
0065 
0066 
0067 % capture input variable names
0068 invars = {};
0069 as     = [];
0070 ps     = [];
0071 for j=1:nargin
0072   invars = [invars cellstr(inputname(j))];
0073   if isa(varargin{j}, 'ao')
0074     as = [as varargin{j}];
0075   end
0076   if isa(varargin{j}, 'plist')
0077     ps = [ps varargin{j}];
0078   end
0079 end
0080 
0081 
0082 
0083 % Look at inputs
0084 if nargin < 1
0085   error('### Incorrect number of inputs.')
0086 end
0087 
0088 na = length(as);
0089 
0090 % Combine plists
0091 if ~isempty(ps)
0092   pl = combine(ps, getDefaultPL());
0093 else
0094   pl = getDefaultPL();
0095 end
0096 
0097 % Initialise output
0098 bo = [];
0099 
0100 % Unpack parameter list
0101 N = find(pl, 'N');
0102 
0103 % Loop over analysis objects
0104 for i=1:na
0105 
0106   % get data out
0107   a = as(i);
0108   d = a.data;
0109   dinfo = whos('d');
0110   if ~isa(d, 'tsdata')
0111     error('### I only work with time-series at the moment.');
0112   end
0113   if ~isreal(d.y)
0114     error('### I only work with real time-series at the moment.');
0115   end
0116 
0117   try
0118     if find(pl, 'M-FILE ONLY')
0119       y = polydetrend(d.y, N);
0120     else
0121       [y,coeffs] = ltpda_polyreg(d.y, N);
0122     end
0123   catch
0124     y = polydetrend(d.y, N);
0125   end
0126     
0127   % Make output analysis object
0128   nameStr = sprintf('poly_detrend(%s)', d.name);
0129 
0130   % create new output data
0131   data = tsdata(y, d.fs);
0132   data = set(data, 'name', nameStr);
0133   data = set(data, 'xunits', d.xunits);
0134   data = set(data, 'yunits', d.yunits);
0135 
0136   % create new output history
0137   h = history(ALGONAME, VERSION, pl, a.hist);
0138   h = set(h, 'invars', invars);
0139 
0140   % make output analysis object
0141   b = ao(data, h);
0142 
0143   % set name
0144   % name for this object
0145   if isempty(invars{i})
0146     n1 = a.name;
0147   else
0148     n1 = invars{i};
0149   end
0150 
0151   nameStr = sprintf('poly_detrend(%s)', n1);
0152   b = setnh(b, 'name', nameStr);
0153 
0154   % Add to output array
0155   bo = [bo b];
0156 
0157 end
0158 
0159 varargout{1} = bo;
0160 
0161 %--------------------------------------------------------------------------
0162 % Get default params
0163 function plo = getDefaultPL()
0164 
0165 disp('* creating default plist...');
0166 
0167 plo = plist('N', 1);
0168 
0169 disp('* done.');
0170 
0171 % END

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003