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.15 2007/10/24 17:35:28 ingo 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
0030 if any(size(a) > 1)
0031 error('### The operation works only with single analysis objects. Do not use vector or matrices of analysis objects.')
0032 end
0033
0034 as = [as a];
0035 else
0036 if isnumeric(a)
0037
0038 as = [as ao(a)];
0039 else
0040 error('### AO/plus inputs must be either numeric or AO.');
0041 end
0042 end
0043 end
0044
0045 if length(as) > 2
0046 warning('!!! I only work with the first two input AOs. Ignoring all others.');
0047 warning('!!! Perhaps you have input an AO array?');
0048 end
0049
0050
0051 a1 = as(1);
0052 a2 = as(2);
0053 clear as;
0054 d1 = a1.data;
0055 d2 = a2.data;
0056
0057
0058
0059 if (isa(d1, 'fsdata') && isa(d2, 'tsdata')) || (isa(d1, 'tsdata') && isa(d2, 'fsdata'))
0060 error('### can''t add time-series data to frequency-series data.');
0061 end
0062 if (isa(d1, 'xydata') && isa(d2, 'tsdata')) || (isa(d1, 'tsdata') && isa(d2, 'xydata'))
0063 error('### can''t add XY data to time-series data.');
0064 end
0065 if (isa(d1, 'xydata') && isa(d2, 'fsdata')) || (isa(d1, 'fsdata') && isa(d2, 'xydata'))
0066 error('### can''t add XY data to frequency-series data.');
0067 end
0068
0069
0070 [x1, y1] = get_xy_values(a1.data);
0071 [x2, y2] = get_xy_values(a2.data);
0072 ny1 = length(y1);
0073 ny2 = length(y2);
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 if isa(d1, 'cdata') && ~isa(d2, 'cdata')
0086 if ny1 > 1 && ny1~=ny2
0087 error('###1 cdata type must be same length as other AO, or single valued.');
0088 end
0089 elseif isa(d2, 'cdata') && ~isa(d1, 'cdata')
0090 if ny2 > 1 && ny1~=ny2
0091 error('###2 cdata type must be same length as other AO, or single valued.');
0092 end
0093 end
0094
0095 if ny1~=ny2
0096 if ny1~=1 && ny2~=1
0097 error('### data vectors must be the same length or one should be single valued.');
0098 end
0099 end
0100
0101
0102 if isa(d1, 'fsdata') && isa(d2, 'fsdata')
0103 if ~strcmp(d1.xunits, d2.xunits)
0104 error('### xunits must be the same for same type of AOs.');
0105 end
0106
0107 if d1.f ~= d2.f
0108 error('### frequency vectors are not the same.');
0109 end
0110 end
0111 if isa(d1, 'tsdata') && isa(d2, 'tsdata')
0112 if ~strcmp(d1.xunits, d2.xunits)
0113 error('### xunits must be the same for same type of AOs.');
0114 end
0115 end
0116 if isa(d1, 'xydata') && isa(d2, 'xydata')
0117 if ~strcmp(d1.xunits, d2.xunits)
0118 error('### xunits must be the same for same type of AOs.');
0119 end
0120 end
0121
0122
0123 disp(sprintf('*** applying %s', op))
0124 eval(sprintf('x = y1%sy2;', op));
0125
0126
0127
0128 if isa(d1, 'fsdata') || isa(d2, 'fsdata')
0129
0130
0131
0132 if isa(d1, 'fsdata')
0133 d = d1;
0134 else
0135 d = d2;
0136 end
0137
0138 do = fsdata(d.f, x, d.fs);
0139 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0140 do = set(do, 'xunits', d.xunits);
0141 do = set(do, 'yunits', d.yunits);
0142 do = set(do, 'enbw', d.enbw);
0143
0144 elseif isa(d1, 'tsdata') || isa(d2, 'tsdata')
0145
0146
0147 if isa(d1, 'tsdata')
0148 d = d1;
0149 else
0150 d = d2;
0151 end
0152
0153 do = d;
0154 do = set(do, 'x', x);
0155 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0156
0157 elseif isa(d1, 'xydata') || isa(d2, 'xydata')
0158
0159
0160 if isa(d1, 'xydata')
0161 d = d1;
0162 else
0163 d = d2;
0164 end
0165
0166 do = xydata(d.x, x);
0167 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0168 do = set(do, 'xunits', d.xunits);
0169 do = set(do, 'yunits', d.yunits);
0170
0171 elseif isa(d1, 'cdata') || isa(d2, 'cdata')
0172
0173
0174
0175 if isa(d1, 'cdata')
0176 d = d1;
0177 else
0178 d = d2;
0179 end
0180
0181 do = cdata(x);
0182 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0183 do = set(do, 'xunits', d.xunits);
0184 do = set(do, 'yunits', d.yunits);
0185
0186 else
0187 error('### unknown data type - 2');
0188 end
0189
0190
0191