Spline Toolbox | ![]() ![]() |
Smoothing
What if the data are noisy? For example, suppose that the given values are
Then you might prefer to approximate instead. For example, you might try the cubic smoothing spline, obtained by the command
This produces a figure like this:
Figure 2-4: Cubic Smoothing Spline to Noisy Data
If you don't like the level of smoothing done by csaps(x,y)
, you can change it by specifying the smoothing parameter, p
, as an optional third argument. Choose this number anywhere between 0 and 1. As p
changes from 0 to 1, the smoothing spline changes, correspondingly, from one extreme, the least squares straight-line approximation to the data, to the other extreme, the "natural" cubic spline interpolant to the data. Since csaps
returns the smoothing parameter actually used as an optional second output, you could now experiment, as follows:
[scs,p] = csaps(x,noisy); fnplt(scs), hold on fnplt(csaps(x,noisy,p/2),'--') fnplt(csaps(x,noisy,(1+p)/2),':'), plot(x,noisy,'o') legend('smoothing spline','more smoothed','less smoothed',... 'noisy data'), hold off
This produces the following picture.
Figure 2-5: Noisy Data More or Less Smoothed
At times, you might prefer simply to get the smoothest cubic spline sp
that is within a specified tolerance tol
of the given data in the sense that
This spline is provided by the command
![]() | Knot Choices | Least Squares | ![]() |