Fourier Series Approximation of a Square Wave

Loading...

Loading video...

Pro
0:00 / 0:00

1. Overview

  • Purpose: Visually demonstrate how the Fourier series of a square wave converges as more odd‑harmonic sine terms are added, highlighting the Gibbs phenomenon near the discontinuities.
  • Scene: A single Manim Scene (e.g., FourierSquareWaveScene).
  • Total Duration: ~25 seconds (well under the 30 s limit).

2. Mathematical Elements

  • Target function (ideal square wave, period 2π2\pi):
    f(x)={1,0<x<π,1,π<x<0,f(x) = \begin{cases} 1, & 0 < x < \pi,\\ -1, & -\pi < x < 0, \end{cases}
  • Fourier series (odd harmonics only):
    SN(x)=4πk=0N1sin((2k+1)x)2k+1,S_N(x) = \frac{4}{\pi}\sum_{k=0}^{N-1} \frac{\sin\big((2k+1)x\big)}{2k+1},
    where NN is the number of odd terms included (i.e., the partial‑sum index).
  • Individual sine component for the k extthk^{\ ext{th}} term:
    sk(x)=4πsin((2k+1)x)2k+1.s_k(x) = \frac{4}{\pi}\frac{\sin\big((2k+1)x\big)}{2k+1}.

3. Visual Elements

Element Description Color / Style
Coordinate axes Horizontal axis from π-\pi to π\pi; vertical axis from 1.5-1.5 to 1.51.5. Tick marks at multiples of π2\frac{\pi}{2}. Light gray axes, black tick labels (optional, small).
Ideal square wave (reference) Thin dashed line showing the exact square wave (height ±1\pm1). Dark gray, stroke width 2, dash pattern.
Partial sum curve Smooth curve representing SN(x)S_N(x). Updated after each new term. Solid line, primary color (e.g., deep blue), stroke width 4.
Current sine component The newly added term sk(x)s_k(x) highlighted while it is being introduced. Distinct bright accent (e.g., orange), stroke width 3, appears briefly then fades into the background color of the partial sum.
Number of terms display Small counter in the upper‑right corner showing "N = X" where X = current number of odd terms. White text on a semi‑transparent dark rectangle (opacity 0.7) for readability.
Title Center‑top title: "Fourier Series Approximation of a Square Wave". Bold white text on a semi‑transparent dark rectangle background.

4. Animation Sequence & Timing

Phase Action Duration Details
0 – 2 s Fade‑in axes, title, and reference square wave. 2 s Axes and title slide in from the top; reference wave draws with a short dash‑stroke animation.
2 – 4 s Introduce first term (k=0, N=1). 2 s The sine component s0(x)s_0(x) draws in bright orange over 1 s, then smoothly morphs (color transition) into the partial‑sum blue curve. Counter updates to "N = 1".
4 – 6 s Add second odd term (k=1, N=2). 2 s New orange sine s1(x)s_1(x) draws, simultaneously the existing blue partial sum morphs to the new sum S2S_2. Counter to "N = 2".
6 – 8 s Add third odd term (k=2, N=3). 2 s Same pattern.
8 – 10 s Add fourth odd term (k=3, N=4). 2 s
10 – 12 s Add fifth odd term (k=4, N=5). 2 s
12 – 14 s Add sixth odd term (k=5, N=6). 2 s
14 – 16 s Add seventh odd term (k=6, N=7). 2 s
16 – 18 s Add eighth odd term (k=7, N=8). 2 s
18 – 20 s Add ninth odd term (k=8, N=9). 2 s
20 – 22 s Pause on final partial sum (N=9) to let viewer observe Gibbs overshoot. 2 s Slight slow‑motion zoom (1.05×) on the discontinuities for emphasis (camera pan).
22 – 24 s Fade‑out all elements except title, then fade‑out title. 2 s Clean exit.

Total: 24 seconds (well within limit).

Transition Details

  • Sine component entry: Use Create‑style drawing for the orange curve over 1 s.
  • Partial sum update: Apply a Transform from the previous blue curve to the new blue curve, synchronized with the orange component fading to the blue color (cross‑fade). Duration 1 s.
  • Counter update: Simple ReplacementTransform of the number text.
  • Zoom on Gibbs region: At 20 s, a subtle camera scale to 1.05 centered on x=±πx = \pm \pi for 2 s, then return to original view.

5. Camera & Perspective

  • Default 2‑D orthographic view.
  • Zoom segment (20‑22 s) as described above to highlight overshoot.
  • No rotation or 3‑D perspective needed.

6. Styling Guidelines

  • Use a clean, sans‑serif font (e.g., OpenSans) for all text.
  • All colors chosen to be color‑blind friendly: deep blue, orange, dark gray, white.
  • Ensure the opaque background rectangle for the counter and title provides at least 80 % contrast with the text.
  • Keep line widths consistent (axes 2, reference wave 2, partial sum 4, sine component 3).

7. Final Remarks

  • The animation progresses smoothly from one partial sum to the next, making the convergence and Gibbs phenomenon visually intuitive.
  • All elements fit within a single Manim Scene class, respecting the duration constraint.

Created By

nande mononokenande mononoke

Description

The animation builds the Fourier series of a square wave by adding successive odd-harmonic sine terms. A dashed reference square wave is shown, and each new sine component appears in orange before merging into the blue partial-sum curve. A counter displays the number of terms. The view zooms near the discontinuities to highlight the Gibbs overshoot as the series converges up to nine terms.

Created At

Feb 1, 2026, 05:10 AM

Duration

0:28

Tags

fourier-seriessquare-wavegibbs-phenomenon

Status

Completed
AI Model
GPT-OSS-120b