Devlog #81 – Wave 61: Double Pendulum Ensemble, Viscoelastic Fluid & DFT/STFT Visualiser

Wave 61 spans three distinct domains of physics and mathematics: a 30-member ensemble of double pendulums that makes the butterfly effect quantitative via Lyapunov regression, an interactive viscoelastic blob that brings rheology to life through Maxwell, Kelvin-Voigt and Standard Linear Solid models, and a live DFT & STFT visualiser that turns any signal into a scrolling spectrogram. The library now stands at 559 simulations.

Wave 61 — 3 simulations added
559
Total simulations
3
New this wave
61
Wave number
81
Devlog #

New Simulations

⚖️

Double Pendulum Ensemble — Chaos Divergence & Lyapunov Exponent

30 double pendulums with nearly identical initial conditions (θ₁ offset by k·Δθ). Left canvas: the fan of all trajectories coloured violet → yellow. Right: log₁₀ max|Δθ₁| vs time with a linear regression slope that estimates the Lyapunov exponent λ.

💧

Viscoelastic Fluid — Maxwell, Kelvin-Voigt & Standard Linear Solid

Interactive 10×10 spring-dashpot blob you can drag. Right panel shows stress-relaxation, creep and frequency-sweep curves (G′/G″ vs ω) for three rheological models. Five material presets: Silly Putty, Silicone Gel, Polymer Melt, Ideal Spring, Ideal Dashpot.

🎵

DFT & STFT Visualiser — Live Fourier Spectrum & Spectrogram

Generate sine, square, sawtooth, chirp, AM or multi-tone signals. Top-left: time-domain oscilloscope. Bottom-left: DFT magnitude spectrum. Right: scrolling STFT spectrogram (viridis colourmap). Change window function (Hanning/Hamming/Blackman/Rectangular) and see the spectral leakage difference live.

⚖️ Double Pendulum Ensemble — Quantifying the Butterfly Effect

Why an ensemble?

A single double-pendulum simulation shows chaos visually — the unpredictable motion — but tells you nothing about how fast nearby trajectories diverge. An ensemble of N=30 pendulums, all starting from the same angle except for a tiny offset Δθ in θ₁, makes that divergence rate measurable. It is the numerical equivalent of Lorenz's butterfly: change the initial state by 10−6 rad and the two trajectories will be completely uncorrelated after ~15 seconds.

Lagrangian equations (m₁=m₂=l₁=l₂=1, g=9.81)

denom = 3 - cos(2θ₁ - 2θ₂)

θ₁'' = [ -3g·sinθ₁ - g·sin(θ₁-2θ₂) - 2sin(θ₁-θ₂)·(θ₂'² + θ₁'²cos(θ₁-θ₂)) ] / denom

θ₂'' = [ 2sin(θ₁-θ₂)·(2θ₁'² + 2g·cosθ₁ + θ₂'²cos(θ₁-θ₂)) ] / denom

Each member is integrated independently with RK4 at Δt = 0.005 s. The reference member (k=0) uses exactly θ₁ = θ₁₀. Member k uses θ₁₀ + k·Δθ. The ensemble spread Δθ₁(t) = max|θ₁(k,t) − θ₁(0,t)| is tracked every frame.

Lyapunov exponent estimation

For a chaotic system, the average rate of growth of infinitesimal separations is δ(t) ~ δ(0) · eλt, so log δ grows linearly with slope λ (bits/s when using log₂, nats/s for ln). The simulation accumulates log₁₀|Δθ|_max over time, then fits a linear regression through the middle 75% of the history (discarding the initial transient and the saturation plateau). The slope × log₂(10) gives λ in bits/s. Positive λ confirms chaos; for regular initial conditions it converges toward zero.

Colour coding and stats

💧 Viscoelastic Fluid — Rheology of Polymer Materials

Viscoelasticity: the middle ground

Most real materials are neither purely elastic (springs that remember their shape) nor purely viscous (fluids that forget it). Polymers, hydrogels, biological tissues, silly putty and paint all show viscoelastic behaviour: they respond elastically to fast deformations (high Deborah number) and viscously to slow ones (low Deborah number). The Deborah number De = τR/tobs is the key dimensionless ratio, where τR = η/G₀ is the Maxwell relaxation time.

The three models and their equations

All three models describe a material element subject to stress σ and strain ε:

Particle simulation

The left canvas shows a 10×10 grid of mass points connected by Maxwell springs (spring G₀ in series with dashpot η). Each bond tracks its internal viscous extension Lv:

F = G₀_bond × (L − L₀ − Lv)       // spring force
dLv/dt = F / η_bond                 // dashpot relaxation (τR = η/G₀)
overdamped: ζ × v = ΣF_springs      // no inertia; instantaneous velocity

When you drag a particle, nearby bonds stretch (blue → red by stress magnitude) and then slowly relax back after you release. The overall blob behaviour is Maxwell-like: the faster you deform it, the stiffer it feels.

🎵 DFT & STFT Visualiser — From Sinusoids to Spectrograms

The Discrete Fourier Transform

Given N time-domain samples x[n], the DFT computes N complex coefficients:

X[k] = Σₙ x[n] · w[n] · e^{−j2πkn/N}    k = 0, 1, …, N/2

where w[n] is a window function. |X[k]| is the magnitude of the k-th frequency bin, with frequency fk = k · fs/N Hz. The visualiser computes this directly (O(N²)) for N ≤ 1024 at 60 fps — fast enough for real-time display.

Window functions and spectral leakage

Non-integer cycles in the DFT window cause energy to "leak" from sharp spectral peaks into neighbouring bins. The choice of window is a trade-off between main-lobe width (frequency resolution) and side-lobe level (leakage):

STFT spectrogram

The Short-Time Fourier Transform applies the DFT to successive overlapping frames: hop = N − overlap samples apart. The result is a 2D matrix: columns are time frames, rows are frequency bins. The simulation maintains a ring buffer of 460 columns (matching the canvas width) colourised with a viridis-like palette mapping DB value (−80…0) to dark blue → cyan → yellow.

Try the chirp preset (frequency sweeping 100 → 800 Hz over 1 second) and watch the diagonal yellow ridge sweep upward on the spectrogram. Then switch to the multi-tone preset and see the three horizontal lines corresponding to the fundamental and harmonics. Changing the window type while viewing a pure sine with the Rectangular window dramatically shows spectral leakage: frequency sidebands appear and disappear as you cycle through windows.

Signal types

Up Next

Wave 62 will continue expanding the library. Candidates under consideration include fluid dynamics simulations, statistical mechanics visualisations, and additional interactive physics demonstrations. Stay tuned.

← Devlog #80: Wave 60 All posts →