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

 VERSION:     $Id: ltpda_timedomainfit.m,v 1.6 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_timedomainfit('Params')
 
 The following call returns a string that contains the routine CVS version:

 >> version = ltpda_timedomainfit('Version')

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

 >> category = ltpda_timedomainfit('Category')

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

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 % VERSION:     $Id: ltpda_timedomainfit.m,v 1.6 2008/03/25 15:28:13 mauro Exp $
0023 %
0024 % HISTORY:     01-03-2007 M Hewitson
0025 %                 Creation
0026 %
0027 % The following call returns a parameter list object that contains the
0028 % default parameter values:
0029 %
0030 % >> pl = ltpda_timedomainfit('Params')
0031 %
0032 % The following call returns a string that contains the routine CVS version:
0033 %
0034 % >> version = ltpda_timedomainfit('Version')
0035 %
0036 % The following call returns a string that contains the routine category:
0037 %
0038 % >> category = ltpda_timedomainfit('Category')
0039 %
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042 ALGONAME = mfilename;
0043 VERSION  = '$Id: ltpda_timedomainfit.m,v 1.6 2008/03/25 15:28:13 mauro Exp $';
0044 CATEGORY = 'Signal Processing';
0045 
0046 %% Check if this is a call for parameters, the CVS version string
0047 % or the function category
0048 if nargin == 1 && ischar(varargin{1})
0049   in = char(varargin{1});
0050   if strcmp(in, 'Params')
0051     varargout{1} = getDefaultPL();
0052     return
0053   elseif strcmp(in, 'Version')
0054     varargout{1} = VERSION;
0055     return
0056   elseif strcmp(in, 'Category')
0057     varargout{1} = CATEGORY;
0058     return
0059   end
0060 end
0061 
0062 % capture input variable names
0063 invars = {};
0064 for j=1:nargin
0065   iname = inputname(j);
0066   if isempty(iname) & isnumeric(varargin{j})
0067     iname = num2str(varargin{j});
0068   elseif isempty(iname) & ischar(varargin{j})
0069     iname = varargin{j};
0070   end
0071   invars = [invars cellstr(iname)];
0072 end
0073 
0074 ALGONAME = mfilename;
0075 VERSION  = '$Id: ltpda_timedomainfit.m,v 1.6 2008/03/25 15:28:13 mauro Exp $';
0076 
0077 % Look at inputs
0078 if nargin < 1
0079   error('### Incorrect number of inputs.')
0080 end
0081 
0082 as = [];
0083 pl = [];
0084 for j=1:nargin
0085   a = varargin{j};
0086   if isa(a, 'plist')
0087     pl = a;
0088   end
0089   if isa(a, 'ao')
0090     for k=1:length(a)
0091       ak = a(k);
0092       d = ak.data;
0093       if isa(d, 'tsdata')
0094         as = [as ak];
0095       else
0096         warning('### skipping fsdata/AO.');
0097       end
0098     end
0099   end
0100 end
0101 
0102 % unpack parameter list
0103 plo = plist();
0104 
0105 % Initialise output
0106 x  = [];
0107 % Loop over analysis objects and build Matrix for fitting
0108 naFit = length(as);
0109 if naFit < 2
0110   error('### Please input at least two AOs.');
0111 end
0112 
0113 ho = [];
0114 for i=1:naFit
0115 
0116   % get data out
0117   a  = as(i);
0118   ho = [ho a.hist];
0119   d  = a.data;
0120   dinfo = whos('d');
0121   if ~isreal(d.y)
0122     error('### I only work with real time-series at the moment.');
0123   end
0124   x(:,i) = d.y;
0125 end
0126 % Fit
0127 [m,n] = size(x);
0128 [coef, stdx, mse, S] = lscov(x(:,2:n),x(:,1));
0129 
0130 disp(['*** got coefficients: ' num2str(coef.')]);
0131 
0132 % Return new cdata AO with  the coefficients in
0133 % - we add '1' to the front of the coefficients so that ltpda_lincom
0134 %   will work directly.
0135 
0136 % make a new history object
0137 h = history(ALGONAME, VERSION, [], ho);
0138 h = set(h, 'invars', invars);
0139 
0140 % make output analysis object
0141 bo = ao([1 -coef.']);
0142 bo = setnh(bo, 'name', ['fit of [' sprintf('%s ', char(invars{2:end})) '] to ' char(invars{1})]);
0143 bo = setnh(bo, 'hist', h);
0144 
0145 varargout{1} = bo;
0146 
0147 %--------------------------------------------------------------------------
0148 % Get default params
0149 function plo = getDefaultPL()
0150 
0151 disp('* creating default plist...');
0152 plo = plist();
0153 disp('* done.');
0154 
0155 
0156 % END

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