Home > m > math > ltpda_lincom.m

ltpda_lincom

PURPOSE ^

LTPDA_LINCOM make the linear combination of the input analysis objects.

SYNOPSIS ^

function varargout = ltpda_lincom(varargin)

DESCRIPTION ^

 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

              The following call returns a parameter list object that
              contains the default parameter values:

              >> pl = ltpda_lincom('Params')

 HISTORY:     14-02-07 M Hewitson
                 Creation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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 %              The following call returns a parameter list object that
0026 %              contains the default parameter values:
0027 %
0028 %              >> pl = ltpda_lincom('Params')
0029 %
0030 % HISTORY:     14-02-07 M Hewitson
0031 %                 Creation.
0032 %
0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0034 
0035 % Check if this is a call for parameters
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 % capture input variable names
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 % Initialise output
0054 b  = [];
0055 ho = [];
0056 %% Look at inputs
0057 
0058 % check for plist and count
0059 % AOs with fsdata and tsdata
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 % if a cdata is supplied, use
0070 % this instead of a plist
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       % is this a constant data
0079       if isa(d, 'cdata')
0080         coeffs = get(d, 'vals');
0081         % add history of this AO
0082         ho = [ho ak.hist];
0083 %         % Add coefficients to plist for history purposes
0084 %         pl = plist(param('coeffs', coeffs));
0085       elseif isa(d, 'tsdata')
0086         as = [as ak];
0087       end
0088     end
0089   end
0090 end
0091 
0092 % If a plist is supplied and no cdata, use plist
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 % loop over all inputs AOs
0111 nameStr = [];
0112 x = 0;
0113 for j=1:na
0114 
0115   % get this data
0116   aa = as(j);
0117   da = aa.data;
0118   dainfo = whos('da');
0119   % store the first AO data type to
0120   % check against the others
0121   if j==1
0122     d = da;
0123     dinfo = whos('d');
0124   end
0125   % check we know what type of data this is
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   % check against first AO data
0135   if ~strcmp(dainfo.class, dinfo.class)
0136     error('### all analysis objects should have the same data type.');
0137   end
0138 
0139   % All time-series vectors should be the same sample rate
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   % All vectors need to be the same length
0147   if x~=0
0148     if length(x) ~= length(xa)
0149       error('### all vectors should be the same length.');
0150     end
0151   end
0152   % get the appropriate coefficient and add to linear combination
0153   c = coeffs(j);
0154   x = x + c.*xa;
0155   % add name to output str
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   % add history of this AO
0168   ho = [ho aa.hist];
0169 end
0170 
0171 % clean up nameStr
0172 if nameStr(1) == '+'
0173   nameStr = nameStr(2:end);
0174 end
0175 
0176 % Make output analysis object
0177 
0178 % create new output data
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 % create new output history
0190 h = history(ALGONAME, VERSION, pl, ho);
0191 h = set(h, 'invars', invars);
0192 
0193 % make output analysis object
0194 b = ao(data, h);
0195 
0196 % set name
0197 b = set(b, 'name', nameStr);
0198 
0199 varargout{1} = b;
0200 
0201 %--------------------------------------------------------------------------
0202 % Get default params
0203 function plo = getDefaultPL()
0204 
0205 disp('* creating default plist...');
0206 plo = plist();
0207 disp('* done.');
0208 
0209 
0210 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003