DSMEAN performs a simple downsampling by taking the mean of every N samples. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: DSMEAN performs a simple downsampling by taking the mean of every N samples. The downsample factor (N) is taken as round(fs/fsout). The original vector is then truncated to a integer number of segments of length N. It is the reshaped to N x length(y)/N. Then the mean is taken. CALL: b = dsmean(a, pl) PARAMETERS: 'fsout' - The output sample rate [default: 10] M-FILE INFO: Get information about this methods by calling >> ao.getInfo('dsmean') Get information about a specified set-plist by calling: >> ao.getInfo('dsmean', 'None') VERSION: $Id: dsmean.m,v 1.9 2008/09/05 11:05:29 ingo Exp $ HISTORY: 20-04-08 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % DSMEAN performs a simple downsampling by taking the mean of every N samples. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: DSMEAN performs a simple downsampling by taking the mean of 0005 % every N samples. The downsample factor (N) is taken as 0006 % round(fs/fsout). The original vector is then truncated to a 0007 % integer number of segments of length N. It is the reshaped 0008 % to N x length(y)/N. Then the mean is taken. 0009 % 0010 % CALL: b = dsmean(a, pl) 0011 % 0012 % PARAMETERS: 'fsout' - The output sample rate [default: 10] 0013 % 0014 % M-FILE INFO: Get information about this methods by calling 0015 % >> ao.getInfo('dsmean') 0016 % 0017 % Get information about a specified set-plist by calling: 0018 % >> ao.getInfo('dsmean', 'None') 0019 % 0020 % VERSION: $Id: dsmean.m,v 1.9 2008/09/05 11:05:29 ingo Exp $ 0021 % 0022 % HISTORY: 20-04-08 M Hewitson 0023 % Creation 0024 % 0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0026 0027 function varargout = dsmean(varargin) 0028 0029 % Check if this is a call for parameters 0030 if utils.helper.isinfocall(varargin{:}) 0031 varargout{1} = getInfo(varargin{3}); 0032 return 0033 end 0034 0035 import utils.const.* 0036 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0037 0038 % Collect input variable names 0039 in_names = cell(size(varargin)); 0040 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0041 0042 % Collect all AOs 0043 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0044 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0045 0046 % Decide on a deep copy or a modify 0047 bs = copy(as, nargout); 0048 0049 % Combine plists 0050 pl = combine(pl, getDefaultPlist); 0051 0052 % Extract necessary parameters 0053 fsout = find(pl, 'fsout'); 0054 0055 % Loop over input AOs 0056 for j=1:length(bs) 0057 if ~isa(bs(j).data, 'tsdata') 0058 warning('!!! Can only downsample time-series (tsdata) objects. Skipping AO %s', ao_invars{j}); 0059 else 0060 % downsample factor 0061 dsf = round(bs(j).data.fs/fsout); 0062 if dsf < 1 0063 error('### I can''t downsample - the sample rate is already lower than the requested.'); 0064 end 0065 % Do Y data 0066 n = floor(length(bs(j).data.y) / dsf); 0067 y = bs(j).data.y(1:n*dsf); 0068 % reshape and take mean 0069 bs(j).data.setY(mean(reshape(y, dsf, length(y)/dsf))); 0070 0071 % If we have an x we should resample it 0072 if ~isempty(bs(j).data.x) 0073 x = bs(j).data.x(1:n*dsf); 0074 % reshape and take mean 0075 bs(j).data.setX(mean(reshape(x, dsf, length(x)/dsf))); 0076 else 0077 % otherwise we need to adjust t0 0078 bs(j).setT0(bs(j).data.t0 + dsf/(2*bs(j).data.fs), 'internal'); 0079 end 0080 % Build output AO 0081 bs(j).setFs(fsout, 'internal'); 0082 bs(j).setName(sprintf('dsmean(%s)', ao_invars{j}), 'internal'); 0083 % Add history 0084 bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist); 0085 end 0086 end 0087 0088 % Set outputs 0089 if nargout > 0 0090 varargout{1} = bs; 0091 end 0092 end 0093 0094 %-------------------------------------------------------------------------- 0095 % Get Info Object 0096 %-------------------------------------------------------------------------- 0097 function ii = getInfo(varargin) 0098 if nargin == 1 && strcmpi(varargin{1}, 'None') 0099 sets = {}; 0100 pl = []; 0101 else 0102 sets = {'Default'}; 0103 pl = getDefaultPlist; 0104 end 0105 % Build info object 0106 ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: dsmean.m,v 1.9 2008/09/05 11:05:29 ingo Exp $', sets, pl); 0107 end 0108 0109 %-------------------------------------------------------------------------- 0110 % Get Default Plist 0111 %-------------------------------------------------------------------------- 0112 function pl = getDefaultPlist() 0113 pl = plist('fsout', 10); 0114 end 0115 0116