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
The coefficients an & bn which
accomplish this (all other variables are known) are :
a0 = 1/2
-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].
f(x) = a0/2 + for which
an = 1/ 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).
SN(x) = a0/2 + may be reasonably accurate. This is indeed so, though this rate of convergence is generally
not fast for non-curved and non-periodic functions.
u = Thus,
f(u) = f(x) = 3 x = 3 (5 ( 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/2 The constant term a0 is :
a0 = 15/4 Concerning other coefficients, solutions to the trigonometric integrals are :
for which the (-1)n implies that the terms alternate signs for odd & even values
of n (cos(n bn = - (15/2 Thus the coefficients are :
a0 = 15/2 an = 0 , n = 0, 1, 2,..., So that the Fourier series for f(u) is :
f(u) = 15/2 + 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 - 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) :
-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]
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=1,N {an cos(nx) + bn sin(nx)} [8]
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,
p (2x/5 - 1) , so x = 5 (p + u)/2p
p
-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
p u½-p,p + 15/4p2 (u2/2)½-p,p = 15/4p (p - (-p)) + 15/8p2 (p2 - p2) = 15/2
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)
p2) (-1)n (2p/n) = -(-1)n (15/np)
¥
bn = - (-1)n (15/np) , n = 0, 1, 2,...,¥
Sn=1,¥ {0 cos(nu) - (-1)n (15/np) sin(nu)} = 15/2 - Sn=1,¥ (-1)n (15/np) sin(nu)
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 :


Even symmetry - Fourier cosine series :
f(x) =
Sn=0,¥ an cos(nx) [9]
0,p f(x) dx [10]
0,p f(x) cos(nx) dx , n = 1, 2,...,¥ [11]
Odd symmetry - Fourier sine series :
f(x) = a0 +
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. Solving the Fourier cosine series (calculations not shown) yields :
f(x) = 15/2 - 60/ A plot of its truncated series for N = 0, 1, 3, 5, & 101 is shown below for comparison with
the previous solution.
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).
p2 Sn=1,3,5,...,¥ cos(np x/5)/n2
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 :

For an odd number 2N + 1 of equally-spaced interpolation points xk
on a periodic interval of 2 p :
xk = 2 with values at those points f(xk), the interpolating series F(x) is :
F(x) = For an even number 2N of equally-spaced interpolation points xk on a
periodic interval of 2 xk = with values at those points f(xk), the interpolating series F(x) is :
F(x) = These forms are analogous with the Month k xk f(xk)
JAN 1 1 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 &
2 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 :
p k/(2N+1) , k = 1, 2,...,2N+1 [14]
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]
pk/N , k = 1, 2,...,2N [19]
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]
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 :
p/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
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 :

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.