Web Simulation 

 

 

 

 

Sampling Theorem (Nyquist-Shannon) Tutorial 

This interactive tutorial demonstrates the Nyquist-Shannon Sampling Theorem, a fundamental principle in signal processing that determines the minimum sampling rate required to accurately reconstruct a continuous signal from its samples. The Sampling Theorem states that a signal must be sampled at a rate at least twice its highest frequency component (the Nyquist rate) to avoid aliasing (frequency folding), which causes high-frequency components to appear as low-frequency artifacts in the reconstructed signal. The tutorial visualizes the sampling process through two interactive graphs: a time domain view showing the continuous signal, sample points, and reconstructed signal, and a frequency domain view showing the signal spectrum, Nyquist limit, and spectral copies (aliases).

The visualization displays three interactive graphs arranged vertically: (1) Time Domain Graph (top) - shows the continuous analog input signal (gray), discrete sample points (green dots with stems), and the reconstructed/alias signal (red or blue) plotted against time, demonstrating how undersampling creates aliasing where the reconstructed signal differs from the true signal, (2) Frequency Domain Graph (middle) - shows the signal spectrum with the input frequency (gray bar), Nyquist limit (yellow dashed line), spectral copies (ghost bars), and alias frequency (red bar when aliasing occurs), demonstrating the frequency folding effect that causes aliasing, (3) Reconstruction Process Graph (bottom) - shows how the reconstructed signal is built from individual Sinc functions (Whittaker-Shannon interpolation) or demonstrates the Zero-Order Hold (ZOH) method with staircase waveform and filtered output, depending on the selected reconstruction method. The graphs are rendered using HTML5 Canvas for real-time visualization with a dark theme (black background) and bright colors for optimal visibility. Real-time statistics display the current values of input frequency (f), sampling rate (fₛ), Nyquist limit (fₛ/2), and apparent frequency (the frequency of the alias signal).

The simulator implements the complete sampling process: True Signal: y(t) = A sin(2πft) (the continuous analog input signal with frequency f and amplitude A), Sampling: samples taken at discrete times t = n/fₛ (where n is an integer and fₛ is the sampling rate), Aliasing: apparent frequency = |f - k·fₛ| (where k is an integer, representing the principal alias when f > fₛ/2). The simulation supports two reconstruction methods: (1) Sinc (Whittaker-Shannon) - mathematical ideal reconstruction using Sinc interpolation, showing individual Sinc functions (yellow bold) and their sum (dotted red line), (2) Zero-Order Hold (ZOH) - practical hardware method showing the staircase waveform (blue) from a DAC and the filtered output (dashed red line) from a reconstruction filter. You can adjust the input frequency (f, range: 1-10 Hz), sampling rate (fₛ, range: 1-30 Hz), and simulation speed (range: 0.1x-5.0x) using sliders, and observe how lowering the sampling rate below the Nyquist limit (fₛ/2) causes aliasing. Control buttons allow you to Play (animate the waves), Pause, and Reset the simulation. An optional audio feature allows you to hear the aliasing effect (frequencies are multiplied by 100 for audio range: 100-1000 Hz).

NOTE : The tutorial uses standard signal processing notation: f (Input Frequency), fₛ (Sampling Rate), fₛ/2 (Nyquist Limit), Aliasing (frequency folding that occurs when f > fₛ/2). The simulation demonstrates the fundamental principle that signals must be sampled at least at twice their highest frequency (the Nyquist rate) to avoid aliasing. When aliasing occurs, high-frequency components are "folded back" into the baseband (0 to fₛ/2), creating false low-frequency components that cannot be distinguished from true low-frequency signals.

Mathematical Model

The Nyquist-Shannon Sampling Theorem is a fundamental result in signal processing that provides the theoretical foundation for converting continuous analog signals into discrete digital samples. The theorem states that a bandlimited signal (with no frequency components above fmax) can be perfectly reconstructed from its samples if the sampling rate fₛ satisfies: fₛ ≥ 2·fmax (the Nyquist criterion).

Sampling Process:

True Signal: y(t) = A sin(2πft) (Continuous analog signal)
Sample Points: y[n] = A sin(2πf·n/fₛ) (Discrete samples)
Reconstructed Signal: yr(t) = A sin(2πfaliast) (Reconstructed/alias signal)

where:

  • f: Input frequency (frequency of the analog signal, Hz)
  • fₛ: Sampling rate (number of samples per second, Hz)
  • fₛ/2: Nyquist limit (half the sampling rate, Hz)
  • falias: Apparent (alias) frequency (frequency of the reconstructed signal, Hz)
  • A: Signal amplitude (normalized to 1.0)
  • t: Time (seconds)
  • n: Sample index (integer)

Understanding the Terms:

True Signal (y(t) = A sin(2πft)): The continuous analog input signal is a sine wave with frequency f and amplitude A. This represents the "ideal" signal that we want to sample and reconstruct. In the time domain graph, this signal is drawn in gray as a smooth, continuous curve.

Sampling (y[n] = A sin(2πf·n/fₛ)): The continuous signal is sampled at discrete time points t = n/fₛ, where n is an integer. The sampling rate fₛ determines how frequently samples are taken. In the time domain graph, sample points are shown as green dots with vertical stems (connecting the sample value to the time axis), emphasizing the discrete nature of the samples.

