Home > classes > @ao > upsample.m

upsample

PURPOSE ^

UPSAMPLE overloads upsample function for AOs.

SYNOPSIS ^

function varargout = upsample(varargin)

DESCRIPTION ^

 UPSAMPLE overloads upsample function for AOs.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: UPSAMPLE overloads upsample function for AOs.

              A signal at sample rate fs is upsampled by inserting N-1 zeros between the
              input samples.

 CALL:        b = upsample(a, pl)

 Parameters: 'N'     - specify the desired upsample rate.
             'phase' - specify an initial phase in range [0, N-1].

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

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

 VERSION:     $Id: upsample.m,v 1.12 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 % UPSAMPLE overloads upsample function for AOs.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: UPSAMPLE overloads upsample function for AOs.
0005 %
0006 %              A signal at sample rate fs is upsampled by inserting N-1 zeros between the
0007 %              input samples.
0008 %
0009 % CALL:        b = upsample(a, pl)
0010 %
0011 % Parameters: 'N'     - specify the desired upsample rate.
0012 %             'phase' - specify an initial phase in range [0, N-1].
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> ao.getInfo('upsample')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> ao.getInfo('upsample', 'None')
0019 %
0020 % VERSION:     $Id: upsample.m,v 1.12 2008/09/05 11:05:29 ingo Exp $
0021 %
0022 % HISTORY: 19-03-07 M Hewitson
0023 %             Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = upsample(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 and plists
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   % Get output sample rate
0053   Nup = find(pl, 'N');
0054   if isempty(Nup)
0055     error('### Please give a plist with a parameter ''N''.');
0056   end
0057   % Get initial phase
0058   phase = find(pl, 'phase');
0059   if isempty(phase)
0060     phase = 0;
0061   end
0062 
0063   % Loop over AOs
0064   for j=1:numel(bs)
0065     if ~isa(bs(j).data, 'tsdata')
0066       warning('!!! Upsample only works on tsdata objects. Skipping AO %s', ao_invars{j});
0067       bs(j) = [];
0068     else
0069       % upsample y
0070       bs(j).setY(upsample(bs(j).data.y, floor(Nup), phase), 'internal');
0071       % Correct fs
0072       bs(j).setFs(floor(Nup)*bs(j).data.fs, 'internal');
0073       % Set name
0074       bs(j).setName(sprintf('upsample(%s)', ao_invars{j}), 'internal');
0075       % Add history
0076       bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0077     end
0078   end
0079 
0080   % Set outputs
0081   if nargout > 0
0082     varargout{1} = bs;
0083   end
0084 end
0085 
0086 %--------------------------------------------------------------------------
0087 % Get Info Object
0088 %--------------------------------------------------------------------------
0089 function ii = getInfo(varargin)
0090   if nargin == 1 && strcmpi(varargin{1}, 'None')
0091     sets = {};
0092     pl   = [];
0093   else
0094     sets = {'Default'};
0095     pl   = getDefaultPlist;
0096   end
0097   % Build info object
0098   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: upsample.m,v 1.12 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0099 end
0100 
0101 %--------------------------------------------------------------------------
0102 % Get Default Plist
0103 %--------------------------------------------------------------------------
0104 function pl_default = getDefaultPlist()
0105   pl_default = plist('N', 1, 'phase', 0);
0106 end
0107 % END
0108

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