0001 function bo = decimate(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 invars = {};
0020 for j=1:nargin
0021 if isa(varargin{j}, 'ao')
0022 invars = [invars cellstr(inputname(j))];
0023 end
0024 end
0025
0026 ALGONAME = mfilename;
0027 VERSION = '$Id: decimate.html,v 1.1 2007/06/08 14:15:02 hewitson Exp $';
0028
0029
0030 as = [];
0031 ps = [];
0032 queries = [];
0033 for j=1:nargin
0034 if isa(varargin{j}, 'ao')
0035 as = [as varargin{j}];
0036 end
0037 if isa(varargin{j}, 'plist')
0038 ps = [ps varargin{j}];
0039 end
0040 end
0041
0042 Na = length(as);
0043 if isempty(as)
0044 error('### Please input at least one AO.');
0045 end
0046
0047
0048 if ~isempty(ps)
0049 pl = combine(ps);
0050 else
0051 pl = plist();
0052 end
0053
0054
0055 offset = find(pl, 'offset');
0056 factor = find(pl, 'factor');
0057
0058
0059 if nargin-Na == 1
0060 if isnumeric(varargin{end})
0061 factor = varargin{end};
0062 end
0063 end
0064 if nargin-Na == 2
0065 if isnumeric(varargin{end-1})
0066 factor = varargin{end-1};
0067 end
0068 if isnumeric(varargin{end})
0069 offset = varargin{end};
0070 end
0071 end
0072
0073 if isempty(factor)
0074 error('### Please specify a decimation factor either directly or in a plist.');
0075 end
0076 if isempty(offset)
0077 warning('!!! No offset specified; using default of 0 samples !!!');
0078 offset = 0;
0079 end
0080
0081
0082 bo = [];
0083 for j=1:Na
0084
0085 a = as(j);
0086 d = a.data;
0087 t = d.t;
0088 x = d.x;
0089 if isa(d, 'tsdata')
0090 ss = 1+offset;
0091 samples = ss:factor:len(a);
0092 d = set(d, 't', t(samples));
0093 d = set(d, 'x', x(samples));
0094
0095 else
0096 error('### I can only decimate time-series AOs.');
0097 end
0098
0099
0100
0101
0102 plo = plist([param('factor', factor) param('offset', offset)]);
0103 h = history(ALGONAME, VERSION, plo, a.hist);
0104 h = set(h, 'invars', invars);
0105
0106
0107 b = ao(d, h);
0108
0109
0110
0111 if isempty(invars{j})
0112 n1 = a.name;
0113 else
0114 n1 = invars{j};
0115 end
0116 b = set(b, 'name', sprintf('decimate(%s)', n1));
0117
0118
0119 bo = [bo b];
0120
0121
0122
0123 end
0124