0001 function varargout = ltpda_lincom(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
0035
0036 if nargin == 1
0037 in = char(varargin{1});
0038 if strcmp(in, 'Params')
0039 varargout{1} = getDefaultPL();
0040 return
0041 end
0042 end
0043
0044
0045 invars = {};
0046 for j=1:nargin
0047 invars = [invars cellstr(inputname(j))];
0048 end
0049
0050 ALGONAME = mfilename;
0051 VERSION = '$Id: ltpda_lincom.m,v 1.13 2007/11/09 14:07:39 ingo Exp $';
0052
0053
0054 b = [];
0055 ho = [];
0056
0057
0058
0059
0060 pl = [];
0061 coeffs = [];
0062 na = 0;
0063 for j=1:nargin
0064 a = varargin{j};
0065 if isa(a, 'plist')
0066 pl = a;
0067 end
0068 end
0069
0070
0071 as = [];
0072 for j=1:nargin
0073 a = varargin{j};
0074 for k=1:length(a)
0075 ak = a(k);
0076 if isa(ak, 'ao')
0077 d = ak.data;
0078
0079 if isa(d, 'cdata')
0080 coeffs = d.y;
0081
0082 ho = [ho ak.hist];
0083
0084
0085 elseif isa(d, 'tsdata')
0086 as = [as ak];
0087 end
0088 end
0089 end
0090 end
0091
0092
0093 if ~isempty(pl) && isempty(coeffs)
0094 coeffs = find(pl, 'coeffs');
0095 end
0096
0097 na = length(as);
0098 nc = length(coeffs);
0099
0100 if na < 2
0101 error('### at least two analysis objects are needed to form a linear combination.');
0102 end
0103
0104 if na ~= nc
0105 disp(sprintf('Num AOs input: %d', na));
0106 disp(sprintf('Num Coeffs input: %d', nc));
0107 error('### specify one coefficient per analysis object.');
0108 end
0109
0110
0111 nameStr = [];
0112 y = 0;
0113 for j=1:na
0114
0115
0116 aa = as(j);
0117 da = aa.data;
0118 dainfo = whos('da');
0119
0120
0121 if j==1
0122 d = da;
0123 dinfo = whos('d');
0124 end
0125
0126 if isa(da, 'tsdata') || isa(da, 'fsdata')
0127 ya = da.y;
0128 else
0129 error('### unknown data type.');
0130 end
0131
0132
0133 if ~strcmp(dainfo.class, dinfo.class)
0134 error('### all analysis objects should have the same data type.');
0135 end
0136
0137
0138 if isa(d, 'tsdata')
0139 if da.fs ~= d.fs
0140 error('### all analysis objects should contain same sample rate data.');
0141 end
0142 end
0143
0144
0145 if y~=0
0146 if length(y) ~= length(ya)
0147 error('### all vectors should be the same length.');
0148 end
0149 end
0150
0151 c = coeffs(j);
0152 y = y + c.*ya;
0153
0154 if j<=length(invars)
0155 if isempty(invars{j})
0156 n = aa.name;
0157 else
0158 n = invars{j};
0159 end
0160 else
0161 n = aa.name;
0162 end
0163 nameStr = [nameStr '+' num2str(c) sprintf('*%s', n)];
0164
0165
0166 ho = [ho aa.hist];
0167 end
0168
0169
0170 if nameStr(1) == '+'
0171 nameStr = nameStr(2:end);
0172 end
0173
0174
0175
0176
0177 if isa(d, 'tsdata')
0178 data = tsdata(d.x, y);
0179 data = set(data, 'name', nameStr);
0180 elseif isa(d, 'fsdata')
0181 data = fsdata(d.x, y, d.fs);
0182 data = set(data, 'name', nameStr);
0183 else
0184 error('### unknown data type.');
0185 end
0186
0187
0188 h = history(ALGONAME, VERSION, pl, ho);
0189 h = set(h, 'invars', invars);
0190
0191
0192 b = ao(data, h);
0193
0194
0195 b = set(b, 'name', nameStr);
0196
0197 varargout{1} = b;
0198
0199
0200
0201 function plo = getDefaultPL()
0202
0203 plo = plist();
0204
0205
0206