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