Nyquist-Shannon Sampling Theorem

Understand sampling requirements, aliasing, and the Nyquist rate for digital signal processing

Try these examples:

Nyquist-Shannon Sampling Theorem

To accurately reconstruct a signal, the sampling rate must be at least twice the highest frequency present. This principle governs all digital signal processing.

Signal and Sampling Parameters

Signal frequency fsigf_{\text{sig}}: 1000 Hz

Sampling rate fsf_s: 8000 Hz

The Nyquist Criterion

For maximum frequency fmax⁡f_{\max} the Nyquist rate is:

fs≥2fmax⁡f_s \geq 2 f_{\max}

Your signal at 1000 Hz requires at least 2,000 Hz. Currently sampling at 8000 Hz:

Properly sampled -- no aliasing will occur.

Frequency Folding (apparent frequency after sampling)

your signal0102001234True signal frequency (kHz)Apparent frequency (kHz)fs/2 (Nyquist frequency)No aliasing (apparent = true)

Sampling at fsf_s cannot tell a frequency ff from f±fsf \pm f_s, f±2fsf \pm 2f_s, and so on, so every true frequency is seen somewhere between 0 and fs/2f_s/2. Up to fs/2f_s/2 = 4 kHz the apparent frequency follows the dotted diagonal; beyond it the zigzag folds back down. Your 1000 Hz tone is read as 1,000 Hz.

What the Samples See

The Samples and the Wave They Fit

0510-101Sample number n (time = n / fs)AmplitudeTrue signalSamples

The stems are the samples, one every 1/fs1/f_s seconds, taken from the grey wave. No slower wave fits these samples, so the signal can be rebuilt from them. Slide 8000 below 2,000 Hz and a slower dashed wave appears that fits the same dots.

MetricValue
Nyquist rate2,000 Hz
Samples per period8
Aliased frequency1,000 Hz

Aliasing

When fs<2fmax⁡f_s < 2 f_{\max}, high frequencies fold back as lower frequencies. The aliased frequency is:

falias=∣fsig−k⋅fs∣f_{\text{alias}} = \left| f_{\text{sig}} - k \cdot f_s \right|

where kk places faliasf_{\text{alias}} in [0,  fs/2][0,\; f_s/2].

Waveform Resolution

With 8 samples per period:

Good resolution -- waveform shape is recognizable.

Even above the Nyquist rate, more samples per period improve reconstruction. Most practical systems oversample at 2.5×2.5\times to 4×4\times the Nyquist rate. Try dragging fsf_s = 8000 to 4 times your signal frequency and compare the metrics.

Reconstruction

A band-limited signal x(t)x(t) with X(f)=0X(f)=0 for ∣f∣>fmax⁡|f|>f_{\max} can be perfectly recovered from its samples when fs≥2fmax⁡f_s \geq 2f_{\max}:

x(t)=∑n=−∞∞x[n]  sinc ⁣(t−nTsTs)x(t) = \sum_{n=-\infty}^{\infty} x[n] \;\text{sinc}\!\left(\frac{t - nT_s}{T_s}\right)

Before sampling, an anti-aliasing filter removes frequencies above fs/2f_s/2. After reconstruction, the formula above fills in the gaps -- but only if the Nyquist criterion is met. Drag 1000 and 8000 to confirm where the boundary lies for your signal.

Try it in Code

f_sig = 1000  # Signal frequency (Hz)
f_s   = 8000     # Sampling rate (Hz)

nyquist_rate = 2 * f_sig
samples_per_period = f_s / f_sig

# Aliased frequency when undersampled
if f_s < nyquist_rate:
    k = round(f_sig / f_s)
    f_alias = abs(f_sig - k * f_s)
else:
    f_alias = f_sig

print(f"Nyquist rate: {nyquist_rate} Hz")
print(f"Samples per period: {samples_per_period:.2f}")
print(f"Status: {'Properly sampled' if f_s >= nyquist_rate else 'ALIASED'}")
print(f"Apparent frequency: {f_alias} Hz")

What to explore next

You might also like