Code covered by the BSD License  

Highlights from
Robust interpolation

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 2.53 KB File ID: #28053
image thumbnail

Robust interpolation

by Don MacLeod

 

29 Jun 2010 (Updated 02 Jul 2010)

1D linear interpolation despite failures of monotonicity in x or y

| Watch this File

File Information
Description

[Yinterp warningflag] = robustinterp(Xdata, Ydata, targetX)
Linearly interpolates in columns of X and Y values with reversals or failures of strict monotonicity in x or y (e.g. noisy and/or quantized observations of ideally monotonic relationships).
Ydata and Xdata are column vectors or matrices of the same size. TargetX is a scalar target X value, or else a vector with a target value for each data column. Robustinterp operates on each column of the data independently, to find Y values, Yinterp, corresponding to the X value(s) given in targetX.
Equalities and reversals in Xdata or Ydata are accommodated by linearly interpolating in Ydata at all points where Xdata moves to, from or through equality with targetX. The locally interpolated Y values are then simply averaged. Yinterp is not constrained to be monotonic!
Xsorted and Ysorted are the data sorted in columns so X is nondecreasing.
Each Xdata column must include at least one value less than and at least one greater than targetX: otherwise Yinterp is NaN. The optional warning flag is set to 1 where targetX coincides with the minimum (row 1) or maximum (row 2) of Xdata, otherwise 0.
Example:
x = (0:.05:1)' ;
x = x + 0.2*rand(size(x)); % disrupt monotonicity for x
y = sqrt(x);
yn = y +0.2*randn(size(y)); % ...and for y
yi = robustinterp(x,yn, 0.6)

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
29 Jun 2010 Don MacLeod

Another approach giving generally similar results is to perform linear regression over a range of X just sufficient to include all the transitions. The regression approach can be more statistically efficient since it makes use of data for other X values besides the ones that immediately flank a transition. But is there a neat way to apply the regression approach to matrix data when the transitional range in X is different for different columns?

Please login to add a comment or rating.
Updates
01 Jul 2010

Fixed an error in size checking.

02 Jul 2010

Initially sorts the columns of Xdata andYdata so Xsorted is nondecreasing.

Tag Activity for this File
Tag Applied By Date/Time
interpolation Don MacLeod 29 Jun 2010 10:22:55
noise Don MacLeod 29 Jun 2010 10:22:55
quantization Don MacLeod 29 Jun 2010 10:22:55
statistics Don MacLeod 29 Jun 2010 10:22:55
regression Don MacLeod 29 Jun 2010 17:00:50
robust interpolation Marcelo Bessa 27 Sep 2010 10:07:50

Contact us at files@mathworks.com