Home > m > sigproc > time_domain > ltpda_timedomainfit.m

ltpda_timedomainfit

PURPOSE ^

LTPDA_TIMEDOMAINFIT uses lscov to fit a set of time-series AOs to a

SYNOPSIS ^

function varargout = ltpda_timedomainfit(varargin)

DESCRIPTION ^

 LTPDA_TIMEDOMAINFIT uses lscov to fit a set of time-series AOs to a
 target time-series AO.
 
 >> b = ltpda_timedomainfit(a1,a2,a3,..., pl)
 
 Inputs:
   asN   - a list of analysis objects containing the data to be fitted.
           The first input analysis object that contains time-series data
           is the target object. A linear combination of all other
           time-series AOs is fit to this target.
   pl - a parameter list
 
 Parameters:
   no valid parameters at the moment.
   
 
 Outputs:
   b - cdata type analysis object containing the fitted coefficients
 
 The following call returns a parameter list object that contains the
 default parameter values:
 
 >> pl = ltpda_timedomainfit('Params')
 
 
 M Hewitson, A Monsky 01-03-07
 
 $Id: ltpda_timedomainfit.m,v 1.2 2007/06/12 12:32:14 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = ltpda_timedomainfit(varargin) 
0002 
0003 % LTPDA_TIMEDOMAINFIT uses lscov to fit a set of time-series AOs to a
0004 % target time-series AO.
0005 %
0006 % >> b = ltpda_timedomainfit(a1,a2,a3,..., pl)
0007 %
0008 % Inputs:
0009 %   asN   - a list of analysis objects containing the data to be fitted.
0010 %           The first input analysis object that contains time-series data
0011 %           is the target object. A linear combination of all other
0012 %           time-series AOs is fit to this target.
0013 %   pl - a parameter list
0014 %
0015 % Parameters:
0016 %   no valid parameters at the moment.
0017 %
0018 %
0019 % Outputs:
0020 %   b - cdata type analysis object containing the fitted coefficients
0021 %
0022 % The following call returns a parameter list object that contains the
0023 % default parameter values:
0024 %
0025 % >> pl = ltpda_timedomainfit('Params')
0026 %
0027 %
0028 % M Hewitson, A Monsky 01-03-07
0029 %
0030 % $Id: ltpda_timedomainfit.m,v 1.2 2007/06/12 12:32:14 hewitson Exp $
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 for j=1:nargin
0045   iname = inputname(j);
0046   if isempty(iname) & isnumeric(varargin{j})
0047     iname = num2str(varargin{j});
0048   elseif isempty(iname) & ischar(varargin{j})
0049     iname = varargin{j};
0050   end    
0051   invars = [invars cellstr(iname)];
0052 end
0053 
0054 ALGONAME = mfilename;
0055 VERSION  = '$Id: ltpda_timedomainfit.m,v 1.2 2007/06/12 12:32:14 hewitson Exp $';
0056 
0057 % Look at inputs
0058 if nargin < 1
0059   error('### Incorrect number of inputs.')
0060 end
0061 
0062 as = [];
0063 pl = [];
0064 for j=1:nargin
0065   a = varargin{j};
0066   if isa(a, 'plist')
0067     pl = a;
0068   end
0069   if isa(a, 'ao')
0070     for k=1:length(a)
0071       ak = a(k);
0072       d = ak.data;
0073       if isa(d, 'tsdata')
0074         as = [as ak];
0075       else
0076         warning('### skipping fsdata/AO.');
0077       end
0078     end
0079   end  
0080 end
0081 
0082 % unpack parameter list
0083 plo = plist();
0084 
0085 % Initialise output
0086 x  = [];
0087 % Loop over analysis objects and build Matrix for fitting
0088 naFit = length(as);
0089 if naFit < 2
0090   error('### Please input at least two AOs.');
0091 end
0092 
0093 ho = [];
0094 for i=1:naFit
0095   
0096   % get data out
0097   a  = as(i);
0098   ho = [ho a.hist];
0099   d  = a.data;
0100   dinfo = whos('d');
0101   if ~isreal(d.x)
0102     error('### I only work with real time-series at the moment.');
0103   end  
0104   x(:,i) = d.x;  
0105 end
0106 % Fit
0107 [m,n] = size(x);
0108 [coef, stdx, mse, S] = lscov(x(:,2:n),x(:,1));
0109 
0110 disp(['*** got coefficients: ' num2str(coef.')]);
0111 
0112 % Return new cdata AO with  the coefficients in
0113 % - we add '1' to the front of the coefficients so that ltpda_lincom
0114 %   will work directly.
0115 
0116 % make a new history object
0117 h = history(ALGONAME, VERSION, [], ho);
0118 h = set(h, 'invars', invars);
0119 
0120 % make output analysis object
0121 bo = ao([1 -coef.']);
0122 bo = set(bo, 'name', ['fit of [' sprintf('%s ', char(invars{2:end})) '] to ' char(invars{1})]);
0123 bo = set(bo, 'hist', h);
0124 
0125 varargout{1} = bo;
0126 
0127 %--------------------------------------------------------------------------
0128 % Get default params
0129 function plo = getDefaultPL()
0130 
0131 disp('* creating default plist...');
0132 plo = plist();
0133 disp('* done.');
0134 
0135 
0136 % END

Generated on Mon 02-Jul-2007 12:19:41 by m2html © 2003