Fourier Series and Interpolation

Fourier Series and Interpolation

Fourier Series

Any function f(x) (except for a few) can be expressed as infinite sums of (periodic) sine & cosine functions which converge to that function :

f(x) = Sn=0,¥ {an cos(nx) + bn sin(nx)} [1]

I.e.,


f(x) = a0 cos(0x) + b0 sin(0x) + a1 cos(1x) + b1 cos(1x) + a2 cos(2x) + b2 cos(2x) ... + an cos(nx) + bn sin(nx) , n ® ¥; [1']

The coefficients an & bn which accomplish this (all other variables are known) are :


a0 = 1/2p -p,p f(x) cos(0x) dx = 1/2p -p,p f(x) dx [2]
an = 1/
p -p,p f(x) cos(nx) dx , n = 1, 2,...,¥ [3]
bn = 1/
p -p,p f(x) sin(nx) dx , n = 1, 2,...,¥ [4]

Note that 1/2p = 1/(2p). No parenthesis in the denominator for such a combined quantity appears less cluttered. b0 in [1] is arbitrary because sin(0x) = 0. Thus [2], [3], & [4] express the relevant coefficients an & bn in [4]. This is defined only for the interval x = [-p,p].

Alternate form

Because 1/2p precedes the integral expressing a0 in [2] and 1/p precedes the integrals expressing the other coefficients in [3] & [4], the factor 1/2 is often moved to [1] in the a0 term. Thus [1] is often expressed as (noting that cos(0x) = 1) :

f(x) = a0/2 + Sn=1,¥ {an cos(nx) + bn sin(nx)} [5]

for which


an = 1/p -p,p f(x) cos(nx) dx , n = 0, 1, 2,...,¥ [6]
bn = 1/
p -p,p f(x) sin(nx) dx , n = 1, 2,...,¥ [7]

The sets of equations [5], [6], & [7] or [1], [2], [3], & [4] with b0 arbitrarily chosen are the Fourier series representation of a function f(x).

Variable interval

If an interval other than that of 2p is desired, a change of variables must be made. A substitution variable which converts the x interval [-p,p] to the desired interval is either used when solving the red or blue sets of equations, or placed directly in those equations as a general formula. These are equivalent, and the form above makes the characteristics of the series more clear, so I do the former in the example below.

Truncated series

Because Fourier series are infinite sums, you may hope that the terms become smaller as n
® ¥, such that a series truncated after several terms :

SN(x) = a0/2 + Sn=1,N {an cos(nx) + bn sin(nx)} [8]

may be reasonably accurate. This is indeed so, though this rate of convergence is generally not fast for non-curved and non-periodic functions.

Example

A simple though rather involved and good example is the Fourier series for the linear function f(x) = 3x for the interval x = 0 to 5 (see graph below). The substitution variable mentioned above is used in the
red equations. Calling this variable u,

u = p (2x/5 - 1) , so x = 5 (p + u)/2p

Thus,

f(u) = f(x) = 3 x = 3 (5 (p + u)/2p) = 15 (p + u)/2p

Note that u varies from -p to p as x does from 0 to 5, and f(u) varies from 0 to 15 on the interval (-p,p) as f(x) does on the interval (0,5), the required transformation.

The coefficients can then be calculated :

a0 = 1/2p -p,p f(u) cos(0u) du = 1/2p -p,p (15 (p + u)/2u) (1) du = 15/4p -p,p du + 15/4p2 -p,p u du
an = 1/
p -p,p f(u) cos(nu) du = 1/p -p,p (15 (p + u)/2p)) cos(nu) du = 15/2p -p,p cos(nu) du + 15/2p2 -p,p u cos(nu) du
bn = 1/
p -p,p f(u) sin(nu) du = 1/p -p,p (15 (p + u)/2p)) sin(nu) du = 15/2p -p,p sin(nu) du + 15/2p2 -p,p u sin(nu) du

The constant term a0 is :

a0 = 15/4p u½-p,p + 15/4p2 (u2/2)½-p,p = 15/4p (p - (-p)) + 15/8p2 (p2 - p2) = 15/2

Concerning other coefficients, solutions to the trigonometric integrals are :

-p,p cos(nu) du = sin(nu)/n½-p,p = 0
-
p,p sin(nu) du = - cos(nu)/n½-p,p = 0
-
p,p u cos(nu) du = {u sin(nu)/n + cos(nu)/n2}½-p,p = 0
-
p,p u sin(nu) du = {sin(nu)/n2 - u cos(nu)}/n½-p,p = - (-1)n (2p/n)

for which the (-1)n implies that the terms alternate signs for odd & even values of n (cos(np) is 1 if n is even & -1 if n is odd). Thus, the only non-zero coefficients if n > 0 are bn :

bn = - (15/2p2) (-1)n (2p/n) = -(-1)n (15/np)