Aliasing (falias = |f - k·fₛ|): When the input frequency f exceeds the Nyquist limit (fₛ/2), aliasing occurs. The apparent (alias) frequency is calculated as falias = |f - k·fₛ|, where k is an integer chosen to minimize the alias frequency (typically k = floor((f + fₛ/2) / fₛ)). This represents the "folding back" of high-frequency components into the baseband (0 to fₛ/2). In the frequency domain, aliasing is visualized as the input frequency bar crossing the Nyquist limit, with a corresponding alias frequency bar appearing on the left side (folded back).

Nyquist Limit (fₛ/2):

The Nyquist limit is half the sampling rate (fₛ/2). It represents the maximum frequency that can be accurately represented without aliasing. Frequencies below the Nyquist limit can be perfectly reconstructed from their samples, while frequencies above the Nyquist limit will be aliased (folded back) into the baseband. In the frequency domain graph, the Nyquist limit is shown as a yellow dashed vertical line labeled "Nyquist Limit".

Frequency Folding (Aliasing Mechanism):

Aliasing occurs through a process called frequency folding. When a signal with frequency f > fₛ/2 is sampled, the sampling process creates "spectral copies" (images) of the signal at frequencies fₛ - f, fₛ + f, 2fₛ - f, 2fₛ + f, etc. The spectral copy at fₛ - f (which is less than fₛ/2) "folds back" into the baseband, creating an alias at frequency falias = fₛ - f. This alias signal has the same sample values as the original signal but a different frequency, making it impossible to distinguish from a true low-frequency signal. In the frequency domain graph, spectral copies are shown as gray "ghost bars" at multiples of the sampling rate, and the alias frequency is highlighted in red when aliasing occurs.

Ideal Signal Reconstruction:

The simulation uses ideal signal reconstruction (sine wave interpolation) to visualize the alias signal. When no aliasing occurs (f ≤ fₛ/2), the reconstructed signal matches the true signal (both are drawn in blue, overlapping). When aliasing occurs (f > fₛ/2), the reconstructed signal is drawn as a sine wave at the alias frequency falias (shown in red), which passes through all the sample points but has a different frequency than the true signal. This ideal reconstruction makes the aliasing effect clearly visible, demonstrating how undersampling creates false low-frequency components.

Frequency Domain Visualization: The frequency domain graph shows the signal spectrum, with frequency on the horizontal axis (0 to 30 Hz) and amplitude on the vertical axis (0 to 1.0). The graph displays: (1) The input frequency (gray vertical bar labeled "True Signal"), (2) The Nyquist limit (yellow dashed vertical line labeled "Nyquist Limit"), (3) Spectral copies (gray "ghost bars" at frequencies fₛ ± f, 2fₛ ± f, etc.), (4) The alias frequency (red vertical bar labeled "Alias" when aliasing occurs). The frequency domain view clearly shows how aliasing occurs: when the input frequency exceeds the Nyquist limit, the corresponding spectral copy at fₛ - f folds back into the baseband, creating the alias frequency that matches the reconstructed signal in the time domain.

 

Usage Example

