17
On the Computation of Fourier Coefficients Wolfram Koepf, Etienne Le Grand Nana Chiadjeu * Abstract In this paper we derive an identity for the Fourier coefficients of a differentiable function f (t) in terms of the Fourier coefficients of its derivative f (t). This yields an algorithm to compute the Fourier coefficients of f (t) whenever the Fourier coefficients of f (t) are known, and vice versa. Furthermore this generates an iterative scheme for N times differentiable functions complementing the direct computation of Fourier coefficients via the defining integrals which can be also treated automatically in certain cases, see [10] and [2]. As an application, we present an algorithm for the computation of the Fourier coefficients of trigonometric rational functions. 1 Introduction As general references for elementary properties of Fourier series see e.g. [1] and [8]. Let f :[a, b] R be a continuous function in the interval I =[a, b] which is continuously differentiable in (a, b). The function f can be periodically continued to R with period T = b - a. Let’s denote the resulting periodic function by F : R R. By definition, the function F is continuous in R besides the points a + kT (k Z) which are (possible) discontinuities of step size Δ := f (a) - f (b). The real and complex Fourier series of f (t) are given as F (f )(t) := a 0 2 + n=1 a n cos(nωt)+ n=1 b n sin(nωt)= n=-∞ c n e inωt , (1) where ω = 2π T is the circular frequency and the corresponding real Fourier coefficients are given by a n = 2 T b a f (t) cos(nωt)dt R , b n = 2 T b a f (t) sin(nωt)dt R , whereas the complex Fourier coefficients are defined as c n = 1 T b a f (t)e -inωt dt C . Note that for real f (t) one has c -n = c n , z denoting the complex conjugate of z . We remark that a finite sum of the form (1) is called a Fourier polynomial. * University of Kassel, Department of Mathematics, Heinrich-Plett-Str. 40, D-34132 Kassel, Germany 1

On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

On the Computation of Fourier Coefficients

Wolfram Koepf, Etienne Le Grand Nana Chiadjeu∗

Abstract

In this paper we derive an identity for the Fourier coefficients of a differentiable function f(t)in terms of the Fourier coefficients of its derivative f ′(t). This yields an algorithm to computethe Fourier coefficients of f(t) whenever the Fourier coefficients of f ′(t) are known, and viceversa. Furthermore this generates an iterative scheme for N times differentiable functionscomplementing the direct computation of Fourier coefficients via the defining integrals whichcan be also treated automatically in certain cases, see [10] and [2]. As an application, wepresent an algorithm for the computation of the Fourier coefficients of trigonometric rationalfunctions.

1 IntroductionAs general references for elementary properties of Fourier series see e.g. [1] and [8].

Let f : [a, b] → R be a continuous function in the interval I = [a, b] which is continuouslydifferentiable in (a, b). The function f can be periodically continued to R with period T = b− a.Let’s denote the resulting periodic function by F : R → R. By definition, the function F iscontinuous in R besides the points a + k T (k ∈ Z) which are (possible) discontinuities of stepsize ∆ := f(a)− f(b).

The real and complex Fourier series of f(t) are given as

F(f)(t) :=a0

2+

∞∑n=1

an cos(n ω t) +∞∑

n=1

bn sin(n ω t) =∞∑

n=−∞

cn einωt , (1)

where ω = 2πT

is the circular frequency and the corresponding real Fourier coefficients are givenby

an =2

T

∫ b

a

f(t) cos(nωt)dt ∈ R ,

bn =2

T

∫ b

a

f(t) sin(nωt)dt ∈ R ,

whereas the complex Fourier coefficients are defined as

cn =1

T

∫ b

a

f(t)e−inωtdt ∈ C .

Note that for real f(t) one has c−n = cn, z denoting the complex conjugate of z. We remark that afinite sum of the form (1) is called a Fourier polynomial.

∗University of Kassel, Department of Mathematics, Heinrich-Plett-Str. 40, D-34132 Kassel, Germany

1

Page 2: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

Of course, by definition we have the relations c0 = a0

2as well as

cn =1

2(an − i bn) and therefore cn =

1

2(an + i bn) (n ∈ Z=1)

which—solving for an and bn—gives

an = cn + cn and bn = i(cn − cn) (n ∈ Z=1) .

Under our assumption that f is continuous in (a, b), it turns out that pointwise F(f)(t) = f(t) forall t ∈ (a, b).1

Note that if the defining interval is symmetric, i.e. (a, b) = (−T2, T

2), then the Fourier coef-

ficients of an even function f satisfy bn = 0 (n ∈ Z=1), and for an odd function f one getsan = 0 (n ∈ Z=1).

Using the defining equations, the Fourier coefficients can be computed automatically in certaininstances using a computer algebra system. This method was considered e.g. in [10] using Maple[6] and in [2] using Mathematica [11]. In the current article we will develop a different method.

In the sequel we will use the following notations. Since f is continuously differentiable, f ′ iscontinuous and has a Fourier series itself, for which we write

F(f ′)(t) =a′02

+∞∑

n=1

a′n cos(n ω t) +∞∑

n=1

b′n sin(n ω t) =∞∑

n=−∞

c′n einωt ,

