INTERP interpolate the values in the input AO(s) at new values. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list. CALL: b = interp(a, pl) INPUTS: a - input array of AOs pl - parameter list with the keys 'vertices' and 'method' OUTPUTS: b - output array of AOs PARAMETERS: 'vertices' - new set of vertices to interpolate on. 'method' - one of: 'nearest' - nearest neighbour 'linear' - linear interpolation 'spline' - spline interpolation [default] 'cubic' - shape-preserving piecewise cubic interpolation REMARKs: 1) Matrix cdata objects are not supported. 2) If a time-series object is interpolated, the sample rate is adjusted to the best fit of the new data. M-FILE INFO: Get information about this methods by calling >> ao.getInfo('interp') Get information about a specified set-plist by calling: >> ao.getInfo('interp', 'None') VERSION: $Id: interp.m,v 1.24 2008/09/05 11:05:29 ingo Exp $ HISTORY: 05-06-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % INTERP interpolate the values in the input AO(s) at new values. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: INTERP interpolate the values in the input AO(s) at new values 0005 % specified by the input parameter list. 0006 % 0007 % CALL: b = interp(a, pl) 0008 % 0009 % INPUTS: a - input array of AOs 0010 % pl - parameter list with the keys 'vertices' and 'method' 0011 % 0012 % OUTPUTS: b - output array of AOs 0013 % 0014 % PARAMETERS: 'vertices' - new set of vertices to interpolate on. 0015 % 'method' - one of: 0016 % 'nearest' - nearest neighbour 0017 % 'linear' - linear interpolation 0018 % 'spline' - spline interpolation [default] 0019 % 'cubic' - shape-preserving piecewise cubic interpolation 0020 % 0021 % REMARKs: 1) Matrix cdata objects are not supported. 0022 % 2) If a time-series object is interpolated, the sample rate 0023 % is adjusted to the best fit of the new data. 0024 % 0025 % M-FILE INFO: Get information about this methods by calling 0026 % >> ao.getInfo('interp') 0027 % 0028 % Get information about a specified set-plist by calling: 0029 % >> ao.getInfo('interp', 'None') 0030 % 0031 % VERSION: $Id: interp.m,v 1.24 2008/09/05 11:05:29 ingo Exp $ 0032 % 0033 % HISTORY: 05-06-07 M Hewitson 0034 % Creation 0035 % 0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0037 0038 function varargout = interp(varargin) 0039 0040 % Check if this is a call for parameters 0041 if utils.helper.isinfocall(varargin{:}) 0042 varargout{1} = getInfo(varargin{3}); 0043 return 0044 end 0045 0046 import utils.const.* 0047 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0048 0049 % Collect input variable names 0050 in_names = cell(size(varargin)); 0051 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0052 0053 % Collect all AOs and plists 0054 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0055 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0056 0057 % Decide on a deep copy or a modify 0058 bs = copy(as, nargout); 0059 0060 % Combine plists 0061 pl = combine(pl, getDefaultPlist); 0062 0063 % Get parameters 0064 vertices = find(pl, 'vertices'); 0065 method = find(pl, 'method'); 0066 0067 %----------------------- 0068 % Loop over input AOs 0069 for j=1:numel(bs) 0070 %---------------------------- 0071 % Interpolate this vector 0072 if ~isa(bs(j).data, 'cdata') 0073 % for tsdata, fsdata and xydata objects 0074 bs(j).data.setXY(vertices, interp1(bs(j).data.getX,bs(j).data.getY,vertices, method, 'extrap')); 0075 else 0076 % for cdata object 0077 bs(j).data.setY(interp1(bs(j).data.y,vertices, method, 'extrap')); 0078 end 0079 0080 % Adjust sample rate for tsdata 0081 if isa(bs(j).data, 'tsdata') 0082 utils.helper.msg(msg.PROC1, 'adjusting sample rate of new data to best fit'); 0083 [fs, t0, fitted] = tsdata.fitfs(bs(j).data.getX); 0084 utils.helper.msg(msg.PROC2, 'got new sample rate of %g Hz', fs); 0085 bs(j).data.setFs(fs); 0086 if ~fitted 0087 bs(j).data.collapseX; 0088 end 0089 end 0090 % Add history 0091 bs(j).addHistory(getInfo, pl, ao_invars, bs(j).hist); 0092 % set name 0093 bs(j).setName(sprintf('%s(%s)', method, ao_invars{j}), 'internal'); 0094 end 0095 0096 % Set outputs 0097 if nargout > 0 0098 varargout{1} = bs; 0099 end 0100 end 0101 0102 %-------------------------------------------------------------------------- 0103 % Get Info Object 0104 %-------------------------------------------------------------------------- 0105 function ii = getInfo(varargin) 0106 if nargin == 1 && strcmpi(varargin{1}, 'None') 0107 sets = {}; 0108 pl = []; 0109 else 0110 sets = {'Default'}; 0111 pl = getDefaultPlist; 0112 end 0113 % Build info object 0114 ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: interp.m,v 1.24 2008/09/05 11:05:29 ingo Exp $', sets, pl); 0115 end 0116 0117 %-------------------------------------------------------------------------- 0118 % Get Default Plist 0119 %-------------------------------------------------------------------------- 0120 function pl_default = getDefaultPlist() 0121 pl_default = plist('vertices', [], 'method', 'spline'); 0122 end 0123