If your data is noisy, you might want to fit it using a smoothing spline. Alternatively, you can use one of the smoothing methods described in Filtering and Smoothing Data.
The smoothing spline s is constructed for the specified smoothing parameter p and the specified weights wi. The smoothing spline minimizes
p ∑ i w i ( y i − s ( x i ) ) 2 + ( 1 − p ) ∫ ( d 2 s d x 2 ) 2 d x
If the weights are not specified, they are assumed to be 1 for all data points.
p is defined between 0 and 1. p = 0 produces a least-squares straight-line fit to the data, while p = 1 produces a cubic spline interpolant. If you do not specify the smoothing parameter, it is automatically selected in the “interesting range.” The interesting range of p is often near 1/(1+h 3 /6) where h is the average spacing of the data points, and the interesting range is typically much smaller than the allowed range [0,1] of the parameter p. Because smoothing splines have an associated smoothing parameter, you might consider these fits to be parametric in that sense. However, smoothing splines are also piecewise polynomials like cubic spline or shape-preserving interpolants and are considered a nonparametric fit type in this guide.
Note
The smoothing spline algorithm is based on the csaps function.
The nuclear reaction data from the file carbon12alpha.mat is shown here with three smoothing spline fits. The default smoothing parameter (p = 0.99) produces the smoothest curve. The cubic spline curve (p = 1) goes through all the data points, but is not quite as smooth. The third curve (p = 0.95) misses the data by a wide margin and illustrates how small the “interesting range” of p can be.