i.e., the Fourier coefficients of the derivative function are denoted by dashes. If f ∈ CN [a, b], thenwe can continue taking derivatives, and for the kth derivative (k 5 N ) we use the notation

F(f (k))(t) =a

(k)0

2+

∞∑n=1

a(k)n cos(n ω t) +

∞∑n=1

b(k)n sin(n ω t) =

∞∑n=−∞

c(k)n einωt .

2 An Identity for Fourier CoefficientsThe complex Fourier coefficients cn are given by the relation

cn =1

T

∫ a+T

a

f(t)e−inωtdt .

Integrating by parts, using u(t) = f(t), v′(t) = e−inωt, hence u′(t) = f ′(t) and v(t) = 1−inω

e−inωt,we get

cn =

[f(t)e−inωt

−inωT

]a+T

a

+1

T

∫ a+T

a

f ′(t)e−inωt

inωdt

=f(a + T )e−inω(a+T ) − f(a)e−inωa

−inωT+

1

inω

(1

T

∫ a+T

a

f ′(t)e−inωtdt

)=

f(a + T )− f(a)

−2πine−inωa − i

nωc′n ,

1One can furthermore prove that at the points of discontinuity one has F(f)(a + kT ) = 12 (f(a) + f(b)) (k ∈ Z).

2

Page 3: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

where we have used that ωT = 2π. Hence we have derived the identity

cn +i

nωc′n =

i

2πn(f(b)− f(a))e−inωa . (2)

As we shall discuss later, this easy-to-derive relation has interesting applications, and can be usedto compute the Fourier coefficients recursively under certain conditions.

Next, we would like to rewrite the above equation in terms of the real Fourier coefficients an

and bn. Using the relation cn = 12(an − ibn), we get from (2)

an − ibn +i

nω(a′n − ib′n) =

i

πn(f(b)− f(a))e−inωa ,

and separating the real and imaginary parts, we conclude that

an +1

nωb′n =

1

πn(f(b)− f(a)) sin(nωa) and

−bn +1

nωa′n =

1

πn(f(b)− f(a)) cos(nωa) .

(3)

Finally, we summarize the above identities in the following

Theorem 1 (Fourier coefficients and derivatives) Let f : [a, b] → R be continuous in [a, b] andcontinuously differentiable in (a, b). Then the real and complex Fourier coefficients of f(t) and off ′(t) satisfy the identities

cn +i

nωc′n =

i

2πn(f(b)− f(a))e−inωa (n ∈ Z, n 6= 0)

andan +

1

nωb′n =

1

πn(f(b)− f(a)) sin(nωa) and

−bn +1

nωa′n =

1

πn(f(b)− f(a)) cos(nωa) (n ∈ Z=1) ,

respectively.In particular: If a = 0, i.e. if the interval is I = [0, T ], then

cn + iT

2πnc′n =

i

2πn(f(T )− f(0))

andan +

T

2πnb′n = 0 and

−bn +T

2πna′n =

1

πn(f(T )− f(0)) .

(4)

Furthermore, if the interval is symmetric w.r.t the origin, i.e. if I = [−T2, T

2], then

cn + iT

2πnc′n =

i

2πn(f(T

2)− f(−T

2))(−1)n

andan +

T

2πnb′n = 0 and

−bn +T

2πna′n =

(−1)n

πn(f(T

2)− f(−T

2)) .

(5)

Using these identities, one can easily compute the Fourier coefficients of f ′(t), if those of f(t) areknown, and vice versa.

3

Page 4: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

3 Iterative Computation of Fourier CoefficientsTheorem 1 can be used to compute the Fourier coefficients iteratively. We give some examples forthis approach.

Example 2 (Fourier coefficients of powers) Let f(t) = tm for some m ∈ Z=1. First, we con-sider the case I = [0, T ]. For m = 1 and m = 2, the corresponding periodic functions F aredrawn in Figure 1. Note that the periodic linear function is called a sawtooth function.

Figure 1: The linear and square functions for T = 1

Whereas in these cases, it is easy to compute the Fourier coefficients directly from the definingformulas, namely for f(t) = t:

an =2

T

∫ T

0

t cos

(2πnt

T

)dt = 0 ,

bn =2

T

∫ T

0

t sin

(2πnt

T

)dt = − T

πn,

and for f(t) = t2:

an =2

T

∫ T

0

t2 cos

(2πnt

T

)dt =

T 2

π2n2,

bn =2

T

∫ T

0

t2 sin

(2πnt

T

)dt = −T 2

πn,

we would like to use Theorem 1 instead. Let f(t) = t. Then the derivative f ′(t) = 1 obviously hasFourier coefficients a′0 = 2 and a′n = 0, b′n = 0 (n ∈ Z=1). Therefore we get from (4)

an +T

2πnb′n = 0 ,

hence an = 0 and

−bn +T

2πna′n =

1

πn(f(T )− f(0)) =

T

πn,

hence bn = − Tπn

.In the next step, we set f(t) = t2. Hence f ′(t) = 2t with a′n = 0 and b′n = −2T

πnby our previous

computation. Therefore, using (4), we get

an +T

2πnb′n = an −

T

2πn

2T

πn= an −

T 2

