pchip

pchip(x,v,xq) returns interpolated data corresponding to the elements of xq and determined by Piecewise Cubic Hermite Interpolating Polynomial.
  • x: vector with sample points
  • v: evaluation of x
  • xq: coordenates of querying points

Examples

>> x = [1 5 8]
y = [5 2 10]
xq = 1:0.2:8
yq = pchip(x,y,xq)
op = struct('show', false)
overlay({plot(xq,yq,op), scatter(x,y,op)})
>> x = [1 5 8]
y = [5 2 10; 4 10 9] 

% y matrix

xq = 1:0.2:8 yq = pchip(x,y,xq) op = struct('show', false) overlay({plot(xq,yq,op), scatter(x,y,op)})

pchip vs. spline

Spline performs a piecewise polynomial interpolation using cubic splines. The interpolation provided by spline is smoother than that provided by pchip. This is due to the continuity of the second derivative in spline. In pchip, there can be jumps in the second derivative and, as a result, the interpolation provided is not as smooth. Pchip was originally designed so that never locally overshoots the data and this explains one of the advantages of this algorithm, its shape-preserving characteristic. The following graph compares the smoothness of spline versus the shape-preserving of pchip and the linear interpolation provided by interp1.

>> x = 1:6		
y = [16 18 21 11 15 12]
xq = 0:0.1:6

yq = spline(x,y,xq)
p = pchip(x,y,xq)
lin = interp1(x,y,xq)

op1 = struct('show', false); op1.markerStroke='black'
op2 = struct('show', false); op2.lineStroke='blue'
op3 = struct('show', false); op3.lineStroke='red'
op4 = struct('show', false); op4.lineStroke='black'; op4.dashArray = '4 4'
o = struct; o.showLegend = true; o.legendLabels = {'data', 'spline', 'pchip','linear'}

p1 = scatter(x,y,op1)
p2 = plot(xq,yq,op2)
p3 = plot(xq,p,op3)
p4 = plot(xq,lin,op4)
overlay({p1,p2,p3,p4},o)

References

[1] D. Kahaner, C. Moler, S. Nash, "Numerical Methods and Software", Prentice Hall, NJ, 1988.

See also

interp1 | interp2 | spline