0001 function bo = decimate(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 ALGONAME = mfilename;
0030 VERSION = '$Id: decimate.m,v 1.7 2007/11/02 12:26:24 ingo Exp $';
0031
0032
0033 if nargin == 2
0034 if isa(varargin{1}, 'ao') && ischar(varargin{2})
0035 in = char(varargin{2});
0036 if strcmp(in, 'Params')
0037 bo = getDefaultPL();
0038 return
0039 elseif strcmp(in, 'Version')
0040 bo = VERSION;
0041 return
0042 end
0043 end
0044 end
0045
0046
0047 invars = {};
0048 for j=1:nargin
0049 if isa(varargin{j}, 'ao')
0050 invars = [invars cellstr(inputname(j))];
0051 end
0052 end
0053
0054
0055 as = [];
0056 ps = [];
0057 queries = [];
0058 aos_in = 0;
0059 for j=1:nargin
0060 if isa(varargin{j}, 'ao')
0061 as = [as varargin{j}];
0062 aos_in = aos_in + 1;
0063 end
0064 if isa(varargin{j}, 'plist')
0065 ps = [ps varargin{j}];
0066 end
0067 end
0068
0069 Na = numel(as);
0070 if isempty(as)
0071 error('### Please input at least one AO.');
0072 end
0073
0074
0075 if ~isempty(ps)
0076 pl = combine(ps);
0077 else
0078 pl = plist();
0079 end
0080
0081
0082 offset = find(pl, 'offset');
0083 factor = find(pl, 'factor');
0084
0085 if rem(factor, floor(factor)) ~= 0
0086 warning('!!! Downsample factor should be an integer. Rounding. !!!');
0087 factor = round(factor);
0088 end
0089
0090 if nargin-aos_in == 1
0091 if isnumeric(varargin{end})
0092 factor = varargin{end};
0093 end
0094 end
0095 if nargin-aos_in == 2
0096 if isnumeric(varargin{end-1})
0097 factor = varargin{end-1};
0098 end
0099 if isnumeric(varargin{end})
0100 offset = varargin{end};
0101 end
0102 end
0103
0104 if isempty(factor)
0105 error('### Please specify a decimation factor either directly or in a plist.');
0106 end
0107 if isempty(offset)
0108 warning('!!! No offset specified; using default of 0 samples !!!');
0109 offset = 0;
0110 end
0111
0112
0113 bo = [];
0114 for j=1:Na
0115
0116 a = as(j);
0117 d = a.data;
0118 t = d.t;
0119 x = d.x;
0120 fs = d.fs;
0121 if isa(d, 'tsdata')
0122 ss = 1+offset;
0123 samples = ss:factor:len(a);
0124 d = set(d, 't', t(samples));
0125 d = set(d, 'x', x(samples));
0126 d = set(d, 'fs', fs/factor);
0127 else
0128 error('### I can only decimate time-series AOs.');
0129 end
0130
0131
0132
0133
0134 plo = plist([param('factor', factor) param('offset', offset)]);
0135 h = history(ALGONAME, VERSION, plo, a.hist);
0136 h = set(h, 'invars', invars);
0137
0138
0139 b = ao(d, h);
0140
0141
0142
0143 if j > length(invars)
0144 n1 = a.name;
0145 else
0146 n1 = invars{j};
0147 end
0148 b = setnh(b, 'name', sprintf('decimate(%s)', n1));
0149
0150
0151 bo = [bo b];
0152
0153 end
0154
0155
0156 bo = reshape(bo, size(as));
0157
0158
0159 function pl_default = getDefaultPL()
0160
0161 pl_default = plist([param('factor', '')
0162 param('offset', 0)]);
0163
0164
0165