DELAY delays a time-series using various methods. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: DELAY delays a time-series using various methods. CALL: b = delay(a, pl) PARAMETERS: N - delay the time-series by N samples. [default: 0] Choose a 'method' for how the end of the time-series is handled: 'zero' - zero pad the time-series EXAMPLES: 1) Shift by 10 samples and zero pad the end of the time-series >> b = delay(a, plist('N', 10, 'method', 'zero')); M-FILE INFO: Get information about this methods by calling >> ao.getInfo('delay') Get information about a specified set-plist by calling: >> ao.getInfo('delay', 'None') VERSION: $Id: delay.m,v 1.12 2008/09/05 11:05:29 ingo Exp $ HISTORY: 08-04-08 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % DELAY delays a time-series using various methods. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: DELAY delays a time-series using various methods. 0005 % 0006 % CALL: b = delay(a, pl) 0007 % 0008 % 0009 % PARAMETERS: N - delay the time-series by N samples. [default: 0] 0010 % Choose a 'method' for how the end of the time-series 0011 % is handled: 0012 % 'zero' - zero pad the time-series 0013 % 0014 % EXAMPLES: 1) Shift by 10 samples and zero pad the end of the time-series 0015 % >> b = delay(a, plist('N', 10, 'method', 'zero')); 0016 % 0017 % M-FILE INFO: Get information about this methods by calling 0018 % >> ao.getInfo('delay') 0019 % 0020 % Get information about a specified set-plist by calling: 0021 % >> ao.getInfo('delay', 'None') 0022 % 0023 % VERSION: $Id: delay.m,v 1.12 2008/09/05 11:05:29 ingo Exp $ 0024 % 0025 % HISTORY: 08-04-08 M Hewitson 0026 % Creation 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 % TODO 0031 % 'extrap' - extrapolate the last N samples 0032 0033 function varargout = delay(varargin) 0034 0035 % Check if this is a call for parameters 0036 if utils.helper.isinfocall(varargin{:}) 0037 varargout{1} = getInfo(varargin{3}); 0038 return 0039 end 0040 0041 import utils.const.* 0042 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0043 0044 % Collect input variable names 0045 in_names = cell(size(varargin)); 0046 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0047 0048 % Collect all AOs 0049 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0050 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0051 0052 % Decide on a deep copy or a modify 0053 bs = copy(as, nargout); 0054 0055 % Combine plists 0056 pl = combine(pl, getDefaultPlist); 0057 0058 %----------- Get parameters 0059 0060 % 1: Sample shift 0061 N = find(pl, 'N'); 0062 method = find(pl, 'method'); 0063 0064 % Loop over AOs 0065 for j=1:numel(bs) 0066 if ~isa(bs(j).data, 'tsdata') 0067 warning('!!! Skipping object %s - it contains no tsdata.', ao_invars{j}); 0068 else 0069 % Which method to use 0070 switch method 0071 case 'zero' 0072 s = size(bs(j).data.y); 0073 if s(1) > s(2) 0074 bs(j).setY([zeros(N,1); bs(j).data.y(1:end-N)], 'internal'); 0075 else 0076 bs(j).setY([zeros(1,N) bs(j).data.y(1:end-N)], 'internal'); 0077 end 0078 otherwise 0079 error('### Unknown method for dealing with end of time-series.'); 0080 end 0081 % Add history 0082 bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist); 0083 % make output analysis object 0084 bs(j).setName(sprintf('delay(%s)', ao_invars{j}), 'internal'); 0085 end 0086 end 0087 0088 % Reshape the ouput to the same size of the input 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: delay.m,v 1.12 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('N', 0, ... 0114 'method', 'zero'); 0115 end 0116 0117