You are on page 1of 5

Fourier Coefficients and Fourier Series

Let f is periodic with period 2 a. The Fourier serie of f is given by


 ∞   n πx   n πx 
A0 + 
 ∑ 
A cos 
 
 + B sin 

 a 




n = 1   a 
n n

where the Fourier coefficients are given by
a a
⌠ ⌠
  n πx    n πx 

a
 f( x ) cos
 
 dx  f( x ) sin
 
 dx
 f( x ) dx 
  a  
  a 
⌡ ⌡ ⌡
−a −a −a
A0 = , An = , Bn =
2a a a

The procedure to compute the Fourier coefficients is therefore pretty standard and tedious. In using
Maple to carry out the integrations, it may be useful to define the functions φ, ψ belows which stand
for the cosine and sine functions in the above integrals and thus depend on the parameters n, a.
> restart:with(plots):phi:=
(n,a,x)->cos(n*Pi*x/a);psi:=(n,a,x)->sin(n*Pi*x/a);
 n πx 
φ:= ( n, a, x ) → cos
 

 a 
 n πx 
ψ := ( n, a, x ) → sin
 

 a 
We then give the formula to define the function f. For example, we consider the function f( x ) = x
> f:=x->x;
f := x → x
Finally, the coefficients are computed as follows ( In fact, one can write a procedure in Maple to
perform all of the followings).
> Int(f(x),x=-a..a)/(2*a)=int(f(x),x=-a..a)/(2*a); A[0]:=rhs(%);
a

 x dx
1 ⌡− a
=0
2 a
A0 := 0
> Int(f(x)*phi(n,a,x),x=-a..a)/a=int(f(x)*phi(n,a,x),x=-a..a)/a;
a

  n πx 
 x cos
 
 dx

  a 

−a
=0
a
> A[n]:=subs(sin(n*Pi)=0,cos(n*Pi)=(-1)^n,rhs(%));
An := 0
> Int(f(x)*psi(n,a,x),x=-a..a)/a=int(f(x)*psi(n,a,x),x=-a..a)/a;

Page 1
a

  n πx 
 x sin
 
 dx

  a 
⌡ a ( − sin( n π) + n πcos( n π) )
−a
=−2
n2 π
a 2

> B[n]:=subs(sin(n*Pi)=0,cos(n*Pi)=(-1)^n,rhs(%));
a ( -1 )n
Bn := − 2

We then form the Fourier series
> Serie:=(x,m)->A[0]+sum(A[n]*phi(n,a,x) + B[n]*psi(n,a,x),n=1..m);
 m 
Serie := ( x, m ) → A0 + 

 (∑An φ( n , a , x ) + B n ψ ( n , a , x ) ) 


n = 1 
The above series depends on:
* a: the domain parameter.
* m: the number of terms in the summation.
We can get the series explicitly as follows
> eval(Serie(x,infinity));
  n πx  
 a ( -1 )n sin
 

∞   
∑ − 2 a 
 
n=1
 nπ 
Finally, we feed Maple with explicit value of a, m in the formula for Serie and plot it against the
function to see how good the approximation is. We notice that the Fourier series approximates fairly
well the original function except in a neighborhood of the left end point x = 1. Try to experiment this
by yourself with large m and compare this with the result of the next example.
> a:=1:
plot([Serie(x,20),f(x)],x=0..a,color=[red,blue],thickness=2,title=
"fourier-red, funct-blue");

Page 2
HW1.1.7: We compute the Fourier of
> f:=x->abs(x);
f := abs
The function is extended in a periodic manner with period 2 π. Thus, a = π. We then repeat the
above calculation to get
> phi:= (n,a,x)->cos(n*Pi*x/a);psi:=(n,a,x)->sin(n*Pi*x/a);
> a:=Pi:Int(f(x),x=-a..a)/(2*a)=int(f(x),x=-a..a)/(2*a);A[0]:=rhs(%)
;
> Int(f(x)*phi(n,a,x),x=-a..a)/a=int(f(x)*phi(n,a,x),x=-a..a)/a;
> A[n]:=subs(sin(n*Pi)=0,cos(n*Pi)=(-1)^n,rhs(%));
> Int(f(x)*psi(n,a,x),x=-a..a)/a=int(f(x)*psi(n,a,x),x=-a..a)/a;B[n]
:=subs(sin(n*Pi)=0,cos(n*Pi)=(-1)^n,rhs(%));
 n πx 
φ:= ( n, a, x ) → cos
 

 a 
 n πx 
ψ := ( n, a, x ) → sin
 

 a 
π

 x dx
1 ⌡− π 1
= π
2 π 2
1
A0 := π
2

Page 3
π

 x cos( n x ) dx
⌡ cos( n π) + n πsin( n π) − 1
−π
=2
π n2 π
( -1 )n − 1
An := 2
n2 π
π

 x sin( n x ) dx

−π
=0
π
Bn := 0
> Serie:=(x,m)->A[0]+sum(A[n]*phi(n,a,x) +
B[n]*psi(n,a,x),n=1..m);eval(Serie(x,infinity));
 m 

Serie := ( x, m ) → A0 + 
 ∑ ( An φ( n, a, x ) + Bn ψ ( n, a, x ) ) 


n = 1 
 ∞  ( ( -1 )n − 1 ) cos( n x ) 

1
π+ 

2



2 n = 1  n π
2


We enter the defintion of the periodic extension of f in the interval (-4,4)into Maple as follows.
> g:=x->piecewise(x<=Pi and
x>=-Pi,f(x),f(x-2*Pi*floor((x+Pi)/(2*Pi))));
  1 x + π
g := x → piecewise
x ≤ πand − π≤ x, f( x ), f
x − 2 πfloor
 



  2 π 
> plot([Serie(x,3),g(x)],x=-2*Pi..2*Pi,color=[red,blue],thickness=2,
title="fourier-red, funct-blue",scaling=CONSTRAINED);

Page 4
We see that the series approximates the function very well even with only 3 terms in the sum.

Page 5

You might also like