π2n2= 0 ,

hence an = T 2

π2n2 and

−bn +T

2πna′n = −bn =

1

πn(f(T )− f(0)) =

T 2

πn,

4

Page 5: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

hence bn = −T 2

πn.

Obviously, this strategy can be used iteratively (or recursively) to compute the Fourier co-efficients of every power f(t) = tm, and by linearity, of every polynomial. This algorithm isconsidered in more generality in the next section.

Next, we consider the symmetric case I = [−T2, T

2]. The corresponding functions for m = 1

and m = 2 are drawn in Figure 2.

Figure 2: The symmetric linear and square functions (f(t) = t and f(t) = 4t2) for T = 1

Again one can compute the Fourier coefficients easily from their definition. For f(t) = t:

an =2

T

∫ T/2

−T/2

t cos

(2πnt

T

)dt = 0 ,

bn =2

T

∫ T/2

−T/2

t sin

(2πnt

T

)dt = −(−1)n T

πn,

and for f(t) = t2:

an =2

T

∫ T/2

−T/2

t2 cos

(2πnt

T

)dt =

(−1)n T 2

π2n2,

bn =2

T

∫ T/2

−T/2

t2 sin

(2πnt

T

)dt = 0 .

However, these results are contained in Formulas (5) and can be also computed iteratively.

Example 3 (Fourier coefficients including special functions) Let f(t) = arctan t. Since f(t) isodd, it is clear that an = 0. However the coefficients bn cannot be easily computed by the definingformula:

bn =2

T

∫ T/2

−T/2

arctan t sin

(2πnt

T

)dt .

Note that Maple fails to compute bn even if T is given explicitly.However, we can compute bn in terms of special functions using (5). Notice that for f(t) =

arctan t, we have f ′(t) = 11+t2

, a rational function. For the even function f ′(t) we get b′n = 0, andfor a′n we derive using Maple

> anprime:=2/T*int(1/(1+tˆ2)*cos(2*Pi*n*t/T),t=-T/2..T/2);

5

Page 6: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

anprime := 2(−2 Si(n π (T + 2 I)

T) sinh(

n π

T) cosh(

n π

T) + Ci(−n π (T + 2 I)

T) cosh(

n π

T)2 I

− 1

2I Ci(−n π (T + 2 I)

T)− 2 Si(

n π (T − 2 I)

T) sinh(

n π

T) cosh(

n π

T)

− Ci(−n π (T − 2 I)

T) cosh(

n π

T)2 I +

1

2I Ci(−n π (T − 2 I)

T)

− Ci(n π (T − 2 I)

T) cosh(

n π

T)2 I +

1

2I Ci(

n π (T − 2 I)

T)

+ Ci(n π (T + 2 I)

T) cosh(

n π

T)2 I − 1

2I Ci(

n π (T + 2 I)

T))/T

where

Ci(t) = −∫ ∞

t

cos x

xdx = γ + ln t +

∫ t

0

cos x− 1

xdx

(γ denoting the Euler-Mascheroni constant) and

Si(t) =

∫ t

0

sin x

xdx

denote the integral cosine and sine functions, respectively.Since for f(t) = arctan t we have f(−T/2) = arctan(−T/2) = − arctan(T/2) = −f(T/2)

it is now clear that we get for bn by (5)> f:=arctan(t);

f := arctan(t)

> bn:=T/(2*Pi*n)*anprime-(-1)ˆn/(Pi*n)*2*subs(t=T/2,f);

bn := (−2 Si(n π (T + 2 I)

T) sinh(

n π

T) cosh(

n π

T) + Ci(−n π (T + 2 I)

T) cosh(

n π

T)2 I

− 1

2I Ci(−n π (T + 2 I)

T)− 2 Si(

n π (T − 2 I)

T) sinh(

n π

T) cosh(

n π

T)

− Ci(−n π (T − 2 I)

T) cosh(

n π

T)2 I +

1

2I Ci(−n π (T − 2 I)

T)

− Ci(n π (T − 2 I)

T) cosh(

n π

T)2 I +

1

2I Ci(

n π (T − 2 I)

T)

+ Ci(n π (T + 2 I)

T) cosh(

n π

T)2 I − 1

2I Ci(

n π (T + 2 I)

T))/(n π)−

2 (−1)n arctan(T

2)

n πIt turns out that for this particular example Maple fails, but Mathematica is successful and givesthe above result directly from the underlying integral. However, our theorem gives an algorithmicapproach which will lead to further examples that are out of reach for Maple or Mathematica.

Let us finish this section with the remark that for rational functions the algorithm described canbe used to lower the degree of powers of the denominator polynomial recursively. Details will begiven in a forthcoming paper.

6

Page 7: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

4 Iterated DerivativesIn this section, we assume that f ∈ CN [0, T ] for some N ∈ Z=1. Then by Theorem 1 we canwrite down successive identities for successive derivatives of f . Using (2), we get for the complexFourier coefficients and for n ∈ Z, n 6= 0

cn + iT

2πnc′n =

i

2πn(f(T )− f(0))

c′n + iT

2πnc′′n =

i

2πn(f ′(T )− f ′(0))

c′′n + iT

