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.10 2007/07/16 12:55:53 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 = get(d, 'vals');
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 x = 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')
0127 xa = da.x;
0128 elseif isa(da, 'fsdata')
0129 xa = da.xx;
0130 else
0131 error('### unknown data type.');
0132 end
0133
0134
0135 if ~strcmp(dainfo.class, dinfo.class)
0136 error('### all analysis objects should have the same data type.');
0137 end
0138
0139
0140 if isa(d, 'tsdata')
0141 if da.fs ~= d.fs
0142 error('### all analysis objects should contain same sample rate data.');
0143 end
0144 end
0145
0146
0147 if x~=0
0148 if length(x) ~= length(xa)
0149 error('### all vectors should be the same length.');
0150 end
0151 end
0152
0153 c = coeffs(j);
0154 x = x + c.*xa;
0155
0156 if j<=length(invars)
0157 if isempty(invars{j})
0158 n = aa.name;
0159 else
0160 n = invars{j};
0161 end
0162 else
0163 n = aa.name;
0164 end
0165 nameStr = [nameStr '+' num2str(c) sprintf('*%s', n)];
0166
0167
0168 ho = [ho aa.hist];
0169 end
0170
0171
0172 if nameStr(1) == '+'
0173 nameStr = nameStr(2:end);
0174 end
0175
0176
0177
0178
0179 if isa(d, 'tsdata')
0180 data = tsdata(x, d.fs);
0181 data = set(data, 'name', nameStr);
0182 elseif isa(d, 'fsdata')
0183 data = fsdata(d.f, x, d.fs);
0184 data = set(data, 'name', nameStr);
0185 else
0186 error('### unknown data type.');
0187 end
0188
0189
0190 h = history(ALGONAME, VERSION, pl, ho);
0191 h = set(h, 'invars', invars);
0192
0193
0194 b = ao(data, h);
0195
0196
0197 b = set(b, 'name', nameStr);
0198
0199 varargout{1} = b;
0200
0201
0202
0203 function plo = getDefaultPL()
0204
0205 disp('* creating default plist...');
0206 plo = plist();
0207 disp('* done.');
0208
0209
0210