Gibbs Explorer

What a digital signal actually looks like
by Jordan Halase






Explanation

The Nyquist-Shannon Sampling Theorem states that any finite bandwidth analog signal can be converted to and from a digital representation perfectly. In this demo, sample points may be drawn manually while in "Capture" mode, and the underlying analog signal it encodes is displayed. When in "Time Shift" mode, the sample points are interpolated such that the underlying analog signal is shifted continuously in time. For coding simplicity, the signal is assumed to be periodic.

A sharp jump contains an infinite number of frequencies. The Sampling Theorem explicitly states that it only holds true for signals of finite bandwidth. When frequency content is removed from a signal, a rippling effect appears where the jumps were. The more frequencies removed, the wider the ripples, until eventually a sinusoid remains. This rippling effect is known as the Gibbs Phenomenon. It is important to know that this rippling is not a distortion, it is fundamentally what a signal of finite bandwidth is. Put another way, the ripples were always there, even for a sharp jump, but were canceled out by the infinite number of higher frequencies. When those higher frequencies were removed, the underlying ripples became visible.

Another explanation for the ripples is that every single signal in existence is secretly the sum of sinusoids at different frequencies. In fact, a sinusoid could be used as the definition of a single frequency. Sinusoids are smooth and ripply by nature, so to create an instantaneous jump from zero to one, an infinite number of sinusoids are required. When higher frequency sinusoids are removed, the ripples become visible.

To learn more about digital signals, the people at xiph.org have made a wonderfully easy-to-follow video series aimed toward absolute beginners which includes detailed graphics and animations.

Oddities at the Nyquist Frequency

You may have noticed in the demo that sometimes the shape of the underlying continuous signal changes after being captured. Why is this?

The Sampling Theorem states that in order to uniquely represent a frequency, at least two samples are required per cycle. The highest possible frequency therefore contains exactly two samples per cycle. This is known as the Nyquist frequency. The change in shape you may have noticed is due to ambiguities at the Nyquist frequency.

Take the signal [1, -1, 1, -1, ...] as an example. This signal is a single cosine wave at exactly the Nyquist frequency with two samples per cycle. If it is phase shifted in time by 60 degrees it becomes [0.5, -0.5, 0.5, -0.5, ...]. While that may still represent a cosine wave with magnitude 1 shifted by 60 degrees, it is indistinguishable from a cosine wave with magnitude 0.5 and no phase shift. If it were instead shifted by 90 degrees it would become [0, 0, ...] and would be indistinguishable from silence. It has been removed completely. When you draw an arbitrary signal it may contain some amount of the Nyquist frequency, and if it is time shifted by 1/2 of a sample it will cancel out. To see this happen more clearly, generate a Nyquist frequency in the demo and observe what happens when it is time shifted. Please note that if the Nyquist frequency is removed, the remaining frequencies remain completely unaffected and are still represented perfectly.

Digital Audio

It is a common misconception that digital audio is a stairstep pattern. When an analog source is sampled, it is first bandlimited to remove any frequencies above the Nyquist limit. For CD quality audio (44.1 kHz), all frequencies above 22.05 kHz are removed before sampling. Thus, the sampled signal is a perfect representation of the original bandlimited signal. The upper limit of human hearing is 20 kHz, and this decreases with age.

Mathematically speaking, the sampling process is perfect, although distortions do exist in the real world. CD quality audio uses a bit depth of 16 bits per sample, so the range of values is quantized to one of 216 possible values, and the values of the sample points may be off by up to 2-16. This adds distortion to the signal, but is very small, and still easily offers 96 dB of dynamic range, and can be further increased to 120 dB with dither. An absolute, mint condition vinyl record has around 70 dB of dynamic range, which decreases with use. If a CD is played back at the maximum safest loudness of 70 dBA, any quantization distortion will be lower than 26 dB below the threshold of human hearing.

Highly Advanced Explanation

This demo aims to communicate the unique underlying continuous signal encoded by a (periodic) digitally sampled signal. A periodic signal was chosen to simplify programming by leveraging the Fast Fourier Transform (FFT) for oversampling and sample shifting without the need to design windowed Finite Impulse Response (FIR) filters or sinc-based resamplers which have performance implications when run in web browsers on less powerful machines. It also serves to communicate the periodic nature of the Discrete Fourier Transform (DFT).

The sample points are translated into the frequency domain via the FFT. Time shifting is achieved in the frequency domain by construction of a "shift" spectrum.