2πnc(3)n =

i

2πn(f ′′(T )− f ′′(0))

...

c(N−1)n + i

T

2πnc(N)n =

i

2πn(f (N−1)(T )− f (N−1)(0))

In order to manipulate the previous relations easier, let us rewrite them in the following way:

cn + a c′n = α0

c′n + a c′′n = α1

c′′n + a c(3)n = α2

...c(N−1)n + a c(N)

n = αN−1

with the abbreviations a = i T2πn

and αk = i2πn

(f (k)(T )− f (k)(0)).Then multiplying the kth equation by (−1)k ak and summing up obviously yields a telescoping

sum with the result

cn = α0 − aα1 + a2α2 − a3α2 + · · ·+ (−1)N−1aN−1αN−1 + (−1)NaNc(N)n

which finally leads to

Theorem 4 (Fourier coefficients and iterated derivatives) For f ∈ CN [0, T ] the following iden-tity for the complex Fourier coefficients is valid (n ∈ Z, n 6= 0):

cn − (−1)N

(Ti

2πn

)N

c(N)n =

N−1∑k=0

(−1)k

(Ti

2πn

)ki

2πn(f (k)(T )− f (k)(0)) . (6)

As a consequence, since a polynomial f(t) of degree N satisfies f (N)(t) = constant, and thereforec(N)n = 0 for n ∈ Z, n 6= 0, Theorem 4 implies

Corollary 5 (Fourier coefficients of polynomials) Let f : [0, T ] → R be a polynomial of degreeN . Then the complex Fourier coefficients of f can be written in the form (n ∈ Z, n 6= 0)

cn =N−1∑k=0

(−1)k

(Ti

2πn

)ki

2πn(f (k)(T )− f (k)(0)) .

7

Page 8: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

Similarly, we can treat the interval I = [−T2, T

2]. In this case, αk = i (−1)n

2πn(f (k)(T ) − f (k)(0)),

hence we have

Theorem 6 (Fourier coefficients and iterated derivatives in symmetric intervals) Forf ∈ CN [−T

2, T

2] the following identity for the complex Fourier coefficients is valid:

cn − (−1)N

(Ti

2πn

)N

c(N)n =

N−1∑k=0

(−1)k+n

(Ti

2πn

)ki

2πn

(f (k)

(T

2

)− f (k)

(−T

2

)).

In particular: Let f : [−T2, T

2] → R be a polynomial of degree N . Then the complex Fourier

coefficients of f can be written in the form (n ∈ Z, n 6= 0)

cn =N−1∑k=0

(−1)k+n

(Ti

2πn

)ki

2πn

(f (k)

(T

2

)− f (k)

(−T

2

)). (7)

Note that the computation of the Fourier coefficients of tm, e.g., using (7) is much more efficientthan the computation using the definition. But for polynomials, we can do even better.

5 Fourier Coefficients of PolynomialsAlthough the algorithm of the previous section can be easily used to compute the Fourier coef-ficients of every polynomial efficiently, in the current section we would like to mention that theFourier coefficients of polynomials can be even written down explicitly.

By the linearity of the Fourier coefficients, it is enough to know them for powers f(t) =tm (m ∈ Z=1). In this case, we have

Theorem 7 (Fourier coefficients of powers) Let f(t) = tm (m ∈ Z=1). The Fourier coefficientsin the interval I = [−T

2, T

2] are given as (n ∈ Z=1)

an =

(

T2πn

)m(−1)n

m2−1∑

k=0

2 m!(2k+1)!

(nπ)2k(−1)m2−1+k if m is even

0 otherwise(8)

and

bn =

(

T2πn

)m(−1)n+1

m−12∑

k=0

2m!(2k+1)!

(nπ)2k(−1)m−1

2+k if m is odd

0 otherwise. (9)

Proof: The formulas are obvious consequences of Theorem 6.On the other hand, these formulas can also be obtained more directly from the definition. We would like

to find

an =2T

∫ T2

−T2

tm cos(

n2π

Tt

)dt .

To do so it is enough to check the antiderivative∫tm cos (nωt) dt =

1(nω)m+1

×

8

Page 9: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

1 + (−1)m

2

m2∑

k=0

(nωt)2k m!(2k)!

(−1)m2

+k sin(nωt) +

m2−1∑

k=0

(−1)m+2

2+k(nωt)2k+1 m!

(2k + 1)!cos(nωt)

+

+1− (−1)m

2

m−12∑

k=0

(−1)m−1

2+k

((nωt)2k m!

(2k)!cos(nωt) + (nωt)2k+1 m!

(2k + 1)!sin(nωt)

)of the integrand tm cos ωt by differentiation. Formula (8) then follows by the fundamental theorem ofcalculus. In a similar fashion the Fourier coefficient bn can be treated. �

We would like to mention that similar formulas can be obtained if the interval is given as I = [0, T ].

6 Efficiency ConsiderationsWhereas it seems obvious that the closed formulas (8)–(9) should yield the fastest computation forthe Fourier coefficients of f(t) = tm whereas (7) should be weaker, and the direct computationusing the definition

cn =1

T

∫ T/2

−T/2

tm exp

(−int

T

)dt (10)

