XKCD's Fourier Joke Falls Apart Once You Remember the Gibbs Phenomenon

Xkcd and Fourier

XKCD's Fourier Joke Falls Apart Once You Remember the Gibbs Phenomenon

Dr. Drang reacts to XKCD #3317, which applies Fourier series to a square wave. He notes that anyone who has worked with Fourier approximations has three reactions: first a smile of recognition, then a "wait a minute" as they recall that the Gibbs phenomenon never shrinks with more terms—it just concentrates at the corners. The ringing persists, as a 99-term plot shows. Finally, overthinking ruins the joke.

Finally, you realized that thinking like this ruins the joke.
  1. bmacho

    > First, of course, was a smile of recognition. Then came a “wait a minute” as you realized that the Gibbs phenomenon doesn’t get smaller as you add more terms to the Fourier expansion;

    Actually, it gets. Gibbs phenomenon is an artifact of a very specific algorithm on very specific inputs. It doesn't say nothing on "approximation of square waves with sine waves" in general, and arguably, it doesn't appear meaningfully in any types of approximation.

    You can approximate a square wave with sine waves with arbitrary precision in most approximations (L1, L2, pointwise etc). What you can't do is to have the largest error less than half the jump at discontiunity, but it is because sum of sine waves is continuous. There is no overshoot or Gibbs of any sort.

  2. TeMPOraL

    If you've ever used an oscilloscope to look at a square wave in electronics, or did any audio synthesis, you look at the ending of the post and raise an eyebrow (in the way Spock does it), and note that yes, this is what square waves are in real life. The corner wobble is normal.

  3. tristanj

    In order for this to work, you'd need to know the direction of the observer you're targeting, since the relative phases/amplitudes of gravitational waves would only cancel out in some directions and not others.

  4. josselex

    If you low pass filter, which any detector will do, it should go away.

  5. nukanse

    Sin cos are exponentials. There is a shorter way to create a square wave function: take a tiny base 0<b<1, and any initial function 0<f(x)<1

    Iterate b^f(x), and it produce a square wave with smooth corners

More from this day

2026-11-26