Fourier series approximations to a square wave

advertisement
Fourier series approximations to a square wave
The square wave is the 2 Π-periodic extension of the function
Ø
≤ -1 x £ 0
∞
≤ 1 x>0.
±
In class we showed it can be represented as a Fourier series
¥
Úm=1 Bm sin m x
where
4
Ø
≤ Π€€€€€€€m€
Bm = ∞
≤
± 0
m odd
m even.
We also showed that this could be written as
4
€€€
Π
sin H2 m+1L x
¥
€
Úm=0 €€€€€€€€€€€€€€€€€€€€€€€€€€€
2 m+1
in which form the even terms have been automatically dropped.
We can write this sum as a Mathematica function
In[3]:=
f@M_, x_D := 4  Pi Sum@Sin@H2 m + 1L xD  H2 m + 1L, 8m, 0, M<D
Plot a few partial sums
In[12]:=
Plot@Table@f@M, xD, 8M, 0, 3<D, 8x, -Pi, Pi<D
1.0
0.5
Out[12]=
-3
-2
1
-1
-0.5
-1.0
Take more terms
2
3
2
SquareWave-1.nb
In[13]:=
Plot@Table@f@M, xD, 8M, 0, 16, 4<D, 8x, -Pi, Pi<D
1.0
0.5
Out[13]=
-3
-2
1
-1
2
3
-0.5
-1.0
It’s looking more and more like a square wave, but notice the persistent overshoot at the end.
Plot a series with a very large number of terms
Notice the overshoot at the jump doesn’t go away as the number of terms increases. This is the Gibbs phenomenon, and is a generic feature of Fourier series representations of discontinuous functions.
In[23]:=
Plot@f@100, xD, 8x, -Pi, Pi<, PlotPoints ® 400D
1.0
0.5
Out[23]=
-3
-2
1
-1
2
3
-0.5
-1.0
Zoom in on the wiggles near zero
In[20]:=
Plot@f@200, xD, 8x, -2  10, 2  10<D
1.0
0.5
Out[20]=
-0.2
0.1
-0.1
-0.5
-1.0
Here’s a neat trick
0.2
SquareWave-1.nb
Here’s a neat trick
To clean the wiggles and reduce the overshoot, apply a low-pass filter to the Fourier coefficients.
In[28]:=
Out[28]=
In[29]:=
filter@Ω_D = 1 - Ω ^ 2
1 - Ω2
g@M_, x_D := 4  Pi Sum@Sin@H2 m + 1L xD  H2 m + 1L filter@m  MD, 8m, 0, M<D
The series approaches the square wave more slowly, but more smoothly.
In[32]:=
Plot@8g@4, xD, g@8, xD, g@16, xD<, 8x, -Pi, Pi<D
1.0
0.5
Out[32]=
-3
-2
1
-1
2
3
-0.5
-1.0
With a large number of terms, the fit is very good.
In[31]:=
Plot@g@100, xD, 8x, -Pi, Pi<, PlotPoints ® 400D
1.0
0.5
Out[31]=
-3
-2
1
-1
-0.5
-1.0
2
3
3
Download