should lead to the longest computation times, reality is a little more complicated. Undoubtedly, thecomputation via the definition is the weakest method. Whether (7) or (8)–(9) are faster, depends onimplementation details, however, and the above assumption is true only for small values of m. If(7) is programmed directly as sum, then (8)–(9) are faster since (7) needs the repeated computationof high order derivatives. On the other hand, if (7) is programmed by computing the high orderderivatives iteratively, then this is faster than (8)–(9) for large m. The reason is that the calculationof large factorials m! and (2k + 1)! and their gcd computation in (8)–(9) is avoided. Detailedtimings can be seen in Tables 1–3.2

The fastest codes for large m in Maple and Mathematica, respectively, based on (7), are givenin Table 6.

m = 100 (10) (7) with Σ (7) iteratively (8)–(9)Maple 3.47 0.47 0.00 0.00

Mathematica 3.61 0.02 0.02 0.00

Table 1: Timings for the computation of cn in [−T2, T

2] for f(t) = t100 with different algorithms

m = 1.000 (10) (7) with Σ (7) iteratively (8)–(9)Maple � 0.86 0.17 0.11

Mathematica 27.45 0.59 0.22 0.23

Table 2: Timings for the computation of cn for f(t) = t1.000

2All timings are in seconds and were done with Maple 10 / Mathematica 5.2 and a laptop with Intel Core Duo T2600, 2.16 GHz CPU and 2 GB RAM. The iteration is most efficient with Maple using a for loop, and with Math-ematica generating a list tab and using Apply[Plus,tab]. � indicates that the computation was not successfulwithin one hour.

9

Page 10: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

m = 10.000 (10) (7) with Σ (7) iteratively (8)–(9)Maple � 105.25 23.64 131.5

Mathematica 112.9 88.77 13.16 77.34

Table 3: Timings for the computation of cn for f(t) = t10.000

Method2b:=proc(m,T,n)local j,x,sum,dif;sum:=0;dif:=xˆm;for j from 0 to m-1 do

sum:=sum+(-1)ˆ(j+n)*Tˆj*(I/(2*Pi*n))ˆ(j+1)*(subs(x=T/2,dif)-subs(x=-T/2,dif));

dif:=diff(dif,x);od;sum;

end:

Method2b[m_, T_, n_] := Module[{j, x, sum, diff, tab},sum = 0;diff = xˆ(m + 1)/(m + 1);tab = Table[diff = D[diff, x];

(-1)ˆ(j + n)*Tˆj*(I/(2*Pi*n))ˆ(j + 1)*((diff /. x -> T/2) - (diff /. x -> -(T/2))),{j, 0, m - 1}];

Apply[Plus,tab]]

Table 4: Fastest Maple and Mathematica codes for the Fourier coefficients of f(t) = tm

7 Fourier Coefficients of Trigonometric Rational FunctionsWhereas in the previous sections we considered rather obvious facts that might have been knownalready to Fourier although he didn’t have a computer algebra system available to implement thesealgorithms, in this section we present an algorithm for a different situation which gives the mainnew result of our paper. In this section, we restrict ourselves to the interval [a, b] = [0, 2π] althoughit is quite easy to generalize our results to an arbitrary interval. Our algorithm solves the problemof determining the complex Fourier coefficients for functions f(t) ∈ R(cos t, sin t), i. e. rationalfunctions in cos t and sin t, in the following way:

1. In the first step we determine a homogeneous linear differential equation DE for f(t) withFourier polynomial coefficients.

2. In the second step this differential equation is converted towards a homogeneous linearrecurrence equation RE with polynomial coefficients—a so-called holonomic recurrenceequation—for the complex Fourier coefficients cn.

3. In the last step the recurrence equation RE is solved using a suitable number of initial valuesif possible.

10

Page 11: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

Note that this procedure imitates the FPS algorithm that was given by the first author [3] whichdetermines a formal power series development of a (holonomic) function. However, both the firstand second steps are non-trivial modifications and therefore quite different. Note further that ifthe third step of the above algorithm does not succeed, the result of our procedure is a holonomicrecurrence equation for cn with which the Fourier coefficients can be computed most efficiently.

Finally, it turns out that our procedure can be modified to functions f(t) ∈ R(t, cos t, sin t) thatare rational in cos t, sin t and t.

Now we would like to present the details of the above mentioned steps.

Theorem 8 (Differential equation for trigonometric rational functions) Let f(t) ∈ R(cos t, sin t).Then for suitable bounds P, L ∈ Z=1 a differential equation of the type

P∑p=0

L∑l=0

(αpl cos(lt) + βpl sin(lt)) f (p)(t) = 0 (11)

is valid. Equation (11) can be determined by linear algebra.

Proof: Every function f(t) ∈ R(cos t, sin t) can be rewritten algorithmically as the ratio of two Fourierpolynomials using the trigonometric addition theorems (see e. g. [5], Section 9.2). Since the derivative of aFourier polynomial is a Fourier polynomial again, all derivatives f (p)(t) can be written as ratios of Fourierpolynomials, and so can the left-hand side of (11).

