# [SciPy-User] Splines in scipy.signal vs scipy.interpolation

denis denis-bz-gg@t-online...
Tue Feb 9 10:46:48 CST 2010

```Tony, Dag Sverre,

let me try to give a bit of notation and background
(as far as I know -- experts please correct me):

- interpolating spline: goes through the data points
- smoothing spline: may not.

Say we have points or knots p0 p1 p2 ... labelled by integers,
and want piecewise cubic p(t) for real t.
NB the points can be in 1d 2d kd, and can be spaced any old way --
they can even overlap, p4 == p5.  Common are (j, yj) and (xj, yj).

Local splines are those for which p(t), 0 <= t <= 1,
depends only on the 4 nearest points p_1 p0 p1 p2.
If p(0) == p0 and p(1) == p1 we're interpolating, if not then not.
Local splines are very simple, and the only kind I use.
Global / least-squares-weighted splines
which depend or more points are common;
they're smoother (C2) but can surprise you  (see extrapolation
plot ...)
scipy.interpolate wraps fitpack which does least-squares weighting,
don't know how.

Of local splines, two kinds are common:
- interpolating: Catmull-Rom
- smoothing: B-spline.
These are defined by 4x4 "blending matrices", see the link below.
(By the way one can mix: (C-R matrix + Bspline matrix) / 2
gives curves between the two.)
For derivatives, any p(t) is cubic on intervals j <= t <= j+1
so one can just take dp(t)/dt (p_1 p0 p1 p2).

Given the many different kinds of splines,
the only way to find out what a given package does
(if its doc isn't clear)
is to plot its impulse response to ... 0 0 1 0 0 ...

Numpy code for local C-R and B-splines can be found at
C-R interpolates, Bspline smooths; no derivatives.
After setup, the p(t) are fast _dotblas.dot s, the higher "times" the
faster.

So after all that, a menu for splines:
- interpolating / smoothing
- local / various global
- work on Nxk reals / work on anything numpy
- 1d as above, 2d image processing
- derivatives
- Bezier curves with control points

And we have rather sad choices on doc.

Before jumping into "speed up ..." I'd like to hear from a few more
numpy/scipy users --
what do users want, do any want doc-first ?

Re timing, has anyone timed np.dot (_dotblas) vs cython vs straight C
say for n in (3, 10, 100, 1000) ?

cheers
-- denis

"Whenever something is a matter of taste, discussions can drag on
forever."
```