This note provides an interactive laboratory for visualizing Signal Resampling: the relationship between a continuous-world signal and its discrete representations. The simulation emphasizes aliasing in downsampling and interpolation in reconstruction.
The lab has two tabs: Basic (synthetic signals with a signal preset dropdown: composite sine, pure sine, square, triangle, sawtooth, harmonics, chirp, DC pulse, noise) and Application (real audio from the audio_data subdirectory or your own WAV upload). You can change the downsampling factor (M), upsampling factor (L), and reconstruction method (zero-stuffing, zero-order hold, linear, sinc). A pre-alias filter option shows how low-pass filtering before decimation reduces aliasing. Each plot has zoom, pan, and home toolbar buttons; Play buttons let you hear the original and reconstructed signals.
Math behind the Simulation
1. Original Signal
In the Basic tab, the signal is chosen from a Signal preset dropdown. The default is a composite wave: x(t) = sin(2πf0t) + 0.5 sin(2π 2.5 f0t + 0.3). Other presets include pure sine, square, triangle, sawtooth, sum of harmonics, chirp, DC pulse, and white noise. The base frequency f0 (cycles per window) is adjustable. In the Application tab, the source is a real audio file (WAV) from the audio_data folder or an uploaded file.
2. Downsampling (Decimation) by M
We keep every M-th sample: y[n] = x[nM]. The effective sample rate becomes 1/M of the original. If the original contains frequencies above the new Nyquist limit (half of the new rate), those components alias (fold back) into lower frequencies. An optional pre-alias low-pass filter (simple one-pole) can be applied before decimation to bandlimit the signal and reduce aliasing.
3. Upsampling by L and Zero-Stuffing
Upsampling inserts L−1 zeros between each sample. In the frequency domain, this creates L−1 images of the spectrum. To recover a smooth signal, we must interpolate (or equivalently, low-pass filter) the zero-stuffed sequence.
4. Reconstruction (Interpolation) Methods
- Zero-stuffing (none): Only the retained samples are shown; no interpolation.
- Zero-order hold (ZOH): Each sample value is held constant until the next sample (staircase).
- Linear: Linear interpolation between adjacent samples: y(t) = x[n](1 − τ) + x[n+1]τ, where τ is the fractional part of the index.
- Sinc (Whittaker–Shannon): Ideal bandlimited reconstruction: y(t) = Σn x[n] sinc(t − n), with sinc(x) = sin(πx)/(πx). A Hamming-windowed sinc kernel (finite support) is used to avoid infinite summation and reduce Gibbs ringing.
5. Nyquist and Aliasing
If the highest frequency in the signal exceeds half the (effective) sample rate, aliasing occurs: high frequencies fold back and appear as lower frequencies. The simulation turns the sampled signal and the "Aliasing" indicator red when the downsampling factor is large and the pre-alias filter is off.
Usage
Use the Basic and Application tabs and the controls to explore downsampling, upsampling, and reconstruction:
-
Tabs: Basic uses synthetic signals (with a preset dropdown). Application uses real audio: select a category (e.g. left) and a file from
audio_data, or upload your own WAV.
-
Signal preset (Basic): Choose the waveform shape: Composite sine (default), Pure sine, Square, Triangle, Sawtooth, Sum of harmonics, Chirp, DC pulse, or White noise.
-
Downsample factor (M): Set M > 1 to keep every M-th sample. With M large (e.g. 8–16), turn off the pre-alias filter to see aliasing (label turns red).
-
Pre-alias filter: Checkbox to apply a simple low-pass before decimation; reduces aliasing.
-
Upsample factor (L): Effective rate = L/M. The upsampled (zero-stuffed) plot shows L−1 zeros between samples; reconstruction interpolates over them.
-
Interpolation method: Zero-stuffing (none), Zero-order hold, Linear, Sinc. Sinc gives the smoothest reconstruction; ZOH shows the staircase.
-
Base frequency (Basic): Slider for cycles per window. Higher frequency content is more susceptible to aliasing when M is large.
-
Zoom / Pan / Home: Each plot has a toolbar: zoom (click or scroll), pan (drag), home (reset view).
-
Play: Use the Play buttons on the original and reconstructed plots to hear the signal (Basic: looped synthetic; Application: actual audio at file sample rate).
-
Spectrum (Basic): Toggle "Show spectrum" to see FFT magnitude of original (green) and reconstructed (yellow). Application tab always shows spectrum comparison.
Visualizations
- Original continuous signal / Original audio waveform: The source signal (green) on a dark grid. In Application tab this is the loaded WAV.
- Sampled discrete signal (stems): Vertical stems at sample values (cyan when safe, red when aliasing risk).
- Upsampled signal (zero-stuffed): Stems with L−1 zeros between each downsampled value (magenta).
- Reconstructed output: Yellow curve is the interpolated signal; grey overlay is the original for comparison. MSE is in the info box.
- Spectrum (magnitude) / Spectrum comparison: FFT magnitude of original and reconstructed. All plots support zoom, pan, and home.
Controls
- Basic tab: Signal preset (dropdown), Downsample (M), Upsample (L), Interpolation, Base frequency, Pre-alias filter, Show spectrum. Each chart: Zoom, Pan, Home, and Play (where shown).
- Application tab: Audio source (category + file select) or file upload; Downsample (M), Upsample (L), Interpolation, Pre-alias filter. Same chart toolbars and Play on original/reconstructed.
Info box
- Effective rate: L/M.
- Samples (after down) / Original samples: Sample counts.
- Reconstruction MSE: Mean squared error between original and reconstructed.
- Aliasing: Yes/No (red when risk). Application tab also shows sample rate.