Thus the coefficients are :

a0 = 15/2 an = 0 , n = 0, 1, 2,...,¥
bn = - (-1)n (15/n
p) , n = 0, 1, 2,...,¥

So that the Fourier series for f(u) is :

f(u) = 15/2 + Sn=1,¥ {0 cos(nu) - (-1)n (15/np) sin(nu)} = 15/2 - Sn=1,¥ (-1)n (15/np) sin(nu)

Calculating for f(x) on the interval 0 to 5 requires no more than substituting for u in the Fourier series :

f(x) = 15/2 - Sn=1,¥ (-1)n (15/np) sin(np (2x/5 - 1)) = 15/2 + (15/1p) sin(1p (2x/5 - 1)) - (15/2p) sin(2p (2x/5 - 1)) ...

Basic properties

A graph of the the truncated series SN(x) of the above example for N = 0-6 & 101 reveals several basic properties of Fourier series :


The constant term a0 (or a0/2 if
blue equations are used), which is S0(x), is 15/2 - the average of f(x) on the interval. Thus, a first approximation to the function is its average. Further terms create an oscillatory solution nearer f(x). This series converges quite slowly (O(1/n)) because a general combination of circular functions are solving for a straight (linear) function. Even 102 terms are insufficient for completely surpressing the endpoint problem. If f(x) were a curved function, convergence would be much better; and (of course) if f(x) were a trigonometric function, it would be calculated exactly as that function. A paradox for this example (and many others) is that although the solution approaches f(x) as n ® ¥, it can never be at the endpoints - it is always 15/2 there ! I suppose the reasoning is that the endpoints vanish as n ® ¥. These properties are certainly not exhaustive, but are the most important ones.

Symmetry

Note in the above example that all anterms are 0 for n > 0. This is because f(x) is an oddly symmetric function (see also relevant graph below) :


The bn sine terms are oddly symmetric; but the an cosine terms are evenly symmetric, thus contribute nothing to the solution. The statement is often made that if you know the symmetry of a function which interests you, you can keep only the relevant coefficients, multiply the equations calculating them with 2, and halve the calculation interval to
p :

Even symmetry - Fourier cosine series :


f(x) = Sn=0,¥ an cos(nx) [9]
a0 = 1/
p 0,p f(x) dx [10]
an = 2/
p 0,p f(x) cos(nx) dx , n = 1, 2,...,¥ [11]

Odd symmetry - Fourier sine series :


f(x) = a0 + Sn=0,¥ bn sin(nx) [12]
a0 = 1/
p 0,p f(x) dx [10]
bn = 2/
p 0,p f(x) sin(nx) dx , n = 1, 2,...,¥ [13]

though an improved solution is sometimes obtained forcing a type of symmetry if possible. For example, consider the function f(x) = 3x shown above. Though this is oddly symmetric on an infinite interval, you can proverbially convince the Fourier series that it is an evenly symmetric function, using a Fourier cosine series. As illustrated, a cosine function with amplitude equaling f(x) on the interval [0,5] (its negative value) is rather similar with f(x) - @ least beginning with a minimum & ending with a maximum; but the sine function with a maximum in the middle and minima of 0 at the endpoints causes osciallation and endpoint problems. The 'attempt' of the cosine series' convergence to portray the sharp V turn at x = 0 toward evenly symmetric values, provides faster convergence (O(1/n2)) (the function as defined does not extend past that toward negative values, but the series doesn't know that).

Solving the Fourier cosine series (calculations not shown) yields :

f(x) = 15/2 - 60/p2 Sn=1,3,5,...,¥ cos(np x/5)/n2

A plot of its truncated series for N = 0, 1, 3, 5, & 101 is shown below for comparison with the previous solution.

Fourier Interpolation

My purpose of discussing Fourier series was actually as a prerequisite for its use for interpolation. If you know a function f(x), calculating its Fourier series can be rather absurd (though it can reveal some properties of the function of which you might else be unaware) - why calculate what you already know ? A more practical use though is calculating such a series for a presumed unknown function.

