0001 function [a1,a2,do] = aooperate(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010 ALGONAME = mfilename;
0011 VERSION = '$Id: aooperate.m,v 1.12 2007/06/12 06:17:27 hewitson Exp $';
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 op = varargin{end};
0022 varargin = varargin{1:end-1};
0023 nargin = length(varargin);
0024
0025 as = [];
0026 for j=1:nargin
0027 a = varargin{j};
0028 if isa(a, 'ao')
0029 as = [as a];
0030 else
0031 if isnumeric(a)
0032
0033 as = [as ao(a)];
0034 else
0035 error('### AO/plus inputs must be either numeric or AO.');
0036 end
0037 end
0038 end
0039
0040 if length(as) > 2
0041 warning('!!! I only work with the first two input AOs. Ignoring all others.');
0042 warning('!!! Perhaps you have input an AO array?');
0043 end
0044
0045
0046 a1 = as(1);
0047 a2 = as(2);
0048 clear as;
0049 d1 = a1.data;
0050 d2 = a2.data;
0051
0052 if (isa(d1, 'fsdata') && isa(d2, 'tsdata')) || (isa(d1, 'tsdata') && isa(d2, 'fsdata'))
0053 error('### can''t add time-series data to frequency-series data.');
0054 end
0055 if (isa(d1, 'xydata') && isa(d2, 'tsdata')) || (isa(d1, 'tsdata') && isa(d2, 'xydata'))
0056 error('### can''t add XY data to time-series data.');
0057 end
0058 if (isa(d1, 'xydata') && isa(d2, 'fsdata')) || (isa(d1, 'fsdata') && isa(d2, 'xydata'))
0059 error('### can''t add XY data to frequency-series data.');
0060 end
0061
0062
0063 x1 = getAOdata(a1);
0064 x2 = getAOdata(a2);
0065 nx1 = length(x1);
0066 nx2 = length(x2);
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 if isa(d1, 'cdata') && ~isa(d2, 'cdata')
0079 if nx1 > 1 && nx1~=nx2
0080 error('###1 cdata type must be same length as other AO, or single valued.');
0081 end
0082 elseif isa(d2, 'cdata') && ~isa(d1, 'cdata')
0083 if nx2 > 1 && nx1~=nx2
0084 error('###2 cdata type must be same length as other AO, or single valued.');
0085 end
0086 end
0087
0088 if nx1~=nx2
0089 if nx1~=1 && nx2~=1
0090 error('### data vectors must be the same length or one should be single valued.');
0091 end
0092 end
0093
0094
0095 if isa(d1, 'fsdata') && isa(d2, 'fsdata')
0096 if ~strcmp(d1.xunits, d2.xunits)
0097 error('### xunits must be the same for same type of AOs.');
0098 end
0099
0100 if d1.f ~= d2.f
0101 error('### frequency vectors are not the same.');
0102 end
0103 end
0104 if isa(d1, 'tsdata') && isa(d2, 'tsdata')
0105 if ~strcmp(d1.xunits, d2.xunits)
0106 error('### xunits must be the same for same type of AOs.');
0107 end
0108 end
0109 if isa(d1, 'xydata') && isa(d2, 'xydata')
0110 if ~strcmp(d1.xunits, d2.xunits)
0111 error('### xunits must be the same for same type of AOs.');
0112 end
0113 end
0114
0115
0116 disp(sprintf('*** applying %s', op))
0117 eval(sprintf('x = x1%sx2;', op));
0118
0119
0120
0121 if isa(d1, 'fsdata') || isa(d2, 'fsdata')
0122
0123
0124
0125 if isa(d1, 'fsdata')
0126 d = d1;
0127 else
0128 d = d2;
0129 end
0130
0131 do = fsdata(d.f, x, d.fs);
0132 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0133 do = set(do, 'xunits', d.xunits);
0134 do = set(do, 'yunits', d.yunits);
0135 do = set(do, 'enbw', d.enbw);
0136
0137 elseif isa(d1, 'tsdata') || isa(d2, 'tsdata')
0138
0139
0140 if isa(d1, 'tsdata')
0141 d = d1;
0142 else
0143 d = d2;
0144 end
0145
0146 do = d;
0147 do = set(do, 'x', x);
0148 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0149
0150 elseif isa(d1, 'xydata') || isa(d2, 'xydata')
0151
0152
0153 if isa(d1, 'xydata')
0154 d = d1;
0155 else
0156 d = d2;
0157 end
0158
0159 do = xydata(d.x, x);
0160 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0161 do = set(do, 'xunits', d.xunits);
0162 do = set(do, 'yunits', d.yunits);
0163
0164 elseif isa(d1, 'cdata') || isa(d2, 'cdata')
0165
0166
0167
0168 if isa(d1, 'cdata')
0169 d = d1;
0170 else
0171 d = d2;
0172 end
0173
0174 do = cdata(x);
0175 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0176 do = set(do, 'xunits', d.xunits);
0177 do = set(do, 'yunits', d.yunits);
0178
0179 else
0180 error('### unknown data type - 2');
0181 end
0182
0183
0184