Home > classes > @ao > smoother.m

smoother

PURPOSE ^

SMOOTHER smooths a given series of data points using the specified method.

SYNOPSIS ^

function varargout = smoother(varargin)

DESCRIPTION ^

 SMOOTHER smooths a given series of data points using the specified method.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SMOOTHER smooths a given series of data points using
              the specified method.

 CALL:        b = smoother(a, pl)

 PARAMETERS:  width  - the width of the smoothing filter [default: 20 samples]
              hc     - a cutoff to throw away outliers (0-1)  [default: 0.8]
              method - the smoothing method:
                       'median'  [default]
                       'mean', 'min', 'max', 'mode'

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('smoother')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('smoother', 'None')

 VERSION:     $Id: smoother.m,v 1.12 2008/09/05 11:05:29 ingo Exp $

 HISTORY:     02-03-08 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % SMOOTHER smooths a given series of data points using the specified method.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: SMOOTHER smooths a given series of data points using
0005 %              the specified method.
0006 %
0007 % CALL:        b = smoother(a, pl)
0008 %
0009 % PARAMETERS:  width  - the width of the smoothing filter [default: 20 samples]
0010 %              hc     - a cutoff to throw away outliers (0-1)  [default: 0.8]
0011 %              method - the smoothing method:
0012 %                       'median'  [default]
0013 %                       'mean', 'min', 'max', 'mode'
0014 %
0015 % M-FILE INFO: Get information about this methods by calling
0016 %              >> ao.getInfo('smoother')
0017 %
0018 %              Get information about a specified set-plist by calling:
0019 %              >> ao.getInfo('smoother', 'None')
0020 %
0021 % VERSION:     $Id: smoother.m,v 1.12 2008/09/05 11:05:29 ingo Exp $
0022 %
0023 % HISTORY:     02-03-08 M Hewitson
0024 %                 Creation
0025 %
0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0027 
0028 function varargout = smoother(varargin)
0029 
0030   % Check if this is a call for parameters
0031   if utils.helper.isinfocall(varargin{:})
0032     varargout{1} = getInfo(varargin{3});
0033     return
0034   end
0035 
0036   import utils.const.*
0037   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0038   
0039   % Collect input variable names
0040   in_names = cell(size(varargin));
0041   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0042 
0043   % Collect all AOs and plists
0044   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0045   [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0046 
0047   % Decide on a deep copy or a modify
0048   bs = copy(as, nargout);
0049 
0050   % combine plists
0051   pl = combine(pl, getDefaultPlist());
0052 
0053   % Get parameters from plist
0054   bw      = find(pl, 'width');
0055   hc      = find(pl, 'hc');
0056   method  = find(pl, 'method');
0057 
0058   % check the method
0059   if  ~strcmp(method, 'median') && ...
0060       ~strcmp(method, 'mean') && ...
0061       ~strcmp(method, 'min') && ...
0062       ~strcmp(method, 'max') && ...
0063       ~strcmp(method, 'mode')
0064     help(mfilename)
0065     error('### Unknown smoothing method');
0066   end
0067 
0068   % Loop over input AOs
0069   for j=1:length(bs)
0070     utils.helper.msg(msg.PROC1, 'smoothing %s', bs(j).name);
0071     if strcmp(method, 'median')
0072       bs(j).data.setY(ltpda_smoother(bs(j).data.getY, bw, hc, method), 'internal');
0073     else
0074       bs(j).data.setY(smooth(bs(j).data.getY, bw, hc, method), 'internal');
0075     end
0076     % Add history
0077     bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0078     % set name
0079     bs(j).setName(sprintf('smoother(%s)', ao_invars{j}), 'internal');
0080   end
0081 
0082   if nargout > 0
0083     varargout{1} = bs;
0084   end
0085 end
0086 
0087 %--------------------------------------------------------------------------
0088 % Get Info Object
0089 %--------------------------------------------------------------------------
0090 function ii = getInfo(varargin)
0091   if nargin == 1 && strcmpi(varargin{1}, 'None')
0092     sets = {};
0093     pl   = [];
0094   else
0095     sets = {'Default'};
0096     pl   = getDefaultPlist;
0097   end
0098   % Build info object
0099   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: smoother.m,v 1.12 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0100 end
0101 
0102 %--------------------------------------------------------------------------
0103 % Get Default Plist
0104 %--------------------------------------------------------------------------
0105 function pl = getDefaultPlist()
0106   pl = plist('width', 20, 'hc', 0.8, 'method', 'median');
0107 end
0108 
0109 %--------------------------------------------------------------------------
0110 % smooth data
0111 function ys = smooth(y, bw, hc, method)
0112   N = length(y);
0113   ys = zeros(size(y));
0114   for kk=1:N
0115     if mod(kk, 1000)==0
0116       disp(sprintf(' -- smoothed %06d samples', kk));
0117     end
0118     % Determine the interval we are looking in
0119     interval = kk-bw/2:kk+bw/2;
0120     interval(interval<=0)=1;
0121     interval(interval>N)=N;
0122     % calculate median value of interval
0123     % after throwing away outliers
0124     trial = sort(y(interval));
0125     b = round(hc*length(trial));
0126     eval(sprintf('ys(kk) = %s(trial(1:b));', method));
0127   end
0128 end
0129 % END
0130

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003