Follow these steps to explore the Sampling Theorem simulation:

  1. Initial State: When you first load the simulation, you'll see three graphs stacked vertically: (1) Time Domain Graph (top) - shows the continuous analog input signal (gray), discrete sample points (green dots with stems), and the reconstructed signal (blue, matching the true signal when no aliasing), (2) Frequency Domain Graph (middle) - shows the input frequency (gray bar), Nyquist limit (yellow dashed line), and spectral copies (gray ghost bars), (3) Reconstruction Process Graph (bottom) - shows the reconstruction method visualization (default: Sinc interpolation with individual Sinc functions in yellow and their sum in dotted red). Real-time statistics display the current values of f (input frequency), fₛ (sampling rate), fₛ/2 (Nyquist limit), and apparent frequency. Notice that with the default parameters (f = 5.0 Hz, fₛ = 15.0 Hz), the input frequency (5.0 Hz) is below the Nyquist limit (7.5 Hz), so no aliasing occurs and the reconstructed signal (blue) matches the true signal (gray).
  2. Observe No Aliasing: With the default parameters (f = 5.0 Hz, fₛ = 15.0 Hz), observe that: (1) The input frequency (5.0 Hz) is below the Nyquist limit (7.5 Hz), (2) The reconstructed signal (blue) overlaps the true signal (gray) in the time domain, (3) No alias frequency bar appears in the frequency domain, (4) The apparent frequency equals the input frequency (5.0 Hz), (5) No "ALIASING DETECTED" warning is displayed. This demonstrates correct sampling: the sampling rate (15.0 Hz) is more than twice the input frequency (5.0 Hz), satisfying the Nyquist criterion (fₛ ≥ 2f).
  3. Lower the Sampling Rate to Cause Aliasing: Gradually decrease the "Sampling Rate (fₛ)" slider from 15.0 Hz down toward 10.0 Hz. Observe what happens: (1) As you cross the Nyquist limit (when fₛ/2 < f), the reconstructed signal (red) separates from the true signal (gray) in the time domain, (2) The reconstructed signal now has a lower frequency (the alias frequency) than the true signal, (3) An alias frequency bar (red) appears in the frequency domain on the left side of the Nyquist limit, (4) The "ALIASING DETECTED" warning appears, (5) The apparent frequency changes from 5.0 Hz to a lower value (e.g., 5.0 Hz when fₛ = 10.0 Hz, the alias is |5.0 - 10.0| = 5.0 Hz, but typically it folds to |10.0 - 5.0| = 5.0 Hz). This demonstrates aliasing: undersampling causes high-frequency components to appear as low-frequency artifacts.
  4. Adjust Input Frequency: Use the "Input Frequency (f)" slider to change the input signal frequency (range: 1-10 Hz, default: 5.0 Hz). Observe how: (1) Changing the input frequency shifts the gray signal and green sample points in the time domain, (2) The input frequency bar (gray) moves in the frequency domain, (3) When f > fₛ/2, aliasing occurs and the alias frequency changes, (4) When f ≤ fₛ/2, no aliasing occurs and the reconstructed signal matches the true signal. Try setting f = 8.0 Hz with fₛ = 10.0 Hz: the Nyquist limit is 5.0 Hz, so aliasing occurs, and the alias frequency is |10.0 - 8.0| = 2.0 Hz (a low-frequency artifact).
  5. Use Play/Pause/Reset Controls: Click "Play" to animate the waves moving through time (phase shift). The animation helps visualize how the signals evolve and how sample points align with the signal values. Click "Pause" to freeze the animation for detailed observation. Click "Reset" to return to the initial state (time = 0, phase = 0). Use the "Simulation Speed" slider to control the animation speed (range: 0.1x to 5.0x, default: 1.0x). Lower values slow down the animation for detailed observation, while higher values speed it up. Use Play to see the dynamic behavior of the signals, especially useful for understanding how the reconstructed signal (red, when aliasing) differs from the true signal (gray).
  6. Select Reconstruction Method: Use the "Reconstruction Method" dropdown to choose between two reconstruction approaches: (1) Sinc (Whittaker-Shannon) - shows the mathematical ideal reconstruction using Sinc interpolation, displaying individual Sinc functions (yellow bold lines) centered at each sample point and their sum (dotted red line) that forms the reconstructed signal, demonstrating how the continuous signal is built from discrete samples using the Whittaker-Shannon interpolation formula, (2) Zero-Order Hold (ZOH) - shows the practical hardware method used in real DACs, displaying the staircase waveform (blue solid line) created by holding each sample value constant until the next sample, and the filtered output (dashed red line) that would result from passing the staircase through a reconstruction filter (low-pass filter), demonstrating how real hardware converts discrete samples back to continuous signals. The ZOH method shows the two-step process: first creating a "blocky" staircase (ZOH), then smoothing it with a filter. Switch between methods to compare the mathematical ideal (Sinc) with the practical hardware approach (ZOH).
  7. Understand the Frequency Domain: Focus on the Frequency Domain Graph (bottom) to understand aliasing visually: (1) The Nyquist limit (yellow dashed line at fₛ/2) divides the frequency range - frequencies below this limit can be accurately represented, frequencies above this limit will be aliased, (2) The input frequency (gray bar labeled "True Signal") represents the actual signal frequency, (3) Spectral copies (gray ghost bars) appear at frequencies fₛ ± f, 2fₛ ± f, etc., representing the "images" created by sampling, (4) When aliasing occurs (f > fₛ/2), the spectral copy at fₛ - f folds back into the baseband (0 to fₛ/2), creating the alias frequency (red bar), (5) A purple arrow shows the "folding" effect, connecting the input frequency to the alias frequency. This visualization clearly demonstrates why aliasing occurs: the sampling process creates spectral copies that overlap into the baseband when the input frequency exceeds the Nyquist limit.
  8. Experiment with Aliasing Cases: Try different combinations to observe various aliasing scenarios: (1) f = 8.0 Hz, fₛ = 10.0 Hz - Nyquist limit is 5.0 Hz, so aliasing occurs; alias frequency is 2.0 Hz (fₛ - f = 10.0 - 8.0 = 2.0 Hz), (2) f = 9.0 Hz, fₛ = 10.0 Hz - alias frequency is 1.0 Hz (10.0 - 9.0 = 1.0 Hz), showing how high frequencies fold to very low frequencies, (3) f = 7.0 Hz, fₛ = 15.0 Hz - Nyquist limit is 7.5 Hz, so f (7.0 Hz) < fₛ/2 (7.5 Hz), no aliasing occurs, (4) f = 8.0 Hz, fₛ = 15.0 Hz - aliasing occurs; alias frequency is 7.0 Hz (15.0 - 8.0 = 7.0 Hz). Each combination demonstrates different aspects of aliasing: how high frequencies fold to low frequencies, how the alias frequency depends on both f and fₛ, and how the Nyquist criterion determines whether aliasing occurs.
  9. Use Audio Feature (Optional): Click "🔊 Off" to enable audio (button changes to "🔊 On"). The audio feature multiplies frequencies by 100 to convert the visual frequency range (1-10 Hz) to an audible range (100-1000 Hz). When audio is enabled: (1) You hear a tone at the apparent (alias) frequency × 100, (2) As you lower the sampling rate below the Nyquist limit, the pitch drops dramatically (representing the alias), (3) This provides an auditory confirmation of aliasing - you can hear the high-frequency tone turn into a low-frequency rumble. Try: (1) Set f = 8.0 Hz, fₛ = 30.0 Hz (no aliasing), enable audio - you hear a high pitch (800 Hz), (2) Gradually lower fₛ to 10.0 Hz - as you cross the Nyquist limit, the pitch drops to a low rumble (200 Hz, representing the 2.0 Hz alias). The volume slider controls the audio output level (0-100%).
  10. Understand the Nyquist Criterion: The Nyquist-Shannon Sampling Theorem states that to avoid aliasing, the sampling rate must satisfy: fₛ ≥ 2f (the Nyquist criterion), where f is the highest frequency component in the signal. Equivalently, the signal frequency must satisfy: f ≤ fₛ/2 (the signal must be below the Nyquist limit). The simulation demonstrates this criterion: when f ≤ fₛ/2, no aliasing occurs and the signal can be perfectly reconstructed; when f > fₛ/2, aliasing occurs and the signal cannot be accurately reconstructed. The Nyquist limit (fₛ/2) represents the maximum frequency that can be accurately represented without aliasing - this is why anti-aliasing filters (low-pass filters with cutoff at fₛ/2) are used before sampling to remove frequency components above the Nyquist limit.
  11. Observe Real-Time Updates: Adjust any slider while the simulation is running (if Play is active). The simulation updates in real-time, immediately affecting the visualizations. Notice how: (1) Changing f shifts the input frequency bar and updates sample points, (2) Changing fₛ shifts the Nyquist limit line and updates sample spacing, (3) When aliasing occurs or stops, the reconstructed signal color changes (blue for no aliasing, red for aliasing), (4) The frequency domain graph updates immediately, showing spectral copies and alias frequencies, (5) Statistics update in real-time, showing current values and aliasing status. This real-time interaction helps you understand how each parameter affects the sampling process and aliasing.

