0001 function varargout = ltpda_timedomainfit(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
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
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.html,v 1.2 2007/07/10 05:37:14 hewitson Exp $';
0056
0057
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
0083 plo = plist();
0084
0085
0086 x = [];
0087
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
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
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
0113
0114
0115
0116
0117 h = history(ALGONAME, VERSION, [], ho);
0118 h = set(h, 'invars', invars);
0119
0120
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
0129 function plo = getDefaultPL()
0130
0131 disp('* creating default plist...');
0132 plo = plist();
0133 disp('* done.');
0134
0135
0136