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.8 2008/02/08 14:59:31 anneke Exp $ HISTORY: 01-03-2007 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.8 2008/02/08 14:59:31 anneke 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.8 2008/02/08 14:59:31 anneke 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.y) 0090 error('### I only work with real time-series at the moment.'); 0091 end 0092 0093 try 0094 if find(pl, 'M-FILE ONLY') 0095 y = polydetrend(d.y, N); 0096 else 0097 [y,coeffs] = ltpda_polyreg(d.y, N); 0098 end 0099 catch 0100 y = polydetrend(d.y, N); 0101 end 0102 0103 % Make output analysis object 0104 nameStr = sprintf('poly_detrend(%s)', d.name); 0105 0106 % create new output data 0107 data = tsdata(y, d.fs); 0108 data = set(data, 'name', nameStr); 0109 data = set(data, 'xunits', d.xunits); 0110 data = set(data, 'yunits', d.yunits); 0111 0112 % create new output history 0113 h = history(ALGONAME, VERSION, pl, a.hist); 0114 h = set(h, 'invars', invars); 0115 0116 % make output analysis object 0117 b = ao(data, h); 0118 0119 % set name 0120 % name for this object 0121 if isempty(invars{i}) 0122 n1 = a.name; 0123 else 0124 n1 = invars{i}; 0125 end 0126 0127 nameStr = sprintf('poly_detrend(%s)', n1); 0128 b = setnh(b, 'name', nameStr); 0129 0130 % Add to output array 0131 bo = [bo b]; 0132 0133 end 0134 0135 varargout{1} = bo; 0136 0137 %-------------------------------------------------------------------------- 0138 % Get default params 0139 function plo = getDefaultPL() 0140 0141 disp('* creating default plist...'); 0142 plo = plist(); 0143 plo = append(plo, param('N', 1)); 0144 disp('* done.'); 0145 0146 % END