Tip: The key to understanding the Sampling Theorem is recognizing the relationship between sampling rate and signal frequency. The Nyquist limit (fₛ/2) is the critical boundary: signals below this limit can be accurately sampled and reconstructed, while signals above this limit will be aliased (folded back) into the baseband. Start with default parameters to see correct sampling (no aliasing), then lower the sampling rate to observe aliasing - watch how the reconstructed signal (red) separates from the true signal (gray) in the time domain, and observe the frequency folding effect in the frequency domain. Use the audio feature to hear the aliasing effect: the pitch drops dramatically when aliasing occurs. Remember that the Nyquist criterion (fₛ ≥ 2f) must be satisfied to avoid aliasing - this is why anti-aliasing filters are essential in real-world sampling systems.

Parameters

Followings are short descriptions on each parameter
  • Input Frequency (f): The frequency of the continuous analog input signal (sine wave). Range: 1-10 Hz. Default: 5.0 Hz. Higher values represent higher-frequency signals. The input frequency determines the "true signal" that we want to sample and reconstruct. In the time domain, this is the gray continuous sine wave. In the frequency domain, this is the gray vertical bar labeled "True Signal". When f exceeds the Nyquist limit (fₛ/2), aliasing occurs. The parameter affects both the time domain signal shape and the frequency domain spectrum location.
  • Sampling Rate (fₛ): The number of samples taken per second. Range: 1-30 Hz. Default: 15.0 Hz. Higher values mean more frequent sampling (tighter spacing between samples). The sampling rate determines: (1) The Nyquist limit (fₛ/2), which is the maximum frequency that can be accurately represented, (2) The spacing between sample points in the time domain, (3) The locations of spectral copies in the frequency domain (at fₛ ± f, 2fₛ ± f, etc.). The Nyquist-Shannon Sampling Theorem requires fₛ ≥ 2f to avoid aliasing, meaning the sampling rate must be at least twice the input frequency.
  • Nyquist Limit (fₛ/2): Half the sampling rate, representing the maximum frequency that can be accurately represented without aliasing. Calculated as fₛ/2. For the default parameters (fₛ = 15.0 Hz), the Nyquist limit is 7.5 Hz. Frequencies below the Nyquist limit can be perfectly reconstructed from their samples, while frequencies above the Nyquist limit will be aliased (folded back) into the baseband. In the frequency domain graph, the Nyquist limit is shown as a yellow dashed vertical line labeled "Nyquist Limit". The Nyquist criterion requires that the input frequency f ≤ fₛ/2 to avoid aliasing.
  • Apparent Frequency (falias): The frequency of the reconstructed/alias signal. When no aliasing occurs (f ≤ fₛ/2), the apparent frequency equals the input frequency (falias = f). When aliasing occurs (f > fₛ/2), the apparent frequency is calculated as falias = |f - k·fₛ|, where k is an integer chosen to minimize the alias frequency (typically k = floor((f + fₛ/2) / fₛ), giving falias = fₛ - f). The apparent frequency represents the "ghost signal" that appears in the reconstructed output due to aliasing - it has the same sample values as the original signal but a different frequency. In the time domain, this is the red reconstructed signal (when aliasing) or blue signal (when no aliasing). In the frequency domain, this is the red alias frequency bar (when aliasing occurs).
  • True Signal: The continuous analog input signal, represented as y(t) = A sin(2πft) where A = 1.0 (amplitude) and f is the input frequency. In the time domain graph, the true signal is drawn as a gray continuous sine wave. In the frequency domain graph, the true signal is represented as a gray vertical bar at frequency f, labeled "True Signal". The true signal represents the "ideal" signal that we want to sample and reconstruct. When sampling is correct (f ≤ fₛ/2), the reconstructed signal matches the true signal. When aliasing occurs (f > fₛ/2), the reconstructed signal differs from the true signal, creating a false low-frequency component.
  • Sample Points: Discrete samples taken from the continuous signal at times t = n/fₛ, where n is an integer and fₛ is the sampling rate. In the time domain graph, sample points are shown as green dots with vertical stems (connecting the sample value to the time axis), emphasizing the discrete nature of the samples. The sample points are located exactly on the true signal curve, representing the values y[n] = A sin(2πf·n/fₛ). The spacing between samples is 1/fₛ seconds. Sample points are the "raw data" from which the signal must be reconstructed - aliasing occurs when these sample points are insufficient to uniquely determine the original signal frequency.
  • Reconstructed/Alias Signal: The signal reconstructed from the sample points using ideal sine wave interpolation. When no aliasing occurs (f ≤ fₛ/2), the reconstructed signal (blue) matches the true signal (gray), passing through all sample points with the correct frequency. When aliasing occurs (f > fₛ/2), the reconstructed signal (red) is a sine wave at the alias frequency falias, which also passes through all sample points but has a different frequency than the true signal. The reconstructed signal demonstrates the "ghost signal" that appears due to aliasing - it cannot be distinguished from a true low-frequency signal based on the samples alone. In the frequency domain, this corresponds to the alias frequency bar (red, when aliasing occurs).
  • Frequency Domain Spectrum: A visualization of the signal in the frequency domain, showing frequency on the horizontal axis (0 to 30 Hz) and amplitude on the vertical axis (0 to 1.0). The spectrum displays: (1) The input frequency (gray vertical bar labeled "True Signal"), (2) The Nyquist limit (yellow dashed vertical line at fₛ/2), (3) Spectral copies (gray "ghost bars" at frequencies fₛ ± f, 2fₛ ± f, etc.), representing the "images" created by the sampling process, (4) The alias frequency (red vertical bar labeled "Alias" when aliasing occurs). The frequency domain view clearly shows how aliasing occurs: when the input frequency exceeds the Nyquist limit, the corresponding spectral copy at fₛ - f folds back into the baseband (0 to fₛ/2), creating the alias frequency.
  • Spectral Copies (Images): Frequency domain representations of the "images" created by the sampling process. When a signal is sampled, the sampling process creates spectral copies (images) of the signal at frequencies fₛ ± f, 2fₛ ± f, 3fₛ ± f, etc. These copies are shown as gray "ghost bars" in the frequency domain graph. The spectral copy at fₛ - f (which is less than fₛ/2 when f > fₛ/2) "folds back" into the baseband, creating the alias frequency. This folding effect is the mathematical explanation for aliasing: the sampling process creates multiple frequency representations, and the one that falls into the baseband becomes the alias. A purple arrow shows the folding effect, connecting the input frequency to the alias frequency when aliasing occurs.
  • Audio Multiplier: A scaling factor (×100) used to convert visual frequencies (1-10 Hz) to audible frequencies (100-1000 Hz) for the optional audio feature. When audio is enabled, the apparent (alias) frequency is multiplied by 100 to generate an audible tone. For example, if the alias frequency is 2.0 Hz, the audio plays at 200 Hz (a low pitch). If the input frequency is 8.0 Hz and no aliasing occurs, the audio plays at 800 Hz (a high pitch). The audio feature provides an auditory confirmation of aliasing - you can hear the pitch drop dramatically when aliasing occurs, matching the visual "slow wave" (red reconstructed signal) in the time domain. The volume slider controls the audio output level (0-100%).
  • Reconstruction Method: The method used to reconstruct a continuous signal from discrete samples. The simulation supports two methods: (1) Sinc (Whittaker-Shannon) - mathematical ideal reconstruction using Sinc interpolation, where the reconstructed signal is the sum of Sinc functions centered at each sample point, demonstrating the theoretical foundation of perfect reconstruction, (2) Zero-Order Hold (ZOH) - practical hardware method used in real DACs, where each sample value is held constant until the next sample (creating a staircase waveform), then passed through a reconstruction filter to smooth the output. The ZOH method demonstrates how real hardware actually converts digital samples to analog signals. The reconstruction method can be selected using a dropdown in the control panel. Default: Sinc (Whittaker-Shannon).
  • Simulation Speed: A multiplier that controls the animation speed of the simulation (range: 0.1x to 5.0x, default: 1.0x). The speed parameter scales both the phase increment and time increment in the animation loop. Lower values (e.g., 0.1x) slow down the animation for detailed observation, while higher values (e.g., 5.0x) speed it up. The speed slider is located in the control panel with label and value display. Adjusting the speed does not affect the signal frequencies or sampling rate - it only controls how fast the animation progresses through time. Use slower speeds to carefully observe how sample points align with signal values, and faster speeds to quickly see long-term behavior.

