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 target time-series AO.

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.

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

 DESCRIPTION: LTPDA_TIMEDOMAINFIT uses lscov to fit a set of time-series AOs to
              a target time-series AO.

 CALL:        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

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

              >> pl = ltpda_xcorr('Params')

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

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