Application Center - Maplesoft

App Preview:

Fourier Series Expansion

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Image 

 

Fourier Series Expansion 

Yasuyuki Nakamura
Graduate School of Information Science, Nagoya University
A4-2(780), Furo-cho, Chikusa-ku, Nagoya, 464-8601, Japan
nakamura@nagoya-u.jp
http://www.phys.cs.is.nagoya-u.ac.jp/~nakamura/
 

 

Definition 

A periodic function f(x) with a period `+`(`*`(2, `*`(L))) can be expressed as follows with sine functions and cosine functions: 

 

where a[n] and b[n] are Fourier coefficients and are defined as  

 

 

 

Example 

Here we consider the case of a function with a period 2 (L = 1) for the simplicity.  

 

Definition of a function  f(x)  

Example:Embedded component 

Definition by yourself:  

        -1 ≤ x < Embedded component ;  Embedded component 

  Embedded componentx < 1        ;  Embedded component 

Draw(When you click this button, the function is drawn.) 

 

Fourier series 

Fourier coefficients are calculated as bellow.Calc 

Embedded component 

Embedded component 

 

Note: n~ means that  n is an integer.  

Embedded component 

Animation 

Fourier series expansion of f(x) and its depiction with n-th order: n = Embedded componentDo 

Embedded component 

Function 

> restart:
 

> with(DocumentTools):
 

>  c := 0:
 f1 := 0:
 f2 := 1:
 f := x -> piecewise(-1 <= x and x <= c, f1, c <= x and x <= 1, f2):
 SetProperty(ComboBox0, value, "Step");
 SetProperty(TextArea0, value, 0);
 SetProperty(TextArea1, value, 0);
 SetProperty(TextArea2, value, 0);
 SetProperty(TextArea3, value, 1);
 SetProperty(TextArea3, visible, true);
 SetProperty(Plot0, value, plot(f(x), x=-1..1, thickness=2, scaling=constrained));
 SetProperty(MathContainer0, value, NULL);
 SetProperty(MathContainer1, value, NULL);
 SetProperty(MathContainer2, value, NULL);
 

> draw := proc()
 global f, c, f1, f2;
 c := parse(GetProperty(TextArea0, value));
 f1 := parse(GetProperty(TextArea2, value));
 f2 := parse(GetProperty(TextArea3, value));
 f := x -> piecewise(-1 <= x and x <= c, f1, c <= x and x <= 1, f2);
 SetProperty(Plot0, value, plot(f(x), x=-1..1, thickness=2, scaling=constrained));
 SetProperty(MathContainer0, value, NULL);
 SetProperty(MathContainer1, value, NULL);
 SetProperty(MathContainer2, value, NULL);
end proc:
 

> calc_ab := proc()
 local n, l, a, b;
 l := 1;
 assume(n, integer);
 a[n] := 1/l*int(f(x)*cos(n*Pi*x/l), x=-l..l);
 b[n] := 1/l*int(f(x)*sin(n*Pi*x/l), x=-l..l);
 SetProperty(MathContainer0, value, a[n]);
 SetProperty(MathContainer1, value, b[n]);
end proc:
 

> cb := proc()
 global c, f1, f2, f;
 if (evalb(GetProperty(ComboBox0, value) = "Step")) then
   c := 0: f1 := 0: f2 := 1:
 elif(evalb(GetProperty(ComboBox0, value) = "Triangle")) then
   c := 0: f1 := x+1: f2 := -x+1:
 elif(evalb(GetProperty(ComboBox0, value) = "Saw")) then
   c := 0: f1 := x+1: f2 := x:
 elif(evalb(GetProperty(ComboBox0, value) = "Other1")) then
   c := 0: f1 := 0: f2 := -4*(x-1/2)^2+1:
 elif(evalb(GetProperty(ComboBox0, value) = "Other2")) then
   c := -1/2: f1 := 0: f2 :=(x+1/2)^2:
 elif(evalb(GetProperty(ComboBox0, value) = "Other3")) then
   c := 1: f1 := x^2: f2 :=x^2:
 end if;

 f := x -> piecewise(-1 <= x and x <= c, f1, c <= x and x <= 1, f2);
 SetProperty(TextArea0, value, c);
 SetProperty(TextArea1, value, c);
 SetProperty(TextArea2, value, f1);
 SetProperty(TextArea3, value, f2);
 SetProperty(Plot0, value, plot(f(x), x=-1..1, thickness=2, scaling=constrained));

end proc:
 

> calc_fourier := proc()
 local N, l, n, a, b;
 global g;
 calc_ab();
 l := 1;
 assume(n, integer);
 a[n] := 1/l*int(f(x)*cos(n*Pi*x/l), x=-l..l);
 b[n] := 1/l*int(f(x)*sin(n*Pi*x/l), x=-l..l);
 a[0] := 1/l*int(f(x), x=-l..l);
 N := parse(GetProperty(TextArea4, value));
 g := (x, N) ->  a[0]/2+sum(a[n]*cos(n*Pi*x/l)+b[n]*sin(n*Pi*x/l), n=1..N);
 SetProperty(MathContainer2, value, g(x, N));
end proc:
 

> draw_fourier := proc()
 local N;
 N := parse(GetProperty(TextArea4, value));
 SetProperty(Plot0, value, fg_plot(N));
end proc:
 

> fg_plot := proc(N::integer)
 plot([f(x), g(x, N)], x=-1..1, thickness=2, scaling=constrained);
end proc:
 

> anim := proc()
 calc_fourier();
 SetProperty(Plot0, value, plots[display](seq(fg_plot(i), i=1..parse(GetProperty(TextArea4, value))), insequence=true));
end proc:
 

> init(); 1
 

init() (1.1)
 

>
 

 

Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.