Home > classes > @ao > resample.m

resample

PURPOSE ^

RESAMPLE overloads resample function for AOs.

SYNOPSIS ^

function varargout = resample(varargin)

DESCRIPTION ^

 RESAMPLE overloads resample function for AOs.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: RESAMPLE overloads resample function for AOs.

 CALL:        b = resample(a, pl)

 Parameters: 'fsout' - specify the desired output sample rate

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

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

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

 HISTORY:     19-03-07 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % RESAMPLE overloads resample function for AOs.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: RESAMPLE overloads resample function for AOs.
0005 %
0006 % CALL:        b = resample(a, pl)
0007 %
0008 % Parameters: 'fsout' - specify the desired output sample rate
0009 %
0010 % M-FILE INFO: Get information about this methods by calling
0011 %              >> ao.getInfo('resample')
0012 %
0013 %              Get information about a specified set-plist by calling:
0014 %              >> ao.getInfo('resample', 'None')
0015 %
0016 % VERSION:     $Id: resample.m,v 1.30 2008/09/05 11:05:29 ingo Exp $
0017 %
0018 % HISTORY:     19-03-07 M Hewitson
0019 %                 Creation
0020 %
0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 
0023 function varargout = resample(varargin)
0024 
0025   % Check if this is a call for parameters
0026   if utils.helper.isinfocall(varargin{:})
0027     varargout{1} = getInfo(varargin{3});
0028     return
0029   end
0030 
0031   import utils.const.*
0032   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0033   
0034   % Collect input variable names
0035   in_names = cell(size(varargin));
0036   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0037 
0038   % Collect all AOs and plists
0039   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0040   pl              = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0041 
0042   % Decide on a deep copy or a modify
0043   bs = copy(as, nargout);
0044 
0045   % Combine plists
0046   pl = combine(pl, getDefaultPlist);
0047 
0048   if isempty(pl)
0049     error('### Please give a plist with a parameter ''fsout''.');
0050   end
0051 
0052   % Get output sample rate
0053   fsout = find(pl, 'fsout');
0054   if isempty(fsout)
0055     error('### Please give a plist with a parameter ''fsout''.');
0056   end
0057 
0058   % Get a filter if specified
0059   filt = find(pl, 'filter');
0060 
0061   % Loop over AOs
0062   for j=1:numel(bs)
0063     if ~isa(bs(j).data, 'tsdata')
0064       warning('!!! Skipping non-tsdata AO: %s', ao_invars{j});
0065       bs(j) = [];
0066     else
0067       % Compute the resampling factors
0068       [P,Q] = utils.math.intfact(fsout,bs(j).data.fs);
0069       utils.helper.msg(msg.PROC1, 'resampling by %g/%g', P, Q);
0070 
0071       % Check we have an evenly sampled data series
0072       [fs, t0, fitted] = tsdata.fitfs(bs(j).data.getX);
0073       if fitted
0074         error('### The AO %s is unevenly sampled. It can not be resampled this way.', ao_invars{j});
0075       end
0076       % resample y
0077       if isempty(filt)
0078         bs(j).setY(resample(bs(j).data.getY, P, Q), 'internal');
0079       else
0080         [p,q] = rat( fsout/d.fs, 1e-12 );
0081         b = p*filt.a;
0082         bs(j).setY(resample(bs(j).data.getY, P, Q, b), 'internal');
0083       end
0084       % Set new sample rate
0085       bs(j).setFs(fsout, 'internal');
0086       % Set output AO name
0087       bs(j).setName(sprintf('resample(%s)', ao_invars{j}), 'internal');
0088       % Add history
0089       bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0090     end
0091   end
0092 
0093   % Set output
0094   if nargout > 0
0095     varargout{1} = bs;
0096   end
0097 end
0098 
0099 %--------------------------------------------------------------------------
0100 % Get Info Object
0101 %--------------------------------------------------------------------------
0102 function ii = getInfo(varargin)
0103   if nargin == 1 && strcmpi(varargin{1}, 'None')
0104     sets = {};
0105     pl   = [];
0106   else
0107     sets = {'Default'};
0108     pl   = getDefaultPlist;
0109   end
0110   % Build info object
0111   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: resample.m,v 1.30 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0112 end
0113 
0114 %--------------------------------------------------------------------------
0115 % Get Default Plist
0116 %--------------------------------------------------------------------------
0117 function pl_default = getDefaultPlist()
0118   pl_default = plist('fsout', []);
0119 end
0120 % END
0121

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