Smoothing or interpolating spline of order 1 to 5

Directly to the input form

 
  • If your data are superimposed by noise, then it makes little sense to represent these data by an interpolating function. In this case some smoothing is necessary. Here we use a least squares approach for this.
  • A spline in the sense used here is a piecewise defined function, the pieces being polynomials of a fixed maximal order k. This order can be chosen here in the range 1 to 5. The spline is represented by a linear combination of so called B-splines (these are nonzero splines with minimal support using the constructed grid).
    S(x) = j=1m-k cj Bk,j(x) .

    Here m is the number of nodes in the grid. For k=1 these B-splines are the ''hat''-functions, for the grid -1,0,1 the function
    B1,0(x) = min(x+1,1-x) for x in [-1,1] and =0 otherwise.

    Higher order B-splines can be computed recursively from these. For more information on this see the book of Dierckx cited in the literature list.
  • The grid consists of the nodes x1, xn, the first and the last data abscissa, taken as k+1-fold nodes (this means that at these nodes there are no requirements whatsoever) and additional nodes in the interior of [x1, xn] chosen adaptively (either as one of the given data abscissa or as midpoints between such two), which are simple nodes with the requirement of continuity of the fit and its first k-1 derivatives. The criterion for this is
    i=1n (yi-S(xi))2 <= sqsum

    with sqsum as given input. Clearly sqsum=0 requires the interpolating spline, hence all data abscissa are in the grid then.
  • For sqsum > 0 and a given grid the spline is obtained by minimizing the sum of squares of the discontinuity jumps of the k-th derivative of S at the interior nodes tj, i.e.
    j=k+2m-k-1 ( S(k)(tj+0)-S(k)(tj-0))2
    in conjunction with the least squares sum of the data.
  • This method allows a good reconstruction of data subject to noise.
  • The numerical code behind this is netlib/dierckx/curfit.
 

Input

 
  • You can choose between input of your own set of (x,y)-data or the artificial generation of these data using a function on an interval and an error level for random error generation. For the function you can choose between 5 predefined ones or a function which you specify yourself. In the case of data of your own it is also required that you specify the upper bound for the sum of squares (sqsum) of the deviations yi-S(xi).
  • In the second case you experiment with data which are generated from the function of your choice. Here sqsum will be taken as sum of squares of the generated errors.
  • You specify the number of data points, which is restricted to 4 <= n<= 200 !.
  • In case of synthetic data you also specify the interval [a,b] from where the x-data are drawn. The xi are chosen equidistant in this case, but your own data need not be equidistant.
  • You fix the order of the spline k, named order in the input form, in the range 1 to 5. Even order and a small sqsum may result in trouble since interpolating splines of even order do not exist always.
  • Moreover you specify an error level for the error generation in this experiment. This is taken as relative error hence must be in [0,1]. For example level=0.05 means 5 percent error relative to the largest y value. The error is computed from
    level*max{|yi|}*(2*r-1)
    where r is an equidistributed pseudo random number in [0,1].
  • In both cases you might want to see the list of nodes t chosen and the coefficients c.
 

Output

 
  • In case of data of your own you get a plot of the data and the smoothing spline.
  • Otherwise you get a plot of the generated data and the smoothing spline and a text which indicates the chosen function, the number of data and the error level.
  • If required the data for the B-spline representation (nodes and coefficients)
 

Questions ?!

 
  • What takes place if the number of your data is quite small (e.g. 4) ?
  • How works the method near points of nonsmoothness of a function?
  • What takes place if you choose sqsum very large?
 

To the input form

 
 
Back to the top!

18.02.2015