Since the representation of a trigonometric polynomial as a Fourier polynomial is a canonical form [5],such a representation is unique. Therefore the left hand side of (11) is zero if and only if the numeratorFourier polynomial has all zero coefficients. This leads to a system of linear equations which can be solvedfor the unknowns αpl, βpl ∈ C (l = 0, . . . , L, p = 0, . . . , P ). If P and L are chosen large enough such thatthe number of variables is = than the number of equations, the corresponding homogeneous linear systemhas a solution. �

We mention that by a similar argument it can be shown that every function f(t) ∈ R(t, cos t, sin t)satisfies a differential equation of type (11).

Example 9 (a): Let

f(t) =1

cos t + 2.

Thenf ′(t) =

sin t

(cos t + 2)2

so that with P = L = 1 we get

11

Page 12: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

0 =1∑

p=0

1∑l=0

(αpl cos(lt) + βpl sin(lt)) f (p)(t)

= (α00 + α01 cos t + β01 sin t) f(t) + (α10 + α11 cos t + β11 sin t) f ′(t)

= (α00 + α01 cos t + β01 sin t)1

cos t + 2+ (α10 + α11 cos t + β11 sin t)

sin t

(cos t + 2)2

=1

(cos t + 2)2

(α00(cos t + 2) + α01(cos2 t + 2 cos t) + β01(sin t cos t + 2 sin t) +

α10 sin t + α11 sin t cos t + β11 sin2 t)

=1

(cos t + 2)2

( (2α00 +

1

2α01 +

1

2β11

)+ (α00 + 2α01) cos t +

(1

2α01 −

1

2β11

)cos(2t) +

(2β01 + α10) sin t +

(1

2β01 +

1

2α11

)sin(2t)

).

Note that in the last step conversion towards a Fourier polynomial took place. Solving the linearsystem by equating the coefficients of the numerator Fourier polynomial yields the differentialequation

(2 + cos t)f ′(t)− sin t f(t) = 0

which is unique up to a constant factor.(b): In a similar way, our Maple implementation yields the following results

> trigratfindde(1/(cos(t)+2),f(t),1,1);

(cos(t) + 2) ( ddt

f(t))− sin(t) f(t)

> trigratfindde(1/(cos(t)+2)ˆ5,f(t),1,1);

(cos(t) + 2) ( ddt

f(t))− 5 sin(t) f(t)

> trigratfindde((cos(t)/(2+cos(t)ˆ2))ˆ3,f(t),3,1);

(21 sin(t)− 3 sin(3 t)) f(t) + (11 cos(t) + cos(3 t)) ( ddt

f(t))

> trigratfindde((cos(t)/(2+cos(t)ˆ2))ˆ3,f(t),2,4);

(99− 9 cos(2 t)) f(t) + 48 sin(2 t) ( ddt

f(t)) + (92− 44 cos(2 t)) ( d2

dt2f(t))

− 12 sin(2 t) ( d3

dt3f(t)) + (5 + cos(2 t)) ( d4

dt4f(t))

Of course, these differential equations can be rather complicated.> g:=add(k*sin(k*t),k=0..5)/add(kˆ2*cos(k*t),k=0..5);

g :=sin(t) + 2 sin(2 t) + 3 sin(3 t) + 4 sin(4 t) + 5 sin(5 t)

cos(t) + 4 cos(2 t) + 9 cos(3 t) + 16 cos(4 t) + 25 cos(5 t)> trigratfindde(g,f(t),10,1);

(−979

10− 594

5cos(t)− 324

5cos(2 t)− 147

5cos(3 t)− 42

5cos(4 t) +

21

10cos(5 t) +

28

5cos(6 t)

+51

10cos(7 t) + 3 cos(8 t) + cos(9 t))f(t) + (−2 sin(t)− 51

20sin(2 t)− 9

5sin(3 t)

+5

2sin(5 t) +

21

4sin(6 t) +

77

10sin(7 t) +

46

5sin(8 t) + 9 sin(9 t) +

25

4sin(10 t))( d

dtf(t))

12

Page 13: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

We develop now the second step of our algorithm.

Theorem 10 (Holonomic recurrence equation for Fourier coefficients) Let f : [0, 2π] → Rsatisfy a differential equation of type (11). Then the complex Fourier coefficients c

(p)n of the deriva-

tives f (p)(t) satisfy the recurrence equation

P∑p=0

2αp0c(p)n +

P∑p=0

L∑l=1

(c(p)n+l(αpl + iβpl) + c

(p)n−l(αpl − iβpl)

)= 0 . (12)

After replacing c(p)n±l for p > 0 according to Equation (6) of Theorem 4 in terms of cn±l this yields

a holonomic recurrence equation for the complex Fourier coefficients cn of f(t).

Proof: We start with the differential equation (11)

P∑p=0

L∑l=0

(αpl cos(lt) + βpl sin(lt)) f (p)(t) = 0 .

Multiplying the differential equation by cos t and integrating in the interval [0, 2π] yields after some calcu-lations using the addition theorems of the trigonometric functions

P∑p=0

αp0a(p)n +

P∑p=0

L∑l=1

(12αpl

(a

(p)n+l + a

(p)n−l

)+

12βpl

(b(p)n+l − b

(p)n−l

))= 0 . (13)

