Home > classes > @ao > interp.m

interp

PURPOSE ^

INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list.

SYNOPSIS ^

function varargout = interp(varargin)

DESCRIPTION ^

 INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list.

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

 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
                   'cubic'   - shape-preserving piecewise cubic interpolation

 REMARK:      Matrix cdata objects are not supported.

 VERSION:     $Id: interp.m,v 1.11 2008/02/12 08:31:45 mauro Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = interp(ao, 'Params')

 The following call returns a string that contains the routine CVS version:

 >> version = interp(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = interp(ao,'Category')

 HISTORY: 05-06-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = interp(varargin)
0002 % INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: INTERP interpolate the values in the input AO(s) at new values
0007 %              specified by the input parameter list.
0008 %
0009 % CALL:        b = interp(a, pl)
0010 %
0011 % INPUTS:      a  - input array of AOs
0012 %              pl - parameter list with the keys 'vertices' and 'method'
0013 %
0014 % OUTPUTS:     b  - output array of AOs
0015 %
0016 % PARAMETERS:  'vertices'     - new set of vertices to interpolate on.
0017 %              'method'       - one of:
0018 %                   'nearest' - nearest neighbour
0019 %                   'linear'  - linear interpolation
0020 %                   'spline'  - spline interpolation
0021 %                   'cubic'   - shape-preserving piecewise cubic interpolation
0022 %
0023 % REMARK:      Matrix cdata objects are not supported.
0024 %
0025 % VERSION:     $Id: interp.m,v 1.11 2008/02/12 08:31:45 mauro Exp $
0026 %
0027 % The following call returns a parameter list object that contains the
0028 % default parameter values:
0029 %
0030 % >> pl = interp(ao, 'Params')
0031 %
0032 % The following call returns a string that contains the routine CVS version:
0033 %
0034 % >> version = interp(ao,'Version')
0035 %
0036 % The following call returns a string that contains the routine category:
0037 %
0038 % >> category = interp(ao,'Category')
0039 %
0040 % HISTORY: 05-06-07 M Hewitson
0041 %             Creation
0042 %
0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0044 
0045 ALGONAME = mfilename;
0046 VERSION  = '$Id: interp.m,v 1.11 2008/02/12 08:31:45 mauro Exp $';
0047 CATEGORY = 'Signal Processing';
0048 
0049 %% Check if this is a call for parameters
0050 if nargin == 2
0051   in = char(varargin{2});
0052   if strcmp(in, 'Params')
0053     varargout{1} = getDefaultPL();
0054     return
0055   elseif strcmp(in, 'Version')
0056     varargout{1} = VERSION;
0057     return
0058   elseif strcmp(in, 'Category')
0059     varargout{1} = CATEGORY;
0060     return
0061   end
0062 end
0063 
0064 % Collect input ao's, plist's and ao variable names
0065 in_names = {};
0066 for ii = 1:nargin
0067   in_names{end+1} = inputname(ii);
0068 end
0069 
0070 [as, ps, invars] = collect_inputs(varargin, in_names);
0071 
0072 % check plist
0073 if isempty(ps)
0074   pl = getDefaultPL();
0075 else
0076   pl = combine(ps, getDefaultPL);
0077 end
0078 
0079 
0080 % Get parameters
0081 vertices = find(pl, 'vertices');
0082 method  = find(pl, 'method');
0083 
0084 %-----------------------
0085 % Loop over input AOs
0086 bs = [];
0087 for j=1:numel(as)
0088 
0089   a = as(j);
0090 
0091   %----------------------------
0092   % Get data
0093   [x,y] = get_xy_values(a.data);
0094 
0095   %----------------------------
0096   % Interpolate this vector
0097   if ~isempty(x)
0098     % for tsdata, fsdata and xydata objects
0099     y = interp1(x,y,vertices, method, 'extrap');
0100   else
0101     % for cdata object
0102     y = interp1(y,vertices, method, 'extrap');
0103   end
0104 
0105   %----------------------------
0106   % Make output AO/cdata
0107   d = a.data;
0108 
0109   d = set_xy_axis(d, vertices, y.');
0110 
0111   d = set(d, 'name', sprintf('%s(%s)', method, d.name));
0112 
0113   h = history(ALGONAME, VERSION, pl, a.hist);
0114   h = set(h, 'invars', invars(j));
0115 
0116   % make output analysis object
0117   b = ao(d, h);
0118 
0119   % set name
0120   b = setnh(b, 'name', sprintf('%s(%s)', method, invars{j}));
0121 
0122   % add to outputs
0123   bs = [bs b];
0124 
0125 end
0126 
0127 % Reshape the ouput to the same size of the input
0128 bs = reshape(bs, size(as));
0129 
0130 % Set outputs
0131 varargout{1} = bs;
0132 
0133 %--------------------------------------------------------------------------
0134 % Get default params
0135 function plo = getDefaultPL()
0136 
0137 plo = plist();
0138 plo = append(plo, param('vertices', []));
0139 plo = append(plo, param('method', 'spline'));
0140 
0141 
0142 
0143 
0144 
0145 % END

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003