Function approximation: Fourier, Chebyshev, Lagrange

¾ Orthogonal functions ¾ ¾ Discrete Fourier Series ¾ Fourier Transform: properties ¾ ¾ Convolution ¾ DFT and FFT

Scope: Understanding where the Fourier Transform comes from. Moving from the continuous to the discrete world. The concepts are the for pseudospectral methods and the spectral element approach.

Orthogonal functions 1 Fourier Series: one way to derive them

The Problem

we are trying to approximate a function f(x) by another function gn (x) which consists of a sum over N orthogonal functions Φ(x) weighted by

some coefficients an .

N N ∑ Φ=≈ ii xaxgxf )()()( i=0

Orthogonal functions 2 The Problem

... and we are looking for optimal functions in a least squares (l2 ) sense ... b 2/1 ⎡ 2 ⎤ {}−=− )()()()( dxxgxfxgxf = !Min N 2 ⎢∫ N ⎥ ⎣a ⎦

... a good choice for the basis functions Φ(x) are orthogonal functions. What are orthogonal functions? Two functions f and g are said to be orthogonal in the interval [a,b] if

b ∫ dxxgxf = 0)()( a How is this related to the more conceivable concept of orthogonal vectors? Let us look at the original definition of :

Orthogonal functions 3 Orthogonal Functions

b ⎛ N ⎞ dxxgxf = ⎜ ii )()(lim)()( Δxxgxf ⎟ ∫ N ∞→ ∑ a ⎝ i=1 ⎠

... where x0 =a and xN =b, and xi-x i-1 =Δx ... If we interpret f(xi) and g(xi) as the ith components of an N component vector, then this sum corresponds directly to a scalar product of vectors. The vanishing of the scalar product is the condition for of vectors (or functions).

gfgf ==• 0 g ∑ iii i fi i i

Orthogonal functions 4 Periodic functions

Let us assume we have a piecewise continuous function of the form + π = xfxf )()2(

40 30 π )()2( ==+ xxfxf 2 20 10

0 -15 -10 -5 0 5 10 15 20

... we want to approximate this function with a linear combination of 2π periodic functions: xxxx nxnx )sin(),cos(),...,2sin(),2cos(),sin(),cos(,1 1 N N )()( 0 +=≈⇒ ∑{}k + k kxbkxaaxgxf )sin()cos( 2 k=1

Orthogonal functions 5 Orthogonality

... are these functions orthogonal ?

⎧ 0 ≠ kj π ⎪ ∫ )cos()cos( dxkxjx = ⎨ 2π kj == 0 − π ⎪ ⎩ π kj >= 0 ⎧ kjkj >≠ 0,,0 π ⎪ ∫ )sin()sin( dxkxjx = ⎨ − π ⎪ ⎩π kj >= 0 π ∫ dxkxjx = 0)sin()cos( kj >≥ 0,0 − π

... YES, and these relations are valid for any interval of length 2π. Now we know that this is an orthogonal basis, but how can we obtain the coefficients for the basis functions?

from minimising f(x)-g(x)

Orthogonal functions 6 Fourier coefficients

optimal functions g(x) are given if xfxg =− !Min)()( or ∂ { xfxg }=− 0)()( n 2 ∂a k n 2 ... with the definition of g(x) we get ...

2 ⎡ π N ⎤ ∂ 2 ∂ ⎡ 1 ⎤ n − xfxg )()( = ⎢ ⎢ 0 + ∑ {}k + k − )()sin()cos( ⎥ dxxfkxbkxaa ⎥ ∂a 2 ∂a ∫ 2 k k ⎣⎢ − π ⎣ k =1 ⎦ ⎦⎥

leading to 1 N N )( 0 += ∑ {}k + k kxbkxaaxg with)sin()cos( 2 k =1 1 π = dxkxxfa ,)cos()( k = ,...,1,0 N k ∫ π −π 1 π = dxkxxfb ,)sin()( k = ,...,2,1 N k ∫ π −π

Orthogonal functions 7 Fourier approximation of |x|

... Example ... = xxf ,)( x ≤≤− ππ

leads to the Fourier Serie

1 ⎧ x )cos(4 x )3cos( x )5cos( ⎫ xg )( π −= ⎨ + + + ... ⎬ 2 π ⎩ 1 2 3 2 5 2 ⎭

.. and for n<4 g(x) looks like

4 3

2 1

0 -20 -15 -10 -5 0 5 10

Orthogonal functions 8 Fourier approximation of x2

... another Example ... = xxf 2 x << 20,)( π

leads to the Fourier Serie

4π 2 N ⎧ 4 4π ⎫ xg )( kx )cos( kx )sin( N += ∑ ⎨ 2 − ⎬ 3 k =1 ⎩ k k ⎭

.. and for N<11, g(x) looks like

40

30

20

10

0

-10 -10 -5 0 5 10

Orthogonal functions 9 Fourier - discrete functions

... what happens if we know our function f(x) only at the points 2π x = i i N it turns out that in this particular case the coefficients are given by

2 N a * = kxxf ,)cos()( k = ,...2,1,0 k ∑ j j N j =1 2 N b * = kxxf ,)sin()( k = ,...3,2,1 k ∑ j j N j =1

.. the so-defined Fourier polynomial is the unique interpolating function to

the function f(xj) with N=2m

1 m −1 1 * )( * += {}* + * )sin()cos( + * kxakxbkxaaxg )cos( m 0 ∑ k k m 2 k =1 2

Orthogonal functions 10 Fourier - collocation points

... with the important property that ...

* im = xfxg i )()(

... in our previous examples ...

3.5

3

2.5

2

1.5

1

0.5

0 -10 -5 0 5

f(x)=|x| => f(x) - blue ; g(x) - red; xi -‘+’

Orthogonal functions 11 Fourier series - convergence

2 f(x)=x => f(x) - blue ; g(x) - red; xi -‘+’

Orthogonal functions 12 Fourier series - convergence

2 f(x)=x => f(x) - blue ; g(x) - red; xi -‘+’

Orthogonal functions 13 Gibb’s phenomenon

2 f(x)=x => f(x) - blue ; g(x) - red; xi -‘+’

N = 16 N = 32

6 6 6 4 4 4 2 2 2 0 0 0 -2 -2 -2 -4 -4 -4 -6 -6 -6 0 0.5 1 1.5 0 0.5 1 1.5 0 0.5 N = 128 N = 256

6 6 4 4 The overshoot for equi- 2 2 spaced Fourier 0 0 interpolations is ≈14% of -2 -2 the step height. -4 -4 -6 -6 0 0.5 1 1.5 0 0.5 1 1.5

Orthogonal functions 14 Chebyshev polynomials

We have seen that Fourier series are excellent for interpolating (and differentiating) periodic functions defined on a regularly spaced grid. In many circumstances physical phenomena which are not periodic (in space) and occur in a limited area. This quest leads to the use of Chebyshev polynomials.

We depart by observing that cos(nϕ) can be expressed by a polynomial in cos(ϕ):

ϕ = 2 ϕ − 1cos2)2cos( ϕ = 3 − cos3cos4)3cos( ϕϕ ϕ = 4 ϕ − 2 ϕ + 1cos8cos8)4cos(

... which leads us to the definition:

Orthogonal functions 15 Chebyshev polynomials - definition

ϕ = Tn n ϕ = n ),())(cos()cos( xxT = ϕ x ∈ − ],1,1[),cos( ∈ Nn

... for the Chebyshev polynomials Tn (x). Note that because of x=cos(ϕ) they are defined in the interval [-1,1] (which - however - can be extended to ℜ). The first polynomials are

0 xT =1)(

1 )( = xxT 2 2 xxT −= 12)( 3 3 −= 34)( xxxT 24 4 xxxT +−= 188)( where

n xT ≤ x −∈ and]1,1[for1)( ∈ Nn 0

Orthogonal functions 16 Chebyshev polynomials - Graphical

The first ten polynomials look like [0, -1]

1

0.5

0 T_n(x)

-0.5

-1 0 0.2 0.4 0.6 0.8 x

The n-th polynomial has extrema with values 1 or -1 at

kπ x ext )( = ),cos( k = ,...,3,2,1,0 n k n

Orthogonal functions 17 Chebyshev collocation points

These extrema are not equidistant (like the Fourier extrema)

k

x(k)

kπ x ext )( = ),cos( k = ,...,3,2,1,0 n k n

Orthogonal functions 18 Chebyshev polynomials - orthogonality

... are the Chebyshev polynomials orthogonal?

Chebyshev polynomials are an orthogonal set of functions in the interval [-1,1] with respect to the weight function 1/1 − x2 such that

⎧ 0 ≠ jkfor ⎫ 1 dx ⎪ ⎪ xTxT )()( = π 2/ jkfor >= 0 ,, ∈ Njk ∫ jk 2 ⎨ ⎬ 0 −1 1 − x ⎪ ⎪ ⎩ π jkfor == 0 ⎭

... this can be easily verified noting that x = ϕ,cos dx = −sinϕdϕ

k = ϕ j = jxTkxT ϕ)cos()(),cos()(

Orthogonal functions 19 Chebyshev polynomials - interpolation

... we are now faced with the same problem as with the Fourier series. We want to approximate a function f(x), this time not a periodical function but a function which is defined between [-1,1].

We are looking for gn (x)

1 n n )()( =≈ 00 + ∑ kk xTcxTcxgxf )()( 2 k =1 ... and we are faced with the problem, how we can determine the

coefficients ck. Again we obtain this by finding the extremum (minimum)

∂ ⎡ 1 dx ⎤ {}− xfxg )()( 2 = 0 ⎢∫ n 2 ⎥ ∂ck ⎣−1 1− x ⎦

Orthogonal functions 20 Chebyshev polynomials - interpolation

... to obtain ... 2 1 dx = xTxfc )()( k = ,...,2,1,0, n k ∫ k 2 π −1 1 − x

... surprisingly these coefficients can be calculated with FFT techniques, noting that 2 π = fc ϕϕϕkdk = ,...,2,1,0,cos)(cos n k ∫ π 0 ... and the fact that f(cosϕ) is a 2π-periodic function ... 1 π = fc ϕϕϕkdk = ,...,2,1,0,cos)(cos n k ∫ π −π

... which means that the coefficients ck are the Fourier coefficients ak of the periodic function F(ϕ)=f(cos ϕ)!

Orthogonal functions 21 Chebyshev - discrete functions

... what happens if we know our function f(x) only at the points π x = cos i i N in this particular case the coefficients are given by 2 N c * = f kϕϕ,)cos()(cos k = N 2/,...2,1,0 k ∑ j j N j =1 ... leading to the polynomial ...

1 m * )( * += * xTcTcxg )( m 0 0 ∑ kk 2 k =1

... with the property

* m = xfxg j = π = N0,1,2,...,jj/N)cos(xat)()(

Orthogonal functions 22 Chebyshev - collocation points - |x|

f(x)=|x| => f(x) - blue ; gn(x) - red; xi -‘+’

N = 8 1

0.8

0.6 8 points 0.4

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8

N = 16 1

0.8

0.6 16 points 0.4

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8

Orthogonal functions 23 Chebyshev - collocation points - |x|

f(x)=|x| => f(x) - blue ; gn(x) - red; xi -‘+’

N = 32 1

0.8

0.6 32 points 0.4

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8

N = 128 1

0.8

128 points 0.6 0.4

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.

Orthogonal functions 24 Chebyshev - collocation points - x2

2 f(x)=x => f(x) - blue ; gn(x) - red; xi -‘+’ N = 8 1.2

1

0.8

8 points 0.6

0.4

0.2 The interpolating

0 function gn(x) was -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 N = 64 shifted by a small 1.2 amount to be

1 visible at all!

0.8

0.6

64 points 0.4

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

Orthogonal functions 25 Chebyshev vs. Fourier - numerical

Chebyshev Fourier

N = 16 N = 1 35

0.8 30

25 0.6 20

15 0.4 10

0.2 5 0

0 -5 0 0.2 0.4 0.6 0.8 1 0 2

2 f(x)=x => f(x) - blue ; gN (x) - red; xi -‘+’

This graph speaks for itself ! Gibb’s phenomenon with Chebyshev?

Orthogonal functions 26 Chebyshev vs. Fourier - Gibb’s

Chebyshev Fourier

N = 16 N = 16 1.5 1.5

1 1

0.5 0.5

0 0

-0.5 -0.5

-1 -1

-1.5 -1.5 -1 -0.5 0 0.5 1 0 2

) f(x)=sign(x-π => f(x) - blue ; gN (x) - red; xi -‘+’

Gibb’s phenomenon with Chebyshev? YES!

Orthogonal functions 27 Chebyshev vs. Fourier - Gibb’s

Chebyshev Fourier

N = 64 N = 6 1.5 1.5

1 1

0.5 0.5

0 0

-0.5 -0.5

-1 -1

-1.5 -1.5 -1 -0.5 0 0.5 1 0 2 4

) f(x)=sign(x-π => f(x) - blue ; gN (x) - red; xi -‘+’

Orthogonal functions 28 Fourier vs. Chebyshev

Fourier Chebyshev

2π π x = i collocation points xi = cos i i N N

periodic functions domain limited area [-1,1]

xT = n ϕ ),cos()( nx nx )sin(),cos( basis functions n x = cos ϕ

* 1 * m m )( = axg 0 2 * 1 * * interpolating m )( 0 0 += kk xTcTcxg )( m −1 ∑ function 2 k =1 + {}* + * kxbkxa )sin()cos( ∑ k k k =1 1 + * kxa )cos( 2 m

Orthogonal functions 29 Fourier vs. Chebyshev (cont’d)

Fourier Chebyshev

N * 2 a = j kxxf j )cos()( N k ∑ * 2 N j =1 c = f kϕϕ)cos()(cos coefficients k N ∑ j j 2 N j =1 b * = kxxf )sin()( k ∑ j j N j =1

• Gibb’s phenomenon for • limited area calculations discontinuous functions some properties • grid densification at boundaries • Efficient calculation via FFT • coefficients via FFT • infinite domain through periodicity • excellent convergence at boundaries

• Gibb’s phenomenon

Orthogonal functions 30 The Fourier Transform Pair

∞ 1 Forward transform F ω)( = ∫ )( ωti dtetf 2π ∞− ∞ = ∫ )()( − ωti deFtf ωω Inverse transform ∞−

Note the conventions concerning the sign of the exponents and the factor.

Orthogonal functions 31 Some properties of the Fourier Transform

Defining as the FT: ⇒ Ftf ω)()(

¾ Linearity 1 + 2 ⇒ 1 ω + bFaFtbftaf 2 ω)()()()(

¾ Symmetry ⇒− πFtf −ω)(2)(

¾ Time shifting ⇒Δ+ ωΔti Fettf ω)()(

∂ n tf )( ¾ Time differentiation −⇒ n Fi ωω)()( ∂t n

Orthogonal functions 32 Differentiation theorem

∂ n tf )( ¾ Time differentiation −⇒ n Fi ωω)()( ∂t n

Orthogonal functions 33 Convolution

The convolution operation is at the heart of linear systems.

Definition:

∞ ∞ =∗ ∫ ∫ −=− dttgttfdtttgtftgtf ')'()'(')'()'()()( ∞− ∞−

Properties: ∗ = ∗ tftgtgtf )()()()(

∗∂ = tfttf )()()( =∗ ∫ )()()( dttftHtf

H(t) is the Heaviside function:

Orthogonal functions 34 The convolution theorem

A convolution in the time domain corresponds to a multiplication in the frequency domain.

… and vice versa …

a convolution in the frequency domain corresponds to a multiplication in the time domain

∗ ⇒ ω GFtgtf ω)()()()( ⇒ ω ∗GFtgtf ω)()()()(

The first relation is of tremendous practical implication!

Orthogonal functions 35 Summary

¾ The Fourier Transform can be derived from the problem of approximating an arbitrary function. ¾ A regular set of points allows exact interpolation (or derivation) of arbitrary functions ¾ There are other basis functions (e.g., Chebyshev polynomials, ) with similar properties ¾ These properties are the basis for the success of the spectral element method

Orthogonal functions 36