Multiplying the differential equation by sin t and integrating in the interval [0, 2π] gives similarly

P∑p=0

αp0b(p)n +

P∑p=0

L∑l=1

(12αpl

(b(p)n+l + b

(p)n−l

)+

12βpl

(−a

(p)n+l + a

(p)n−l

))= 0 . (14)

The linear combination (13)–i(14) leads to (12). �

We remark that the order of the recurrence equation (12) is 2L. Hence for the given algorithm instep 1 (Theorem 8) it is better to search for a higher order differential equation (high P ) keeping Las low as possible.

Example 11 (Holonomic recurrence equation for Fourier coefficients) (a): We consider again

f(t) =1

cos t + 2

for which we had already computed the differential equation (2 + cos t)f ′(t)− sin t f(t) = 0. Thealgorithm of Theorem 10 yields the simple recurrence equation

ncn−1 + 4ncn + ncn+1 = 0 .

Note that the leading coefficient n in front of cn+1 shows (for n = 0) that c1 cannot be computedfrom the previous values c0 and c−1, whereas the factor n in front of cn−1 shows that c−1 cannot becomputed from the later values c0 and c1. Therefore different formulas for cn are valid for n = 0and for n 5 0. It turns out that for n = 0 we get the solution

cn =

√3

3

(√3− 2

)n

,

13

Page 14: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

and for n 5 0 we have

cn =

√3

3

(−√

3− 2)n

.

Our Maple implementation gives the above results by> g:=1/(cos(t)+2);

g :=1

cos(t) + 2> DE:=trigratfindde(g,f(t),1,1);

DE := (cos(t) + 2) ( ddt

f(t))− sin(t) f(t)

> RE:=trigdetore(DE,f(t),c(n));

RE := n c(n− 1) I + n c(n + 1) I + 4 I n c(n)> REright:={RE,c(0)=1/(2*Pi)*int(g,t=0..2*Pi),> c(1)=1/(2*Pi)*int(g*exp(-I*t),t=0..2*Pi)};

REright :=

n c(n− 1) I + n c(n + 1) I + 4 I n c(n), c(0) =

√3

3, c(1) =

−4

3π√

3 + 2 π

2 π

> rsolve(REright,c(n));

(−2 +√

3)n√

3

3> REleft:={RE,c(0)=1/(2*Pi)*int(g,t=0..2*Pi),> c(-1)=1/(2*Pi)*int(g*exp(I*t),t=0..2*Pi)};

REleft :=

c(−1) =−4

3π√

3 + 2 π

2 π, −4 I n c(n)− n c(n− 1) I − n c(n + 1) I, c(0) =

√3

3

> sol2:=rsolve(REleft,c(n));

sol2 := (−2−√

3)(n+1) (−2√

3

3+ 1)

Note that—since f(t) is an even and 2π-periodic function—the real Fourier coefficients are givenby bn = 0 and

an = 2cn = 2

√3

3

(√3− 2

)n

for n = 0.(b): For

f(t) =1

(cos t + 2)5,

we get the differential equation

(cos t + 2) f ′(t)− 5 sin t f(t) = 0 ,

the recurrence equation

(n− 4) cn+1 + 4 n cn + (n + 4) cn−1 = 0 ,

14

Page 15: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

Figure 3: The functions f(t) = 1cos t+2

and f(t) = 1(cos t+2)5

and finally the closed form for the complex Fourier coefficients

cn =