Controls and Visualizations

Followings are short descriptions on each control
  • Input Frequency (f) Slider: Controls the frequency of the continuous analog input signal (range: 1-10 Hz, default: 5.0 Hz). Located in the control panel with label and value display. Higher values represent higher-frequency signals. The slider updates in real-time, immediately affecting: (1) The gray true signal in the time domain (higher frequency = more oscillations), (2) The input frequency bar (gray) in the frequency domain (moves to the right), (3) The sample point locations (green dots align with the signal), (4) The aliasing status (when f > fₛ/2, aliasing occurs). The parameter determines the "true signal" that we want to sample and reconstruct.
  • Sampling Rate (fₛ) Slider: Controls the number of samples taken per second (range: 1-30 Hz, default: 15.0 Hz). Located in the control panel with label and value display. Higher values mean more frequent sampling (tighter spacing between samples). The slider updates in real-time, immediately affecting: (1) The Nyquist limit (fₛ/2, yellow dashed line in frequency domain), (2) The spacing between sample points (green dots) in the time domain (more samples = tighter spacing), (3) The locations of spectral copies in the frequency domain (at fₛ ± f, 2fₛ ± f, etc.), (4) The aliasing status (when f > fₛ/2, aliasing occurs). The Nyquist-Shannon Sampling Theorem requires fₛ ≥ 2f to avoid aliasing.
  • Play Button: Starts or resumes the animation, making the waves move through time (phase shift). Located in the control panel. When clicked, the simulation animates continuously, updating the phase of the signals to show how they evolve over time. The animation helps visualize: (1) How the signals oscillate, (2) How sample points align with signal values at different phases, (3) How the reconstructed signal (red, when aliasing) differs from the true signal (gray) as they evolve. Use Play to see the dynamic behavior of the signals, especially useful for understanding aliasing.
  • Pause Button: Pauses the animation, freezing the current state. Located in the control panel. When clicked, the simulation stops at the current phase, allowing you to examine the graphs in detail, adjust parameters, or analyze the current signal values. The graphs remain visible with the current state. Use Pause to freeze the simulation for detailed observation, then Resume to continue.
  • Reset Button: Returns the simulation to the initial state (time = 0, phase = 0). Located in the control panel. When clicked, the simulation clears the animation state and resets to time t = 0 with phase = 0. The graphs are redrawn from the beginning. Use Reset to start over with new parameters or to return to a clean initial state.
  • Audio Toggle Button: Enables or disables the audio feature (button shows "🔊 Off" or "🔊 On"). Located in the control panel. When enabled, the simulation generates an audible tone at the apparent (alias) frequency × 100 (converting 1-10 Hz to 100-1000 Hz). The audio provides an auditory confirmation of aliasing - you can hear the pitch drop dramatically when aliasing occurs. Default state: Off (browsers block auto-playing audio, so user must enable it). The button toggles between "🔊 Off" (gray) and "🔊 On" (blue) states.
  • Reconstruction Method Dropdown: A dropdown menu that allows you to select the reconstruction method used to convert discrete samples back to a continuous signal. Options: (1) Sinc (Whittaker-Shannon) - mathematical ideal reconstruction using Sinc interpolation, (2) Zero-Order Hold (ZOH) - practical hardware method showing DAC output and filtered signal. Located in the control panel. When changed, the Reconstruction Process graph updates immediately to show the selected method. The Sinc method demonstrates the theoretical foundation of perfect reconstruction, while the ZOH method shows how real hardware actually works. Default: Sinc (Whittaker-Shannon).
  • Simulation Speed Slider: Controls the animation speed multiplier (range: 0.1x to 5.0x, default: 1.0x). Located in the control panel with label and value display. Higher values mean faster animation. The slider updates in real-time, immediately affecting the rate at which the phase and time progress in the animation. Lower values (e.g., 0.1x) slow down the animation for detailed observation of how signals evolve and how sample points align with signal values. Higher values (e.g., 5.0x) speed up the animation to quickly see long-term behavior. The speed parameter does not affect signal frequencies or sampling rates - it only controls animation speed. Use slower speeds to carefully study the reconstruction process, especially when observing the Sinc summation or ZOH staircase formation.
  • Volume Slider: Controls the audio output level (range: 0-100%, default: 50%). Located in the control panel with label and value display. Higher values mean louder audio. The slider updates in real-time, smoothly adjusting the audio gain to prevent clicking/popping sounds. Use the volume slider to adjust the audio level when the audio feature is enabled.
  • Time Domain Graph Canvas: Canvas displaying the time domain visualization showing the continuous analog input signal (gray), discrete sample points (green dots with stems), and the reconstructed/alias signal (blue when no aliasing, red when aliasing) plotted against time. The X-axis represents time (seconds), and the Y-axis represents amplitude (-1.0 to 1.0). The graph demonstrates how undersampling creates aliasing, where the reconstructed signal (red) differs from the true signal (gray) and has a lower frequency (the alias frequency). The graph scrolls horizontally as time progresses (when Play is active), maintaining a fixed time window.
  • Frequency Domain Graph Canvas: Canvas displaying the frequency domain visualization showing the signal spectrum with the input frequency (gray bar labeled "True Signal"), Nyquist limit (yellow dashed vertical line labeled "Nyquist Limit"), spectral copies (gray "ghost bars" at fₛ ± f, 2fₛ ± f, etc.), and alias frequency (red bar labeled "Alias" when aliasing occurs). The X-axis represents frequency (0 to 30 Hz), and the Y-axis represents amplitude (0 to 1.0). The graph clearly shows how aliasing occurs: when the input frequency exceeds the Nyquist limit, the corresponding spectral copy at fₛ - f folds back into the baseband (0 to fₛ/2), creating the alias frequency. A purple arrow shows the folding effect when aliasing occurs.
  • Reconstruction Process Graph Canvas: Canvas displaying the reconstruction process visualization, which changes based on the selected reconstruction method. When Sinc (Whittaker-Shannon) is selected: shows individual Sinc functions (yellow bold lines) centered at each sample point, and their sum (dotted red line) that forms the reconstructed signal, demonstrating how the continuous signal is mathematically built from discrete samples using Sinc interpolation. When Zero-Order Hold (ZOH) is selected: shows the sample points (green dots with stems), the staircase waveform (blue solid line) created by holding each sample value constant until the next sample (representing DAC output), and the filtered output (dashed red line) that would result from passing the staircase through a reconstruction filter (representing the final analog signal). The X-axis represents time (seconds), and the Y-axis represents amplitude (-1.0 to 1.0). This graph provides insight into the mathematical (Sinc) or practical (ZOH) process of signal reconstruction, showing how discrete samples are converted back to continuous signals.
  • Real-Time Statistics Display: Text overlay displaying current values of f (input frequency), fₛ (sampling rate), fₛ/2 (Nyquist limit), and apparent frequency in real-time. Located above the graphs. The statistics update continuously as parameters change, showing the current state of the system. When aliasing occurs (f > fₛ/2), a red "⚠️ ALIASING DETECTED" warning is displayed. The display format shows values rounded to one or two decimal places. Uses Courier New font with bright text on dark background for visibility.
  • Graph Colors and Labels: The time domain graph uses gray for the true signal (continuous), green for sample points (dots with stems), and blue/red for the reconstructed signal (blue when no aliasing, red when aliasing). The frequency domain graph uses gray for the input frequency and spectral copies, yellow for the Nyquist limit (dashed line), and red for the alias frequency (when aliasing occurs). A purple arrow shows the folding effect when aliasing occurs. Both graphs use a dark theme (black background) with bright colors for optimal visibility. Graph labels indicate axes and key elements (e.g., "True Signal", "Nyquist Limit", "Alias").

