Home > atmlab > math > interp360.m

interp360

PURPOSE ^

------------------------------------------------------------------------

SYNOPSIS ^

function yi = interp360(x,y,xi,varargin)

DESCRIPTION ^

------------------------------------------------------------------------
 NAME:    interp360

    Interpolation of data where y and y+360 are identical points. A typical
    application is interpolation of longitudes.
    
    Before the interpolation, the data points are shifted with n*360 in order
    to avoid jumps from 0 to 360 (or reversed). These jumps are identified
    by looking for abs(y(i+1)-y(i))>180. A caveat of the function is then
    that the input data must be suffiently dense that steps > 180 only
    occur when going between 0 and 360.

    An example (note that cubic interpolation works despite the step
    structure of y):
      x=0:1000; y=rem(x,360); xi=0.5:900;
      yi=interp1cyclic(x,y,xi,'cubic');
      plot(x,y,xi,yi,'.')

 FORMAT:  As for interp1, beside that y is only allowed to be a vector.
------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

interp360.m

SOURCE CODE ^

0001 %------------------------------------------------------------------------
0002 % NAME:    interp360
0003 %
0004 %    Interpolation of data where y and y+360 are identical points. A typical
0005 %    application is interpolation of longitudes.
0006 %
0007 %    Before the interpolation, the data points are shifted with n*360 in order
0008 %    to avoid jumps from 0 to 360 (or reversed). These jumps are identified
0009 %    by looking for abs(y(i+1)-y(i))>180. A caveat of the function is then
0010 %    that the input data must be suffiently dense that steps > 180 only
0011 %    occur when going between 0 and 360.
0012 %
0013 %    An example (note that cubic interpolation works despite the step
0014 %    structure of y):
0015 %      x=0:1000; y=rem(x,360); xi=0.5:900;
0016 %      yi=interp1cyclic(x,y,xi,'cubic');
0017 %      plot(x,y,xi,yi,'.')
0018 %
0019 % FORMAT:  As for interp1, beside that y is only allowed to be a vector.
0020 %------------------------------------------------------------------------
0021 
0022 % HISTORY: 20111-08-09  Created by Patrick Eriksson.
0023 
0024 
0025 function yi = interp360(x,y,xi,varargin)
0026 
0027 rqre_datatype( y, @isvector );
0028 
0029 ind = find( abs( diff( y ) ) > 180 );
0030 while ~isempty(ind)
0031   i = ind(1);
0032   if y(i+1) > y(i)
0033     y(i+1:end) = y(i+1:end) - 360; 
0034   else
0035     y(i+1:end) = y(i+1:end) + 360; 
0036   end
0037   ind = find( abs( diff( y ) ) > 180 );
0038 end
0039   
0040 
0041 yi = interp1( x, y, xi, varargin{:} );
0042 
0043 
0044 % Make sure all data are inside [0 and 360]
0045 n  = round( (yi-180)/360 );
0046 yi = yi - 360*n;
0047

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005