Home > classes > @ao > decimate.m

decimate

PURPOSE ^

DECIMATE AOs containing time-series data.

SYNOPSIS ^

function bo = decimate(varargin)

DESCRIPTION ^

 DECIMATE AOs containing time-series data.
 
 Usage: b = decimate(a, 4)     - decimate x4; offset is set to default of 0
        b = decimate(a, 2, 1)  - decimate x2 with 1 sample offset
        b = decimate(a, pl)    - use plist to get paramters
        b = decimate(a1, a2, pl) - decimate both a1 and a2; b is then a 2x1
                                   vector.
 
 Parameters:
   'factor'  - decimation factor
   'offset'  - sample offset for decimation [default: 0]
 
 M Hewitson 14-05-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bo = decimate(varargin)
0002 
0003 % DECIMATE AOs containing time-series data.
0004 %
0005 % Usage: b = decimate(a, 4)     - decimate x4; offset is set to default of 0
0006 %        b = decimate(a, 2, 1)  - decimate x2 with 1 sample offset
0007 %        b = decimate(a, pl)    - use plist to get paramters
0008 %        b = decimate(a1, a2, pl) - decimate both a1 and a2; b is then a 2x1
0009 %                                   vector.
0010 %
0011 % Parameters:
0012 %   'factor'  - decimation factor
0013 %   'offset'  - sample offset for decimation [default: 0]
0014 %
0015 % M Hewitson 14-05-07
0016 %
0017 
0018 % capture input variable names
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 % Get inputs
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 % Combine plists
0048 if ~isempty(ps)
0049   pl = combine(ps);
0050 else
0051   pl = plist();
0052 end
0053 
0054 % Get parameters from plist
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 % Loop over input AOs
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   %------- Make output AO
0100   
0101   % create new output history
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   % make output analysis object
0107   b = ao(d, h);
0108 
0109   % set name
0110   % name for this object
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   % Add to output array
0119   bo = [bo b];
0120 
0121   
0122   
0123 end
0124 % END

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003