Gibbs phenomenon¶

Oscillatory behavior of the Fourier series around a jump discontinuity.

  • wiki: Gibbs phenomenon

Convergence of Fourier series¶

  • The Fourier series converges at all points where $f(x)$ is continuous, and it converges to $\frac{1}{2}(f(x^+)+f(x^-))$ at all points where $f$ is discontinuous.
  • The Fourier series converges to $f$ in the mean square sense.
In [171]:
import numpy as np
from numpy.fft import fft,ifft,fftshift
import matplotlib.pyplot as plt

N = 1000
L = 2
x = np.arange(-N, N)*L/N
In [172]:
f = np.heaviside(np.sin(np.pi*x), 0.0)
f_hat = fft(f)
plt.scatter(x, f)
Out[172]:
<matplotlib.collections.PathCollection at 0x7ff6f51dd0a0>
In [173]:
def Gibbs(fun_hat, M):
    g_hat = fun_hat.copy()
    g_hat[M+1:2*N-M] = 0.0
    fun = np.real(ifft(g_hat))
    return fun
In [174]:
#fig = plt.figure(figsize=plt.figaspect(0.1))
fig = plt.figure(figsize=(20, 4))
ax = fig.add_subplot(1, 3, 1)
ax.plot(x, Gibbs(f_hat, 10))
ax.plot(x, f, lw=5, alpha=0.5)

ax = fig.add_subplot(1, 3, 2)
ax.plot(x, Gibbs(f_hat, 30))
ax.plot(x, f, lw=5, alpha=0.5)

ax = fig.add_subplot(1, 3, 3)
ax.plot(x, Gibbs(f_hat, 200))
ax.plot(x, f, lw=5, alpha=0.5)
plt.show()
In [175]:
#fig = plt.figure(figsize=plt.figaspect(0.1))
fig = plt.figure(figsize=(20, 4))
ax = fig.add_subplot(1, 3, 1)
ax.plot(x, Gibbs(f_hat, 10))
ax.plot(x, f, lw=5, alpha=0.5)
plt.xlim(-0.2, 0.2)

ax = fig.add_subplot(1, 3, 2)
ax.plot(x, Gibbs(f_hat, 30))
ax.plot(x, f, lw=5, alpha=0.5)
plt.xlim(-0.2, 0.2)

ax = fig.add_subplot(1, 3, 3)
ax.plot(x, Gibbs(f_hat, 200))
ax.plot(x, f, lw=5, alpha=0.5)
plt.xlim(-0.2, 0.2)

plt.show()
In [ ]: