Home > classes > @ao > zeropad.m

zeropad

PURPOSE ^

ZEROPAD zero pads the input data series.

SYNOPSIS ^

function varargout = zeropad(varargin)

DESCRIPTION ^

 ZEROPAD zero pads the input data series.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: ZEROPAD zero pads the input data series.

 CALL:        b = zeropad(a, pl)

 PARAMETERS: 'Factor'  - Pad to <Factor> times the input data length
                         [default: 2]
           or
             'N'       - Pad with N zero samples

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

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

 VERSION:     $Id: zeropad.m,v 1.11 2008/09/05 11:15:19 ingo Exp $

 HISTORY:     25-04-08 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % ZEROPAD zero pads the input data series.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: ZEROPAD zero pads the input data series.
0005 %
0006 % CALL:        b = zeropad(a, pl)
0007 %
0008 % PARAMETERS: 'Factor'  - Pad to <Factor> times the input data length
0009 %                         [default: 2]
0010 %           or
0011 %             'N'       - Pad with N zero samples
0012 %
0013 % M-FILE INFO: Get information about this methods by calling
0014 %              >> ao.getInfo('zeropad')
0015 %
0016 %              Get information about a specified set-plist by calling:
0017 %              >> ao.getInfo('zeropad', 'None')
0018 %
0019 % VERSION:     $Id: zeropad.m,v 1.11 2008/09/05 11:15:19 ingo Exp $
0020 %
0021 % HISTORY:     25-04-08 M Hewitson
0022 %                 Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 function varargout = zeropad(varargin)
0027 
0028   % Check if this is a call for parameters
0029   if utils.helper.isinfocall(varargin{:})
0030     varargout{1} = getInfo(varargin{3});
0031     return
0032   end
0033 
0034   import utils.const.*
0035   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0036   
0037   % Collect input variable names
0038   in_names = cell(size(varargin));
0039   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0040 
0041   % Collect all AOs and plists
0042   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0043   pl              = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0044 
0045   %%% Decide on a deep copy or a modify
0046   bs = copy(as, nargout);
0047 
0048   % combine plists
0049   pl = combine(pl, getDefaultPlist());
0050 
0051   % Extract necessary parameters
0052   Factor = find(pl, 'Factor');
0053   N      = find(pl, 'N');
0054 
0055   if isempty(Factor) && isempty(N)
0056     error('### Specify either a padding Factor, or a number of samples.');
0057   end
0058 
0059   % Loop over input AOs
0060   for j=1:length(bs)
0061     if ~isa(bs(j).data, 'tsdata')
0062       warning('!!! Zero padding only works on time-series. Skipping AO %s', ao_invars{j});
0063       bs(j) = [];
0064     else
0065       % Check the time-series is evenly samples
0066       if ~isempty(bs(j).data.x)
0067         error('### Zero padding only makes sense on evenly sampled time-series. Resample first.');
0068       end
0069       if isempty(N)
0070         if Factor < 2
0071           error('### Padding factor must be >= 2')
0072         end
0073         bs(j).setY([bs(j).data.getY; repmat(zeros(size(bs(j).data.getY)), Factor-1, 1)], 'internal');
0074       else
0075         if N > 0
0076           bs(j).setY([bs(j).data.getY; zeros(N,1)], 'internal');
0077         else
0078           error('### Number of samples to pad must be > 0');
0079         end
0080       end
0081       % Set name
0082       bs(j).setName(sprintf('zeropad(%s)', ao_invars{j}), 'internal');
0083       % Correct Nsecs
0084       bs(j).data.fixNsecs;
0085       % Add history
0086       bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0087     end
0088   end
0089 
0090   % Set outputs
0091   if nargout > 0
0092     varargout{1} = bs;
0093   end
0094 end
0095 
0096 %--------------------------------------------------------------------------
0097 % Get Info Object
0098 %--------------------------------------------------------------------------
0099 function ii = getInfo(varargin)
0100   if nargin == 1 && strcmpi(varargin{1}, 'None')
0101     sets = {};
0102     pl   = [];
0103   else
0104     sets = {'Default'};
0105     pl   = getDefaultPlist;
0106   end
0107   % Build info object
0108   ii = minfo(mfilename, 'ao', '', utils.const.categories.op, '$Id: zeropad.m,v 1.11 2008/09/05 11:15:19 ingo Exp $', sets, pl);
0109 end
0110 
0111 %--------------------------------------------------------------------------
0112 % Get Default Plist
0113 %--------------------------------------------------------------------------
0114 function pl = getDefaultPlist()
0115   pl = plist('Factor', 2);
0116 end
0117 % END

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