Suppose you have a set of periodic data points such as average monthly precipitation (periodic because they vary from the January to December values, then the next value would be January's again - a period of a year) and you want values between these points which do not vary abruptly. Though rarely bad, linear interpolation does not accomplish this - abrupt shifts likely at the data points :


The periodic nature suggests that a Fourier series is a natural solution. A truncated quasi-Fourier series which interpolates (passes thru) the data points is the presumed function. The solution differs slightly depending whether an odd or even number of points is chosen.

For an odd number 2N + 1 of equally-spaced interpolation points xk on a periodic interval of 2 p :

xk = 2p k/(2N+1) , k = 1, 2,...,2N+1 [14]

with values at those points f(xk), the interpolating series F(x) is :

F(x) = Sn=0,N {an cos(nx) + bn sin(nx)} [15]
a0 = 1/(2N+1)
Sk=1,2N+1 f(xk) cos(0xk) = 1/(2N+1) Sk=1,2N+1 f(xk) [16]
an = 2/(2N+1)
Sk=1,2N+1 f(xk) cos(nxk) , n = 1, 2,...,N [17]
bn = 2/(2N+1)
Sk=1,2N+1 f(xk) sin(nxk) , n = 0, 1, 2,...,N [18]

For an even number 2N of equally-spaced interpolation points xk on a periodic interval of 2 p :

xk = pk/N , k = 1, 2,...,2N [19]

with values at those points f(xk), the interpolating series F(x) is :

F(x) = Sn=0,N-1 {an cos(nx) + bn sin(nx)} + 1/2 {aN cos(Nx) + bN sin(Nx)} [20]
a0 = 1/2N
Sk=1,2N f(xk) cos(nxk) = 1/2N Sk=1,2N f(xk) [21]
an = 1/N
Sk=1,2N f(xk) cos(nxk) , n = 1, 2,...N [22]
bn = 1/N
Sk=1,2N f(xk) sin(nxk) , n = 0, 1, 2,...N [23]

These forms are analogous with the red equations above. Note that the b0 & bN terms are 0 because sin(0xk) = sin(Nxk) = 0, so they can be removed from the equations. I used the word quasi-Fourier series above because though F(x) has the same general properties - e.g., a0 is the average of all f(xk), convergence is best for smoothly varying data, similar adjustments for symmetry can be made - which you may feel should exist even if the data deviates from it - a few differences exist. The sums for the coefficients using the trapezoidal rule compute them exactly, though obviously fewer are used for interpolation than the infinite number available if the function were known.

Variable change

Again, a variable change or mapping is necessary for intervals other than length 2p, which can be accomplished either adjusting the interval for interpolation points or inserting these changes directly in the above equations. These are equivalent, though the former requires fewer calculations because calculating the coefficients would require an extra multiplication for each term else. After the coefficients are calculated, the variable change or mapping to the correct interval must be done only once for each estimated value desired.

Example

Values of the average monthly precipitation amounts f(xk) (inches) shown above are :

Month k xk f(xk) JAN 1 1p/6 1.861944 FEB 2 2p/6 1.663889 MAR 3 3p/6 2.468889 APR 4 4p/6 3.047500 MAY 5 5p/6 2.882778 JUN 6 6p/6 3.510278 JUL 7 7p/6 3.162500 AUG 8 8p/6 3.355833 SEP 9 9p/6 2.915000 OCT 10 10p/6 2.158056 NOV 11 11p/6 2.678056 DEC 12 12p/6 2.650833

For this, f(xk) are data for months k = 1, 2,...,12 (thus 2N = 12) January to December, such that the interval begins and ends (xk = 0 & 2p) at December's monthly value. Any beginning/ending point can be chosen - one closely corresponding with a solstice may be best; though the series doesn't know about solstices either - the best is
probably that for which the plotted data (from beginning to end) most closely resembles the sines & cosines. This is a long calculation, though easy for a computer program. Using the above equations for an even number of interpolation points yields the following coefficients :

n an bn 0 2.696296 0 1 -.5756244 -.2815022 2 .1595369 -.1042437 3 .2869913 -.1082867 4 .1899539 -.05059842 5 -.1410878 -.04984074 6 .06953704 0

Using which F(x) can be calculated. A diagram of such is :


with the abscissa adjusted, but interpolation points xk remaining at the center of each month. This method can be used even for irregular data intervals, though the interpolation points must be equally-spaced. The precipitation data is actually an example of this, because monthly durations differ. Below are the days of an average year (assuming 1 leap year for every 4 years, for which most data will be valid) :

Month Days of year Midpoint JAN 0-31 15.5 FEB 31-59.25 45.125 MAR 59.25-90.25 74.75 APR 90.25-120.25 105.25 MAY 120.25-151.25 135.75 JUN 151.25-181.25 166.25 JUL 181.25-212.25 196.75 AUG 212.25-243.25 227.75 SEP 243.25-273.25 258.25 OCT 273.25-304.25 288.75 NOV 304.25-334.25 319.25 DEC 334.25-365.25 349.75

If daily average values between the midpoints of March & April are desired, for example; daily values of x must be mapped to the correct points between the interpolation points x3 & x4 for March & April, which are xd below. Because day durations are equal, linear interpolation is used for this (but not for many other forms of data) :

xd = x3 + (x4 - x3) (d - 74.75)/(105.25 - 74.75)

Then values of xd can be inserted in [20] - coefficients are only calculated once !


Text and embedded images are copyright of Joseph Bartlo, though may be used with proper crediting.

Home Page