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.html,v 1.7 2008/01/22 20:43:15 hewitson 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 invars = {};
0047 as = [];
0048 ps = [];
0049 aos_in = 0;
0050
0051
0052
0053 for j=1:nargin
0054
0055 if isa(varargin{j}, 'ao')
0056 as = [as varargin{j}];
0057 aos_in = aos_in + 1;
0058
0059 ao_name = inputname(j);
0060 if isempty(ao_name)
0061 ao_name = 'no_ao_name';
0062 end
0063
0064
0065
0066 if numel(varargin{j}) == 1
0067 invars{end+1} = ao_name;
0068 else
0069 for ii=1:numel(varargin{j})
0070 [I,J] = ind2sub(size(varargin{j}),ii);
0071 invars{end+1} = sprintf('%s(%d,%d)', ao_name, I, J);
0072 end
0073 end
0074 end
0075 if isa(varargin{j}, 'plist')
0076 ps = [ps varargin{j}];
0077 end
0078 end
0079
0080 Na = numel(as);
0081 if isempty(as)
0082 error('### Please input at least one AO.');
0083 end
0084
0085
0086 if ~isempty(ps)
0087 pl = combine(ps);
0088 else
0089 pl = plist();
0090 end
0091
0092
0093 offset = find(pl, 'offset');
0094 factor = find(pl, 'factor');
0095
0096 if rem(factor, floor(factor)) ~= 0
0097 warning('!!! Downsample factor should be an integer. Rounding. !!!');
0098 factor = round(factor);
0099 end
0100
0101 if nargin-aos_in == 1
0102 if isnumeric(varargin{end})
0103 factor = varargin{end};
0104 end
0105 end
0106 if nargin-aos_in == 2
0107 if isnumeric(varargin{end-1})
0108 factor = varargin{end-1};
0109 end
0110 if isnumeric(varargin{end})
0111 offset = varargin{end};
0112 end
0113 end
0114
0115 if isempty(factor)
0116 error('### Please specify a decimation factor either directly or in a plist.');
0117 end
0118 if isempty(offset)
0119 warning('!!! No offset specified; using default of 0 samples !!!');
0120 offset = 0;
0121 end
0122
0123
0124 bo = [];
0125 for j=1:Na
0126
0127 a = as(j);
0128 d = a.data;
0129 x = d.x;
0130 y = d.y;
0131 fs = d.fs;
0132 if isa(d, 'tsdata')
0133 ss = 1+offset;
0134 samples = ss:factor:len(a);
0135 d = set(d, 'x', x(samples));
0136 d = set(d, 'y', y(samples));
0137 d = set(d, 'fs', fs/factor);
0138 else
0139 error('### I can only decimate time-series AOs.');
0140 end
0141
0142
0143
0144
0145 plo = plist([param('factor', factor) param('offset', offset)]);
0146 h = history(ALGONAME, VERSION, plo, a.hist);
0147 h = set(h, 'invars', invars);
0148
0149
0150 b = ao(d, h);
0151
0152
0153 b = setnh(b, 'name', sprintf('decimate(%s)', invars{j}));
0154
0155
0156 bo = [bo b];
0157
0158 end
0159
0160
0161 bo = reshape(bo, size(as));
0162
0163
0164 function pl_default = getDefaultPL()
0165
0166 pl_default = plist([param('factor', '')
0167 param('offset', 0)]);
0168
0169
0170