B-Spline Interpolation of Data with Regular Sampling

Philippe Thévenaz and Michael Unser
Swiss Federal Institute of Technology Lausanne, Switzerland
http://bigwww.epfl.ch/

The purpose of the five routines provided here is to illustrate a signal-processing approach to the interpolation of regularly-sampled data The relevant theory is explained in more details in the following two references:

[1]	M. Unser, A. Aldroubi and M. Eden,
	"B-Spline Signal Processing: Part I—Theory,"
	IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 821-833,
	February 1993. 
[2]	M. Unser, A. Aldroubi and M. Eden,
	"B-Spline Signal Processing: Part II—Efficient Design and Applications,"
	IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 834-848,
	February 1993.

Theory

Interpolation Coefficients

Given a set of samples s, the fundamental task of interpolation is to compute the following equation for any real, possibly non-integer value of x:

f[x] = (∑_(k = -∞)^∞) 
              (Subscript[c, [[k]]]) φ[x - k]

For a specific integer value j, it is also desired that the interpolated function f[j] takes the same value as the sample \(TraditionalForm\`s\_\(\([[\)\(j\)\(]]\)\)\) of the set of available samples we want to interpolate

(Subscript[s, [[j]]]) = f[
          j] = (∑_(k = -∞)^∞) 
                (Subscript[c, [[k]]]) φ[j - k]

We discourage the traditional approach one usually follows in order to satisfy this equation. Traditionally, one makes sure that two conditions are met. Firstly, set \(TraditionalForm\`c\_\(\([[\)\(k\)\(]]\)\) = 
        s\_\(\([[\)\(k\)\(]]\)\)\) for all k. Secondly, select a function φ that takes value 0 for all integer arguments, except at the origin where it must equal unity (for any non-integer arguments, φ is free to take any value it may like, although some choices are better than others). This would do the trick, and would be the classical approach to interpolation.

Now, B-splines have very attractive properties, which makes them very good candidates in the role of the function φ. Unfortunately, they don't have all the qualities in the world; in particular, they may take a non-zero value for integer arguments, and they may differ from unity at the origin. Thus, one must depart from traditional interpolation so as to use B-splines for interpolating data. Instead, one must determine the suitable set of coefficients \(TraditionalForm\`c\_\(\([[\)\(k\)\(]]\)\) ≠ 
          s\_\(\([[\)\(k\)\(]]\)\) = 
        f[k]\) such that \(TraditionalForm\`f[
          j] = ∑\(c\_\(\([[\)\(k\)\(]]\)\)\) φ[j - k]\) still holds true for any integer j. This time, setting \(TraditionalForm\`c\_\(\([[\)\(k\)\(]]\)\) = 
        s\_\(\([[\)\(k\)\(]]\)\)\) doesn't do the trick. We need instead some routine that produces a set of coefficients c out of a set of samples s. This is the role of the routine BSplineCoefficients[]. The core of this routine consists in a forward-backward recursive filter (for more details, see the references [1, 2]).

Border Conditions

So far, we have taken for granted that the number of samples s was infinite, same with the number of coefficients c. Obviously, the amount of RAM in your computer is only so much, which asks for a finite number of data. Reconciliation of these contradictory requirements is the object of the present section.

Let us suppose you have m samples at your disposal. Given only those samples you know of, if we find a way to predict (extrapolate) the value of any coefficient outside the range of your known data, then we are back to the first (infinite) formulation, without its associated cost. This is known as an implicit scheme. Extrapolating the samples s is less relevant than extrapolating the coefficients c, for the former do not explicitly appear in what we compute in practice, that is, \(TraditionalForm\`∑\(c\_\(\([[\)\(k\)\(]]\)\)\) φ[x - k]\).

There is no limit to the number of ways one may select to perform extrapolation. After all, any single one is but a wild guess, even though some are more informed than others. We advocate here an extrapolation scheme where coefficients are mirrored around their extremities, namely, around \(TraditionalForm\`c\_\(\([[\)\(1\)\(]]\)\)\) and around \(TraditionalForm\`c\_\(\([[\)\(m\)\(]]\)\)\). This double mirroring ensures that every coefficient \(TraditionalForm\`c\_\(\([[\)\(k\)\(]]\)\)\) takes a definite value, no matter how far k is from the interval [1, m]. Moreover, it imposes the same doubly-mirrored structure on the samples \(TraditionalForm\`s\_\(\([[\)\(k\)\(]]\)\)\), and also on the whole curve f[x] which now satisfies f[1 - x] = f[1 + x] and f[m - x] = f[m + x], ∀ x ∈ ℝ. An important benefit of this scheme is that there is no need to "invent" special values (e.g., zero); all extrapolated values are replicated from those of the known interval. Moreover, this scheme ensures that no discontinuities (or strong changes of value) of f[x] arise at the extremities of the known interval.

Implementation

We provide five routines. Since this count is rather low, we proceed by the way of function definitions rather than by the way of a full-blown Mathematica package. The drawback is that you have to pay attention to dependencies, and you need to ensure that the definitions are made in the same order as they are described here.

1. Border Conditions

Given an integer index value i, this routine returns an index lying in the range Interval[{k1,k2}]. The mapping satisfies mirror boundary conditions.

MirroredIndex[i_, k1_, k2_] := 
      Module[{m = k2 - k1 + 1, j}, 
If[m == 1, k1, 
          j = Mod[i - k1, 2  m - 2]; 
          k1 + If[j < m, j, 2  m - 2 - j]]]

2. Auxilliary Function

Given a strictly positive real argument x and a real exponent a, this routine returns x^a. If the argument is strictly negative, the value 0 is returned. When the argument is null, special rules apply.

OneSidedPower[x_, a_] := 
      If[a == 
          0, ((1 + Sign[x])/2), (((((x + Abs[x])/2)))^a)]

3. B-Spline

Given a real argument x and a positive or null integer parameter n called the B-spline degree, this routine evaluates the value of the B-spline.

BSpline[x_, n_] := 
      Module[{k}, (∑_(k = 0)^(n + 1))((((-1))^k)/(n!)) 
            Binomial[n + 1, k] 
            OneSidedPower[x - k + ((n + 1)/2), n]]

4. Interpolation Coefficients

Given a non-empty list s of real-valued data samples, and given a positive or null integer B-spline degree n, this routine returns a list of interpolation coefficients. The returned list has the same length than s and assumes double mirroring of the data.

BSplineCoefficients[s_, n_] := 
      If[(n == 0) || (n == 1), 
        Return[s], 
Module[{k, i, m = Length[s], x, p, 
            q = Quotient[n, 2], c, z}, 
p = 
            N[Roots[0 == (∑_(k = -q)^q) (x^k) BSpline[k, n], 
                x]]; 
p = 
            Sort[Table[p[[k, 2]], {k, 2  q}]]; 
p = 
            Take[p, -q]; 
c = 
            s (∏_(k = 1)^(Quotient[n, 2]))((((1 - (Subscript[p, [[k]]])))^2)/(-(Subscript[p, [[k]]]))); 
For[k = 1, 
            k ≤ q, k++, 
z = 
              (Subscript[p, [[k]]]); 
(Subscript[c, [[1]]]) = (((Subscript[c, [[1]]]) z + (Subscript[c, [[m]]]) (z^m) + (∑_(i = 2)^(m - 1))(Subscript[c, [[i]]]) ((z^i) + (z^(2  m - i))))/(z - (z^(2  m - 1)))); 
For[i = 2, i ≤ m, i++, 
              (Subscript[c, [[i]]]) += (Subscript[c, [[i - 1]]]) 
                  z]; 
(Subscript[c, [[m]]]) = ((-z ((Subscript[c, [[m]]]) + (Subscript[c, [[m - 1]]]) z))/(1 - (z^2))); 
For[
              i = m - 1, 1 ≤ i, i--, 
              (Subscript[c, [[i]]]) = 
                z ((Subscript[c, [[i + 1]]]) - 
                      (Subscript[c, [[i]]]))]]; 
Return[c]]]

5. Interpolation Evaluation

Given a real argument x, a non-empty list c of real-valued interpolation coefficients, and given its corresponding positive or null integer B-spline degree n, this routine evaluates the interpolated function s (out of which c has been computed) for the argument x. The interpolation scheme assumes that c can be extended by double-mirroring.

BSplineInterpolate[x_, c_, 
        n_] := 
Module[{k, i, m = Length[c], 
          s = 0}, 
i = ⌊x + 
                Mod[n + 1, 2]/2⌋ - 
            Quotient[n, 
              2]; 
(∑_(k = 0)^n) 
                (Subscript[c, [[MirroredIndex[i + k, 1, 
                  m]]]]) 
            BSpline[x - i - k, n]]

Examples

Choose an arbitrary signal

s = {1, 3, -1, 5, 7, 2, 4, 0, 6, 8}

Plot a graphical representation of the data we want to interpolate

g = 
      ListPlot[s, 
        DisplayFunction -> Identity]
Show[g, Prolog -> AbsolutePointSize[5], 
      DisplayFunction -> $DisplayFunction, 
      PlotRange -> {{0, 11}, {-2, 10}}]

Compute the B-spline interpolation coefficients for several B-spline degrees. Observe that s=c0=c1; also, observe that s≠cn for n > 1

c0 = BSplineCoefficients[s, 0]
c1 = BSplineCoefficients[s, 1]
c2 = BSplineCoefficients[s, 2]
c3 = BSplineCoefficients[s, 3]
c4 = BSplineCoefficients[s, 4]
c5 = BSplineCoefficients[s, 5]

Check that the interpolated functions reproduce the samples exactly, up to numerical inaccuracies

s0 = 
        Table[BSplineInterpolate[x, c0, 0], {x, 1, 
            Length[c0]}];
s1 = 
        Table[BSplineInterpolate[x, c1, 1], {x, 1, 
            Length[c1]}];
s2 = 
        Table[BSplineInterpolate[x, c2, 2], {x, 1, 
            Length[c2]}];
s3 = 
        Table[BSplineInterpolate[x, c3, 3], {x, 1, 
            Length[c3]}];
s4 = 
        Table[BSplineInterpolate[x, c4, 4], {x, 1, 
            Length[c4]}];
s5 = 
        Table[BSplineInterpolate[x, c5, 5], {x, 1, 
            Length[c5]}];
Sqrt[(s - s0) . (s - s0)/(s . 
            s)]
Sqrt[(s - s1) . (s - s1)/(s . 
            s)]
Sqrt[(s - s2) . (s - s2)/(s . 
            s)]
Sqrt[(s - s3) . (s - s3)/(s . 
            s)]
Sqrt[(s - s4) . (s - s4)/(s . 
            s)]
Sqrt[(s - s5) . (s - s5)/(s . s)]

Plot the interpolated functions of varying degrees, put them all on the same graph. Observe the symmetry around x = 1 and around x = m

h = 
        Table[c = 
            BSplineCoefficients[s, n]; {Plot[
              BSplineInterpolate[x, c, n], {x, 0, Length[c] + 1}, 
              DisplayFunction -> Identity], 
            ListPlot[s, DisplayFunction -> Identity]}, {n, 0, 
            5}];
Show[{g} ⋃ h, Prolog -> AbsolutePointSize[5], 
      PlotRange -> {{0, 11}, {-2, 10}}, Frame -> True, 
      FrameLabel -> {"", "", "Degree 0 to" 
            PaddedForm[5, 2], ""}, Axes -> None, 
      DisplayFunction -> $DisplayFunction]

Plot the interpolated functions of varying degrees, put them on different graphs (you can animate them, if you want)

Do[Show[h[[k]], Prolog -> AbsolutePointSize[5], 
        PlotRange -> {{0, 11}, {-2, 10}}, Frame -> True, 
        FrameLabel -> {"", "", "Degree =" 
              PaddedForm[k - 1, 2], ""}, Axes -> None, 
        DisplayFunction -> $DisplayFunction], {k, Length[h]}]

April 2000