Home > classes > @ao > complex.m

complex

PURPOSE ^

COMPLEX overloads the complex operator for Analysis objects.

SYNOPSIS ^

function varargout = complex(varargin)

DESCRIPTION ^

 COMPLEX overloads the complex operator for Analysis objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: COMPLEX overloads the complex operator for Analysis objects.
              A3 = COMPLEX(A1,A2) returns the complex result A1 + A2i,
              where A1 and A2 are identically sized real arrays.

 CALL:        ao_out = complex(a1, a2);

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('complex')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('complex', 'None')

 VERSION:     $Id: complex.m,v 1.16 2008/08/15 11:45:18 ingo Exp $

 HISTORY:     20-08-2007 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % COMPLEX overloads the complex operator for Analysis objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: COMPLEX overloads the complex operator for Analysis objects.
0005 %              A3 = COMPLEX(A1,A2) returns the complex result A1 + A2i,
0006 %              where A1 and A2 are identically sized real arrays.
0007 %
0008 % CALL:        ao_out = complex(a1, a2);
0009 %
0010 % M-FILE INFO: Get information about this methods by calling
0011 %              >> ao.getInfo('complex')
0012 %
0013 %              Get information about a specified set-plist by calling:
0014 %              >> ao.getInfo('complex', 'None')
0015 %
0016 % VERSION:     $Id: complex.m,v 1.16 2008/08/15 11:45:18 ingo Exp $
0017 %
0018 % HISTORY:     20-08-2007 Diepholz
0019 %                 Creation
0020 %
0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 
0023 function varargout = complex(varargin)
0024 
0025   % Check if this is a call for parameters
0026   if utils.helper.isinfocall(varargin{:})
0027     varargout{1} = getInfo(varargin{3});
0028     return
0029   end
0030 
0031   import utils.const.*
0032   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0033   
0034   % Collect input variable names
0035   in_names = cell(size(varargin));
0036   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0037 
0038   % Collect all AOs and plists
0039   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0040 
0041   % Decide on a deep copy or a modify
0042   bs = copy(as, nargout);
0043 
0044   % Check input arguments number
0045   if length(bs) ~= 2
0046     error ('### Incorrect inputs. Please enter 2 AOs');
0047   end
0048 
0049   % Only support data2D or cdata for now
0050   if isa(bs(1).data, 'data3D') || isa(bs(2).data, 'data3D')
0051     error('### 3D data objects are currently not supported.');
0052   end
0053 
0054   % Check for the same data.
0055   if ~strcmp(class(bs(1).data), class(bs(2).data))
0056     error ('### The data class of the two AOs must be the same. (%s <-> %s)', ...
0057       class(bs(1).data), class(bs(2).data));
0058   end
0059 
0060   % Check for the same sampe rate
0061   fields = fieldnames(bs(1).data);
0062   if ismember('fs', fields)
0063     if bs(1).data.fs ~= bs(2).data.fs
0064       error('### The sample rate of the two AOs is not the same. Please resample one of them.');
0065     end
0066   end
0067 
0068   % Check the length of the AO's
0069   if length(bs(1).data.y) ~= length(bs(2).data.y) || length(bs(1).data.x) ~= length(bs(2).data.x)
0070     error ('### The length of the data vectors must be the same.')
0071   end
0072 
0073   % The x vector should be the same
0074   if ~isequal(bs(1).data.x, bs(2).data.x)
0075     error('### The two data series should have the same x values.');
0076   end
0077 
0078   % The time should be the same
0079   if ismember('t0', fields)
0080     if bs(1).data.t0.utc_epoch_milli ~= bs(2).data.t0.utc_epoch_milli
0081       error('### The two data series don''t start at the same time.');
0082     end
0083   end
0084 
0085   % The x units should match
0086   if ismember('xunits', fields)
0087     if bs(1).data.xunits ~= bs(2).data.xunits
0088       error('### The two data series should have the same x units');
0089     end
0090   end
0091 
0092   % Copy object 1 for the output
0093   bs(1).data.setY(complex(bs(1).data.y, bs(2).data.y));
0094   if ismember('yunits', fields)
0095     if bs(1).data.yunits ~= bs(2).data.yunits
0096       bs(1).data.setYunits(bs(1).data.yunits + bs(2).data.yunits*'i');
0097     end
0098   end
0099 
0100   % Add history
0101   bs(1).addHistory(getInfo, plist, ao_invars, [bs(1).hist bs(2).hist]);
0102 
0103   % Set name
0104   bs(1).setName(sprintf('complex(%s, %s)', ao_invars{1}, ao_invars{2}), 'internal');
0105 
0106   % Set output
0107   varargout{1} = bs(1);
0108 end
0109 
0110 %--------------------------------------------------------------------------
0111 % Get Info Object
0112 %--------------------------------------------------------------------------
0113 function ii = getInfo(varargin)
0114   if nargin == 1 && strcmpi(varargin{1}, 'None')
0115     sets = {};
0116     pl   = [];
0117   else
0118     sets = {'Default'};
0119     pl   = getDefaultPlist;
0120   end
0121   % Build info object
0122   ii = minfo(mfilename, 'ao', '', 'Operator', '$Id: complex.m,v 1.16 2008/08/15 11:45:18 ingo Exp $', sets, pl);
0123 end
0124 
0125 %--------------------------------------------------------------------------
0126 % Get Default Plist
0127 %--------------------------------------------------------------------------
0128 function pl = getDefaultPlist()
0129   pl = plist();
0130 end
0131

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003