Key Concepts

  • Nyquist-Shannon Sampling Theorem: The fundamental theorem in signal processing that states a bandlimited signal (with no frequency components above fmax) can be perfectly reconstructed from its samples if the sampling rate fₛ satisfies: fₛ ≥ 2fmax (the Nyquist criterion). Equivalently, the signal frequency must satisfy: f ≤ fₛ/2 (the signal must be below the Nyquist limit). The theorem provides the theoretical foundation for converting continuous analog signals into discrete digital samples. When the Nyquist criterion is satisfied, the signal can be perfectly reconstructed using ideal interpolation (sinc function). When the criterion is violated, aliasing occurs, making accurate reconstruction impossible.
  • Aliasing: The phenomenon that occurs when a signal is sampled at a rate below the Nyquist rate (fₛ < 2f). Aliasing causes high-frequency components to be "folded back" into the baseband (0 to fₛ/2), creating false low-frequency components (aliases) that cannot be distinguished from true low-frequency signals. The alias frequency is calculated as falias = |f - k·fₛ|, where k is an integer chosen to minimize the alias frequency (typically k = floor((f + fₛ/2) / fₛ), giving falias = fₛ - f when f > fₛ/2). Aliasing is a fundamental problem in signal processing - once aliasing occurs, the original signal cannot be recovered from the samples. This is why anti-aliasing filters (low-pass filters with cutoff at fₛ/2) are essential before sampling to remove frequency components above the Nyquist limit.
  • Nyquist Limit (fₛ/2): Half the sampling rate, representing the maximum frequency that can be accurately represented without aliasing. The Nyquist limit divides the frequency range into two regions: (1) Baseband (0 to fₛ/2) - frequencies that can be accurately sampled and reconstructed, (2) Above Nyquist (fₛ/2 to fₛ) - frequencies that will be aliased (folded back) into the baseband. The Nyquist criterion requires that the input frequency f ≤ fₛ/2 to avoid aliasing. In the frequency domain, the Nyquist limit is shown as a yellow dashed vertical line. The Nyquist limit is also called the "Nyquist frequency" or "folding frequency" because frequencies above this limit "fold back" into the baseband.
  • Frequency Folding: The mechanism by which aliasing occurs. When a signal with frequency f > fₛ/2 is sampled, the sampling process creates "spectral copies" (images) of the signal at frequencies fₛ ± f, 2fₛ ± f, 3fₛ ± f, etc. The spectral copy at fₛ - f (which is less than fₛ/2 when f > fₛ/2) "folds back" into the baseband, creating an alias at frequency falias = fₛ - f. This folding effect is visualized in the frequency domain graph: when the input frequency (gray bar) exceeds the Nyquist limit (yellow dashed line), a corresponding alias frequency bar (red) appears on the left side of the Nyquist limit, and a purple arrow shows the "folding" connection. Frequency folding is the mathematical explanation for aliasing: the sampling process creates multiple frequency representations, and the one that falls into the baseband becomes the alias.
  • Spectral Copies (Images): Frequency domain representations of the "images" created by the sampling process. When a continuous signal is sampled at rate fₛ, the sampling process creates spectral copies (images) of the signal spectrum at frequencies fₛ ± f, 2fₛ ± f, 3fₛ ± f, etc. These copies are a mathematical consequence of the sampling process (related to the Poisson summation formula). In the frequency domain graph, spectral copies are shown as gray "ghost bars" at multiples of the sampling rate. The spectral copy at fₛ - f (which is less than fₛ/2 when f > fₛ/2) "folds back" into the baseband, creating the alias frequency. Understanding spectral copies is crucial for understanding aliasing: they show how the sampling process creates multiple frequency representations, and aliasing occurs when one of these copies overlaps with the baseband.
  • Signal Reconstruction: The process of recovering a continuous signal from its discrete samples. When the Nyquist criterion is satisfied (fₛ ≥ 2f), the signal can be perfectly reconstructed using ideal interpolation (sinc function, or sine wave interpolation for simple signals). When aliasing occurs (fₛ < 2f), perfect reconstruction is impossible because the samples are insufficient to uniquely determine the original signal frequency. The simulation supports two reconstruction methods: (1) Sinc (Whittaker-Shannon) Interpolation - the mathematical ideal, where the reconstructed signal is the sum of Sinc functions centered at each sample point, with each Sinc function having the form y = sampleValue × sinc(π × fₛ × (t - tₖ)), demonstrating the theoretical foundation of perfect reconstruction, (2) Zero-Order Hold (ZOH) - the practical hardware method, where a DAC holds each sample value constant until the next sample (creating a staircase waveform), then a reconstruction filter (low-pass filter) smooths the staircase to produce the final analog signal. The simulation uses ideal sine wave reconstruction in the time domain graph to visualize the alias signal: when no aliasing occurs, the reconstructed signal (blue) matches the true signal (gray); when aliasing occurs, the reconstructed signal (red) is a sine wave at the alias frequency, which passes through all sample points but has a different frequency than the true signal. The Reconstruction Process graph shows either the Sinc summation (mathematical ideal) or the ZOH staircase and filtered output (practical hardware), providing insight into both theoretical and practical reconstruction methods.
  • Anti-Aliasing Filters: Low-pass filters with cutoff frequency at fₛ/2 (the Nyquist limit) that are used before sampling to remove frequency components above the Nyquist limit, preventing aliasing. Anti-aliasing filters are essential in real-world sampling systems because: (1) Real signals often contain frequency components above the Nyquist limit, (2) Without anti-aliasing filters, these high-frequency components would be aliased, creating false low-frequency artifacts, (3) Once aliasing occurs, the original signal cannot be recovered. The simulation demonstrates the need for anti-aliasing filters: when the input frequency exceeds the Nyquist limit, aliasing occurs, and the original signal cannot be distinguished from the alias. In practice, anti-aliasing filters are implemented as analog low-pass filters before the ADC (Analog-to-Digital Converter) or as digital filters in oversampled systems.
  • Oversampling: Sampling at a rate significantly higher than the Nyquist rate (fₛ >> 2f). Oversampling provides several benefits: (1) Easier anti-aliasing filtering (wider transition band), (2) Reduced quantization noise (noise is spread over a wider bandwidth), (3) Better signal reconstruction (more samples per period). The simulation demonstrates oversampling implicitly: when fₛ is much larger than 2f, the sample points are very closely spaced, making signal reconstruction easier and more accurate. In the time domain, oversampling results in many sample points per signal period, clearly showing the signal shape. In practice, oversampling is commonly used in audio systems (e.g., 44.1 kHz sampling for 20 kHz audio signals, providing a 2.2× oversampling factor).
  • Applications: The Sampling Theorem has applications in many fields: (1) Digital Audio - CD audio uses 44.1 kHz sampling for 20 kHz audio signals (satisfying Nyquist), (2) Digital Communications - signal sampling in modems and wireless systems, (3) Image Processing - pixel sampling in digital cameras and displays, (4) Control Systems - sensor data acquisition and digital control, (5) Medical Imaging - MRI, CT scans, and ultrasound imaging, (6) Scientific Data Acquisition - oscilloscopes, spectrum analyzers, and data loggers. Understanding the Sampling Theorem is essential for designing any system that converts analog signals to digital form, ensuring that sampling rates are chosen appropriately to avoid aliasing.
  • Practical Considerations: Real-world sampling systems face several challenges beyond the theoretical Sampling Theorem: (1) Anti-Aliasing Filters - must be implemented before sampling to remove frequency components above fₛ/2, (2) Filter Imperfections - real filters have transition bands, so some margin is needed (typically sample at 2.2-2.5× the maximum frequency), (3) Quantization Noise - digital samples have finite precision, introducing quantization error, (4) Jitter - sample timing uncertainty causes phase noise, (5) Non-Ideal Reconstruction - practical DACs use zero-order hold or linear interpolation instead of ideal sinc interpolation. The simulation uses ideal reconstruction to clearly demonstrate aliasing, but real systems must account for these practical limitations.