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 M Hewitson, A Monsky 01-03-07 $Id: ltpda_timedomainfit.html,v 1.1 2007/06/08 14:15:11 hewitson Exp $
0001 function bo = 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 % M Hewitson, A Monsky 01-03-07 0023 % 0024 % $Id: ltpda_timedomainfit.html,v 1.1 2007/06/08 14:15:11 hewitson Exp $ 0025 % 0026 0027 % capture input variable names 0028 invars = {}; 0029 for j=1:nargin 0030 iname = inputname(j); 0031 if isempty(iname) & isnumeric(varargin{j}) 0032 iname = num2str(varargin{j}); 0033 elseif isempty(iname) & ischar(varargin{j}) 0034 iname = varargin{j}; 0035 end 0036 invars = [invars cellstr(iname)]; 0037 end 0038 0039 ALGONAME = mfilename; 0040 VERSION = '$Id: ltpda_timedomainfit.html,v 1.1 2007/06/08 14:15:11 hewitson Exp $'; 0041 0042 % Look at inputs 0043 if nargin < 1 0044 error('### Incorrect number of inputs.') 0045 end 0046 0047 as = []; 0048 pl = []; 0049 for j=1:nargin 0050 a = varargin{j}; 0051 if isa(a, 'plist') 0052 pl = a; 0053 end 0054 if isa(a, 'ao') 0055 for k=1:length(a) 0056 ak = a(k); 0057 d = ak.data; 0058 if isa(d, 'tsdata') 0059 as = [as ak]; 0060 else 0061 warning('### skipping fsdata/AO.'); 0062 end 0063 end 0064 end 0065 end 0066 0067 % unpack parameter list 0068 plo = plist(); 0069 0070 % Initialise output 0071 x = []; 0072 % Loop over analysis objects and build Matrix for fitting 0073 naFit = length(as); 0074 if naFit < 2 0075 error('### Please input at least two AOs.'); 0076 end 0077 0078 ho = []; 0079 for i=1:naFit 0080 0081 % get data out 0082 a = as(i); 0083 ho = [ho a.hist]; 0084 d = a.data; 0085 dinfo = whos('d'); 0086 if ~isreal(d.x) 0087 error('### I only work with real time-series at the moment.'); 0088 end 0089 x(:,i) = d.x; 0090 end 0091 % Fit 0092 [m,n] = size(x); 0093 [coef, stdx, mse, S] = lscov(x(:,2:n),x(:,1)); 0094 0095 disp(['*** got coefficients: ' num2str(coef.')]); 0096 0097 % Return new cdata AO with the coefficients in 0098 % - we add '1' to the front of the coefficients so that ltpda_lincom 0099 % will work directly. 0100 0101 % make a new history object 0102 h = history(ALGONAME, VERSION, [], ho); 0103 h = set(h, 'invars', invars); 0104 0105 % make output analysis object 0106 bo = ao([1 -coef.']); 0107 bo = set(bo, 'name', ['fit of [' sprintf('%s ', char(invars{2:end})) '] to ' char(invars{1})]); 0108 bo = set(bo, 'hist', h); 0109 % END 0110 0111 % 0112 % %-------------------------------------------------------------------------- 0113 % x = []; 0114 % % Loop over asSubt 0115 % naSubt = length(asSubt); 0116 % for i=1:naSubt 0117 % 0118 % % get data out 0119 % a = asSubt(i); 0120 % d = a.data; 0121 % dinfo = whos('d'); 0122 % if ~isa(d, 'tsdata') 0123 % error('### I only work with time-series at the moment.'); 0124 % end 0125 % if ~isreal(d.x) 0126 % error('### I only work with real time-series at the moment.'); 0127 % end 0128 % 0129 % x(:,i) = d.x; 0130 % 0131 % end 0132 % 0133 % %% calculate new timeseries 0134 % [m,n] = size(x); 0135 % sum = 0; 0136 % for i=2:n 0137 % sum = sum + coef(i-1).*x(:,i); 0138 % end 0139 % res = x(:,1) - sum; 0140 % %% create output analysis object 0141 % nameStr = sprintf('timedomainfit(%s)', d.name); 0142 % 0143 % % create new output data 0144 % data = tsdata(res, d.fs); 0145 % data = set(data, 'name', nameStr); 0146 % data = set(data, 'xunits', d.xunits); 0147 % data = set(data, 'yunits', d.yunits); 0148 % 0149 % plo = append(plo, param('coefficients', coef)); 0150 % plo = append(plo, param('standard deviation',stdx)); 0151 % plo = append(plo, param('mean square error', mse)); 0152 % plo = append(plo, param('covariance matrix', S)); 0153 % % create new output history 0154 % h = history(ALGONAME, VERSION, plo, a.hist); 0155 % 0156 % % make output analysis object 0157 % b = ao(data, h); 0158 % 0159 % % set name 0160 % b = set(b, 'name', nameStr); 0161 % 0162 % % Add to output array 0163 % bo = [bo b]; 0164 0165 % END