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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: DECIMATE AOs containing time-series data.

 CALL:        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]

 VERSION:     $Id: decimate.m,v 1.6 2007/07/18 13:58:44 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = decimate(ao, 'Params')

 HISTORY: 14-05-07 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function bo = decimate(varargin)
0002 % DECIMATE AOs containing time-series data.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: DECIMATE AOs containing time-series data.
0007 %
0008 % CALL:        b = decimate(a, 4)     - decimate x4; offset is set to default of 0
0009 %              b = decimate(a, 2, 1)  - decimate x2 with 1 sample offset
0010 %              b = decimate(a, pl)    - use plist to get paramters
0011 %              b = decimate(a1, a2, pl) - decimate both a1 and a2; b is then a 2x1
0012 %                                   vector.
0013 %
0014 % PARAMETERS: 'factor'  - decimation factor
0015 %             'offset'  - sample offset for decimation [default: 0]
0016 %
0017 % VERSION:     $Id: decimate.m,v 1.6 2007/07/18 13:58:44 ingo Exp $
0018 %
0019 % The following call returns a parameter list object that contains the
0020 % default parameter values:
0021 %
0022 % >> pl = decimate(ao, 'Params')
0023 %
0024 % HISTORY: 14-05-07 M Hewitson
0025 %             Creation
0026 %
0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0028 
0029 %% Check if this is a call for parameters
0030 if nargin == 2
0031   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0032     in = char(varargin{2});
0033     if strcmp(in, 'Params')
0034       ao_out = getDefaultPL();
0035       return
0036     end
0037   end
0038 end
0039 
0040 %% capture input variable names
0041 invars = {};
0042 for j=1:nargin
0043   if isa(varargin{j}, 'ao')
0044     invars = [invars cellstr(inputname(j))];
0045   end
0046 end
0047 
0048 ALGONAME = mfilename;
0049 VERSION  = '$Id: decimate.m,v 1.6 2007/07/18 13:58:44 ingo Exp $';
0050 
0051 %% Get inputs
0052 as      = [];
0053 ps      = [];
0054 queries = [];
0055 for j=1:nargin
0056   if isa(varargin{j}, 'ao')
0057     as = [as varargin{j}];
0058   end
0059   if isa(varargin{j}, 'plist')
0060     ps = [ps varargin{j}];
0061   end
0062 end
0063 
0064 Na = length(as);
0065 if isempty(as)
0066   error('### Please input at least one AO.');
0067 end
0068 
0069 %% Combine plists
0070 if ~isempty(ps)
0071   pl = combine(ps);
0072 else
0073   pl = plist();
0074 end
0075 
0076 %% Get parameters from plist
0077 offset = find(pl, 'offset');
0078 factor = find(pl, 'factor');
0079 
0080 if rem(factor, floor(factor)) ~= 0
0081   warning('!!! Downsample factor should be an integer. Rounding. !!!');
0082   factor = round(factor);
0083 end
0084 
0085 if nargin-Na == 1
0086   if isnumeric(varargin{end})
0087     factor = varargin{end};
0088   end
0089 end
0090 if nargin-Na == 2
0091   if isnumeric(varargin{end-1})
0092     factor = varargin{end-1};
0093   end
0094   if isnumeric(varargin{end})
0095     offset = varargin{end};
0096   end
0097 end
0098 
0099 if isempty(factor)
0100   error('### Please specify a decimation factor either directly or in a plist.');
0101 end
0102 if isempty(offset)
0103   warning('!!! No offset specified; using default of 0 samples !!!');
0104   offset = 0;
0105 end
0106 
0107 %% Loop over input AOs
0108 bo = [];
0109 for j=1:Na
0110 
0111   a  = as(j);
0112   d  = a.data;
0113   t  = d.t;
0114   x  = d.x;
0115   fs = d.fs;
0116   if isa(d, 'tsdata')
0117     ss = 1+offset;
0118     samples = ss:factor:len(a);
0119     d = set(d, 't', t(samples));
0120     d = set(d, 'x', x(samples));
0121     d = set(d, 'fs', fs/factor);
0122   else
0123     error('### I can only decimate time-series AOs.');
0124   end
0125 
0126   %------- Make output AO
0127 
0128   % create new output history
0129   plo  = plist([param('factor', factor) param('offset', offset)]);
0130   h = history(ALGONAME, VERSION, plo, a.hist);
0131   h = set(h, 'invars', invars);
0132 
0133   % make output analysis object
0134   b = ao(d, h);
0135 
0136   % set name
0137   % name for this object
0138   if isempty(invars{j})
0139     n1 = a.name;
0140   else
0141     n1 = invars{j};
0142   end
0143   b = set(b, 'name', sprintf('decimate(%s)', n1));
0144 
0145   % Add to output array
0146   bo = [bo b];
0147 
0148 end
0149 
0150 %% Get default params
0151 function pl_default = getDefaultPL()
0152 
0153 disp('* creating default plist...');
0154   pl_default = plist([param('factor',  '')
0155                       param('offset',  0)]);
0156 disp('* done.');
0157 
0158 
0159 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003