Skip to article frontmatterSkip to article content

Trigonometric interpolation

Up to this point, all of our global approximating functions have been polynomials. While they are versatile and easy to work with, they are not always the best choice.

Suppose we want to approximate a function ff that is periodic, with one period represented by the standard interval [1,1][-1,1]. Mathematically, periodicity means that f(x+2)=f(x)f(x+2)=f(x) for all real xx. We could use polynomials to interpolate or project ff. However, it seems more reasonable to replace polynomials by functions that are also periodic.

It turns out that trigonometric interpolation allows us to return to equally spaced nodes without any problems. We therefore define N=2n+1N=2n+1 equally spaced nodes inside the interval [1,1][-1,1] by

tk=2kN,k=n,,n. t_k = \frac{2k}{N}, \quad k=-n,\ldots,n.

The formulas in this section require some minor but important adjustments if NN is even instead. We have modified our standard indexing scheme here to make the symmetry within [1,1][-1,1] about x=0x=0 more transparent. Note that the endpoints ±1\pm 1 are not among the nodes.

As usual, we have sample values yn,,yny_{-n},\ldots,y_n, perhaps representing values of a function f(x)f(x) at the nodes. We also now assume that the sample values can be extended periodically forever in both directions, so that yk+mN=yky_{k+mN}=y_k for any integer mm.

9.5.1Cardinal functions

We can explicitly state the cardinal function basis for equispaced trigonometric interpolation. It starts with

τ(x)=2N(12+cosπx+cos2πx++cosnπx)=sin(Nπx/2)Nsin(πx/2).\tau(x) = \frac{2}{N} \left( \frac{1}{2} + \cos \pi x + \cos 2\pi x + \cdots + \cos n\pi x\right) = \frac{\sin(N\pi x/2)}{N\sin(\pi x/2)}.

You can directly check the following facts. (See Exercise 9.5.3.)

Because the functions τn,,τn\tau_{-n},\ldots,\tau_n form a cardinal basis, the coefficients of the interpolant are just the sampled function values, i.e., the interpolant of points (tk,yk)(t_k,y_k) is

p(x)=k=nnykτk(x).p(x) = \sum_{k=-n}^n y_k \tau_k(x).

The convergence of a trigonometric interpolant is spectral, i.e., exponential as a function of NN in the max-norm.

9.5.2Implementation

Function 9.5.1 is an implementation of trigonometric interpolation based on (9.5.4). The function accepts an NN-vector of equally spaced nodes. Although we have not given the formulas above, the case of even NN is included in the code.

9.5.3Fast Fourier transform

Although the cardinal form of the interpolant is useful and stable, there is a fundamental alternative. It begins with an equivalent complex form of the trigonometric interpolant (9.5.1),

p(x)=k=nnckeikπx. p(x) = \sum_{k=-n}^n c_k e^{ik\pi x}.

The connection is made through Euler’s formula,

eiθ=cos(θ)+isin(θ), e^{i\theta} = \cos(\theta) + i\sin(\theta),

and the resultant identities

cosθ=eiθ+eiθ2,sinθ=eiθeiθ2i. \cos \theta = \frac{e^{i \theta}+e^{-i\theta}}{2}, \qquad \sin \theta = \frac{e^{i \theta}-e^{-i\theta}}{2i}.

Specifically, we have

ck={a02,k=0,12(ak+ibk),k>0,ck,k<0.c_k = \begin{cases} \frac{a_0}{2}, & k=0, \\[1mm] \frac{1}{2}(a_k + i b_k), & k> 0, \\[1mm] \overline{c_{-k}}, & k < 0. \end{cases}

While working with an all-real formulation seems natural when the data are real, the complex-valued version leads to more elegant formulas and is standard.

The N=2n+1N=2n+1 coefficients ckc_k are determined by interpolation nodes at the NN nodes within [1,1][-1,1]. By evaluating the complex exponential functions at these nodes, we get the N×NN\times N linear system

Fc=y,F=[eisπtr]r=n,,n,s=n,,n,\mathbf{F}\mathbf{c} = \mathbf{y}, \qquad \mathbf{F} = \bigl[ e^{\,is\pi t_r} \bigr]_{\, r=-n,\ldots,n,\, s=-n,\ldots,n,}

to be solved for the coefficients. Up to a scalar factor, the matrix F\mathbf{F} is unitary, which implies that the system can be solved in O(N2)O(N^2) operations simply by a matrix-vector multiplication.

However, one of the most important (though not entirely original) algorithmic observations of the 20th century was that the linear system can be solved in just O(NlogN)O(N\log N) operations by an algorithm now known as the fast Fourier transform, or FFT.

The FFTW package provides a function fft to perform this transform, but its conventions are a little different from ours. Instead of nodes in (1,1)(-1,1), it expects the nodes to be defined in [0,2)[0,2), and it returns the trig polynomial coefficients in the order

[c0,c1,cn,cn,c1].\begin{bmatrix} c_0, & c_1, & \cdots & c_n, & c_{-n}, & \cdots & c_{-1} \end{bmatrix}.

The theoretical and computational aspects of Fourier analysis are vast and far-reaching. We have given only the briefest of introductions.

9.5.4Exercises