{1

1944

√3(−2 +

√3)n (

3 n4 + 20 n3√

3 + 150 n2 + 170 n√

3 + 227)

if n = 01

1944

√3(−2−

√3)n (

3 n4 − 20 n3√

3 + 150 n2 − 170 n√

3 + 227)

if n 5 0.

For the real Fourier coefficients we have again an = 2cn and bn = 0 (n = 0). In this case, by theleading and trailing coefficients n−4 and n+4 of the recurrence equation, we must treat the threeintervals n 5 −4, n = −4, . . . , 4 and n = 4 separately. The above formula covers all three cases.

Note that in this example for n = 0 the resulting Fourier coefficient cn is a hypergeometric term(see e. g. [4], Chapter 2) which can be algorithmically determined from the holonomic recurrenceequation found by an algorithm due to Petkovsek ([7], see [4], Chapter 9) and van Hoeij [9]. VanHoeij’s very efficient variant of this algorithm is part of the Maple 10 recurrence equation solverrsolve.(c): As third example, we consider

f(t) =

(cos t

2 + cos2 t

)3

satisfying the differential equation

(11 cos t + cos(3 t)) f ′(t) + 3 (7 sin(t)− sin(3t)) f(t) = 0 .

Therefore, we receive for the complex Fourier coefficients

n cn+3 + (32 + 11 n) cn+1 + (−32 + 11 n) cn−1 + n cn−3 = 0 .

Using 6 initial values, for n = 0 we get finally the following result3

cn −1

144(√

3−√

2)n (2√

3 n2 − 4√

3− 3 n√

2) sin(n π

2

)and again an = 2cn, bn = 0 (n = 0).

3which is a linear combination of hypergeometric terms

15

Page 16: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

Figure 4: The functions f(t) =(

cos t2+cos2 t

)3 and f(t) = sin t+2 sin(2t)2+cos(2t)

(d): We finish with a Maple example for which a closed form for cn cannot be computed.> g:=(sin(t)+2*sin(2*t))/(2+cos(2*t));

g :=sin(t) + 2 sin(2 t)

2 + cos(2 t)> DE:=trigratfindde(g,f(t),2,4);

DE := 6 sin(2 t) ( ddt

f(t))− 4 sin(2 t) ( d3

dt3f(t)) + (5− 19

2cos(2 t)) ( d2

dt2f(t))

+ (1 +1

2cos(2 t)) ( d4

dt4f(t)) + 4 f(t)

> RE:=trigdetore(DE,f(t),c(n));

RE :=1

2(n− 2)4 c(n− 2) + 2 (2− 2 n + n2) (2 + 2 n + n2) c(n) +

1

2(n + 2)4 c(n + 2)

> REcomplete:={RE,c(0)=1/(2*Pi)*int(g,t=0..2*Pi),> c(1)=1/(2*Pi)*int(g*exp(-I*t),t=0..2*Pi),> c(2)=1/(2*Pi)*int(g*exp(-2*I*t),t=0..2*Pi),> c(3)=1/(2*Pi)*int(g*exp(-3*I*t),t=0..2*Pi)};

REcomplete := {c(1) =−√

3 π I + π I

2 π, c(2) =

4 I√

3 π − 8 I π

2 π, c(3) =

3 I√

3 π − 5 I π

2 π,

c(0) = 0,

1

2(n− 2)4 c(n− 2) + 2 (2− 2 n + n2) (2 + 2 n + n2) c(n) +

1

2(n + 2)4 c(n + 2)}

> rsolve(REcomplete,c(n));

rsolve({c(1) =−√

3 π I + π I

2 π, c(2) =

4 I√

3 π − 8 I π

2 π, c(3) =

3 I√

3 π − 5 I π

2 π, c(0) = 0,

1

2(n− 2)4 c(n− 2) + 2 (2− 2 n + n2) (2 + 2 n + n2) c(n) +

1

2(n + 2)4 c(n + 2)}, c(n))

We would like to point out again that the output of our algorithm is the holonomic recurrenceequation RE for the Fourier coefficients cn. The recurrence equation with some suitable initialvalues constitutes a normal form [5]. Whether or not the holonomic recurrence can be solved in“closed form”, is not essential.

We conclude this section with the

16

Page 17: On the Computation of Fourier Coefficientskoepf/Publikationen/KoepfNana2006.pdfin terms of the Fourier coefficients of its derivative f0(t). This yields an algorithm to compute This

Corollary 12 (Complex Fourier coefficients for trigonometric rational functions) Letf : [0, 2π] → R be continuous and f(t) ∈ R(cos t, sin t).4 Then the complex Fourier coefficientscn of f(t) are holonomic, i. e., they satisfy a holonomic recurrence equation.

Proof: Combining Theorems 8 and 10 gives the result. �

ConclusionWe have shown that for certain input functions, in particular for polynomials and for trigonometricrational functions, the Fourier coefficients can be determined algorithmically. In the latter case,the algorithm mimics the FPS algorithm [3]. Maple programs for the algorithms considered canbe received on demand from the authors ([email protected]).

References[1] Bronstein, I. N., Semendjajew, K. A.: Taschenbuch der Mathematik. Harri Deutsch. Zurich

and Frankfurt, 1971

[2] Denkewitz, L.: Fourieranalyse mit Mathematica. Diploma Thesis, HTWK Leipzig, 2000.http://www.mathematik.uni-kassel.de/˜koepf/Diplome

[3] Koepf, W.: Power series in computer algebra. Journal of Symbolic Computation 13, 1992,581–603

[4] Koepf, W.: Hypergeometric Summation. An Algorithmic Approach to Summation and Spe-cial Function Identities. Vieweg, Braunschweig/Wiesbaden, 1998

[5] Koepf, W.: Computeralgebra. Eine algorithmisch orientierte Einfhrung. Springer, Berlin-Heidelberg, 2006

[6] Monagan, M. B., Geddes, K. O., Heal, K. M., Labahn, G., Vorkoetter, S. M., McCarron, J.,DeMarco, P.: Maple 9: Advanced Programming Guide. Maplesoft, Waterloo, 2003

[7] Petkovsek, M.: Hypergeometric solutions of linear recurrences with polynomial coefficients.J. Symb. Comp. 14, 1992, 243–264

[8] Stocker, H.: Taschenbuch mathematischer Formeln und moderner Verfahren. Harri Deutsch.Fourth Edition, Zurich and Frankfurt, 1999

[9] Van Hoeij, M.: Finite singularities and hypergeometric solutions of linear recurrence equa-tions. J. Pure Appl. Alg. 139, 1999, 109–131

[10] Werner, W.: Mathematik lernen mit Maple. Band 2, Section 1.6.2, dpunkt, Heidelberg, 1996

[11] Wolfram, Stephen: The Mathematica Book. Wolfram Media und Cambridge UniversityPress. Fourth Edition, Cambridge, 1999

4Hence we assume that f(t) has no singularities.

17