LTPDA_LINCOM make the linear combination of the input analysis objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: LTPDA_LINCOM make the linear combination of the input analysis objects. CALL: b = lincom(a1,a2,a3,...,pl) b = lincom(a1,a2,a3,...,aN) If no parameter list is specified, one of the analysis objects should contain a cdata type with the coefficients inside. INPUTS: aN - a list of analysis objects of the same type pl - a parameter list OUTPUTS: b - output analysis object If the last input argument is a parameter list (plist) it is used. The following parameters are recognised. PARAMETERS: 'coeffs' - vector of coefficients, same length as number of input AOs VERSION: $Id: ltpda_lincom.html,v 1.14 2008/03/31 10:27:43 hewitson Exp $ HISTORY: 14-02-07 M Hewitson Creation. The following call returns a parameter list object that contains the default parameter values: >> pl = ltpda_lincom('Params') The following call returns a string that contains the routine CVS version: >> version = ltpda_lincom('Version') The following call returns a string that contains the routine category: >> category = ltpda_lincom('Category') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function varargout = ltpda_lincom(varargin) 0002 % LTPDA_LINCOM make the linear combination of the input analysis objects. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: LTPDA_LINCOM make the linear combination of the 0007 % input analysis objects. 0008 % 0009 % CALL: b = lincom(a1,a2,a3,...,pl) 0010 % b = lincom(a1,a2,a3,...,aN) 0011 % 0012 % If no parameter list is specified, one of the analysis objects 0013 % should contain a cdata type with the coefficients inside. 0014 % 0015 % INPUTS: aN - a list of analysis objects of the same type 0016 % pl - a parameter list 0017 % 0018 % OUTPUTS: b - output analysis object 0019 % 0020 % If the last input argument is a parameter list (plist) it is used. 0021 % The following parameters are recognised. 0022 % 0023 % PARAMETERS: 'coeffs' - vector of coefficients, same length as number of input AOs 0024 % 0025 % VERSION: $Id: ltpda_lincom.html,v 1.14 2008/03/31 10:27:43 hewitson Exp $ 0026 % 0027 % HISTORY: 14-02-07 M Hewitson 0028 % Creation. 0029 % 0030 % The following call returns a parameter list object that contains the 0031 % default parameter values: 0032 % 0033 % >> pl = ltpda_lincom('Params') 0034 % 0035 % The following call returns a string that contains the routine CVS version: 0036 % 0037 % >> version = ltpda_lincom('Version') 0038 % 0039 % The following call returns a string that contains the routine category: 0040 % 0041 % >> category = ltpda_lincom('Category') 0042 % 0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0044 0045 ALGONAME = mfilename; 0046 VERSION = '$Id: ltpda_lincom.html,v 1.14 2008/03/31 10:27:43 hewitson Exp $'; 0047 CATEGORY = 'Signal Processing'; 0048 0049 %% Check if this is a call for parameters, the CVS version string 0050 % or the function category 0051 if nargin == 1 && ischar(varargin{1}) 0052 in = char(varargin{1}); 0053 if strcmp(in, 'Params') 0054 varargout{1} = getDefaultPL(); 0055 return 0056 elseif strcmp(in, 'Version') 0057 varargout{1} = VERSION; 0058 return 0059 elseif strcmp(in, 'Category') 0060 varargout{1} = CATEGORY; 0061 return 0062 end 0063 end 0064 0065 % capture input variable names 0066 invars = {}; 0067 for j=1:nargin 0068 invars = [invars cellstr(inputname(j))]; 0069 end 0070 0071 % Initialise output 0072 b = []; 0073 ho = []; 0074 0075 %% Look at inputs 0076 0077 % check for plist and count 0078 % AOs with fsdata and tsdata 0079 pl = []; 0080 coeffs = []; 0081 na = 0; 0082 for j=1:nargin 0083 a = varargin{j}; 0084 if isa(a, 'plist') 0085 pl = a; 0086 end 0087 end 0088 % if a cdata is supplied, use 0089 % this instead of a plist 0090 as = []; 0091 for j=1:nargin 0092 a = varargin{j}; 0093 for k=1:length(a) 0094 ak = a(k); 0095 if isa(ak, 'ao') 0096 d = ak.data; 0097 % is this a constant data 0098 if isa(d, 'cdata') 0099 coeffs = d.y; 0100 % add history of this AO 0101 ho = [ho ak.hist]; 0102 % % Add coefficients to plist for history purposes 0103 % pl = plist(param('coeffs', coeffs)); 0104 elseif isa(d, 'tsdata') 0105 as = [as ak]; 0106 end 0107 end 0108 end 0109 end 0110 0111 % If a plist is supplied and no cdata, use plist 0112 if ~isempty(pl) && isempty(coeffs) 0113 coeffs = find(pl, 'coeffs'); 0114 end 0115 0116 na = length(as); 0117 nc = length(coeffs); 0118 0119 if na < 2 0120 error('### at least two analysis objects are needed to form a linear combination.'); 0121 end 0122 0123 if na ~= nc 0124 disp(sprintf('Num AOs input: %d', na)); 0125 disp(sprintf('Num Coeffs input: %d', nc)); 0126 error('### specify one coefficient per analysis object.'); 0127 end 0128 0129 % loop over all inputs AOs 0130 nameStr = []; 0131 y = 0; 0132 for j=1:na 0133 0134 % get this data 0135 aa = as(j); 0136 da = aa.data; 0137 dainfo = whos('da'); 0138 % store the first AO data type to 0139 % check against the others 0140 if j==1 0141 d = da; 0142 dinfo = whos('d'); 0143 end 0144 % check we know what type of data this is 0145 if isa(da, 'tsdata') || isa(da, 'fsdata') 0146 ya = da.y; 0147 else 0148 error('### unknown data type.'); 0149 end 0150 0151 % check against first AO data 0152 if ~strcmp(dainfo.class, dinfo.class) 0153 error('### all analysis objects should have the same data type.'); 0154 end 0155 0156 % All time-series vectors should be the same sample rate 0157 if isa(d, 'tsdata') 0158 if da.fs ~= d.fs 0159 error('### all analysis objects should contain same sample rate data.'); 0160 end 0161 end 0162 0163 % All vectors need to be the same length 0164 if y~=0 0165 if length(y) ~= length(ya) 0166 error('### all vectors should be the same length.'); 0167 end 0168 end 0169 % get the appropriate coefficient and add to linear combination 0170 c = coeffs(j); 0171 y = y + c.*ya; 0172 % add name to output str 0173 if j<=length(invars) 0174 if isempty(invars{j}) 0175 n = aa.name; 0176 else 0177 n = invars{j}; 0178 end 0179 else 0180 n = aa.name; 0181 end 0182 nameStr = [nameStr '+' num2str(c) sprintf('*%s', n)]; 0183 0184 % add history of this AO 0185 ho = [ho aa.hist]; 0186 end 0187 0188 % clean up nameStr 0189 if nameStr(1) == '+' 0190 nameStr = nameStr(2:end); 0191 end 0192 0193 % Make output analysis object 0194 0195 % create new output data 0196 if isa(d, 'tsdata') 0197 data = tsdata(d.x, y); 0198 data = set(data, 'name', nameStr); 0199 elseif isa(d, 'fsdata') 0200 data = fsdata(d.x, y, d.fs); 0201 data = set(data, 'name', nameStr); 0202 else 0203 error('### unknown data type.'); 0204 end 0205 0206 % create new output history 0207 h = history(ALGONAME, VERSION, pl, ho); 0208 h = set(h, 'invars', invars); 0209 0210 % make output analysis object 0211 b = ao(data, h); 0212 0213 % set name 0214 b = set(b, 'name', nameStr); 0215 0216 varargout{1} = b; 0217 0218 %-------------------------------------------------------------------------- 0219 % Get default params 0220 function plo = getDefaultPL() 0221 0222 plo = plist(); 0223 0224 0225 % END