This is a great question about the Nyquist-Shannon sampling theorem. I'll provide a comprehensive mathematical proof using frequency domain analysis. Let me structure this clearly:
- Define the problem
- Use the comb function to show sampling in frequency domain
- Show alias creation
- Prove perfect reconstruction is possible with proper sampling
- Provide visualizations
Let me work through this systematically.
Nyquist-Shannon Sampling Theorem
Statement: A bandlimited signal with maximum frequency B can be perfectly reconstructed from its samples if the sampling frequency is at least f_s ≥ 2B (Nyquist rate = 2B).
Part 1: Signal Sampling as Multiplication by Impulse Train
Let's say we have a continuous signal x(t) that is bandlimited to frequency B (meaning X(f) = 0 for |f| > B).
When we sample x(t) at times t_n = nT where T = 1/f_s is the sampling period, we get:
xs(t)=x(t)∑n=−∞∞δ(t−nT)
This is multiplication of x(t) by the Dirac comb (shah function):
IIIT(t)=∑n=−∞
Part 2: Frequency Domain Analysis
Taking the Fourier transform:
xs(t)=x(t)⋅IIIT
Using the convolution theorem, multiplication in time domain equals convolution in frequency domain:
Xs(f)=X(f)∗F{III
The Fourier transform of the Dirac comb is another Dirac comb:
F{IIIT(t)}=f
where f_s = 1/T is the sampling frequency.
Convolving with the impulse train creates periodic repetitions of the original spectrum:
Xs(f)=fs∑
This crucial result shows that sampling replicates the signal's spectrum at intervals of f_s, each scaled by the sampling frequency.
Part 3: No Aliasing Condition
To avoid spectral overlap and enable reconstruction, the copies must remain separated. Since the original spectrum spans [-B, B], adjacent replicas centered at ±f_s will occupy [-f_s - B, -f_s + B] and [f_s - B, f_s + B]. Preventing the original from merging with these neighbors requires the gap between them to remain non-negative: B ≤ f_s - B, which gives f_s ≥ 2B. This threshold is the Nyquist rate f_N = 2B, with the corresponding Nyquist frequency at B.
Perfect Reconstruction with Ideal Low-Pass Filter
When the sampling rate satisfies f_s ≥ 2B, an ideal low-pass filter can isolate the original spectrum from the replicas. Using a brick-wall filter with gain 1/f_s and cutoff frequency between B and f_s - B, the filter passes only the original spectrum while blocking all copies. Multiplying the sampled spectrum by this filter recovers X(f) exactly for |f| ≤ B, yielding perfect reconstruction x(t) = x_rec(t).
Sinc Interpolation
The ideal low-pass filter's impulse response is a sinc function, which provides an explicit formula for reconstructing the continuous signal from its samples.
For critical sampling where f_s = 2B, the impulse response becomes h(t) = sinc(πt/T), and the reconstructed signal is expressed as a weighted sum of sinc functions centered at each sample time:
x(t)=∑n=−∞∞x(nT)
This is the Whittaker-Shannon interpolation formula. The sinc functions satisfy the interpolation property where sinc(πn) equals 1 when n = 0 and 0 for all other integers, ensuring that x(mT) recovers the original sample values exactly.
When undersampling occurs (f_s < 2B), frequency domain copies overlap and high-frequency content folds back into the baseband, creating irreversible distortion that cannot be recovered through filtering.
Nyquist-Shannon Sampling Theorem: Complete Proof
1. Mathematical Framework
Signal Sampling as Impulse Train Multiplication
A continuous signal x(t) sampled at times t_n = nT (where T = 1/f_s) can be expressed as:
xs(t)=x(t)⋅∑
where III_T(t) is the Dirac comb (pulse train).
2. Frequency Domain: Key Proof
Taking Fourier transforms and using the convolution theorem:
Xs(f)=X(f)∗F{IIIT
The Fourier transform of the comb function is:
F{IIIT(t)}=f
Therefore:
Xs(f)=fs
This is the core equation: sampling creates copies of the spectrum at integer multiples of f_s.
3. Complete Python Visualization
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.fft import fft, fftfreq
# ============================================================
# PART 1: SIGNAL DEFINITION AND BANDWIDTH
# ============================================================
def create_bandlimited_signal(duration=2, f_max=50):
"""Create a bandlimited signal with max frequency f_max Hz."""
t = np.linspace(0, duration, 10000)
# Composite signal: 10 Hz + 30 Hz + 45 Hz components
x = np.sin(2*np.pi*10*t) + 0.5*np.sin(2*np.pi*30*t) + 0.3*np.sin(2*np.pi*45*t)
return t, x, f_max
t_cont, x_cont, B = create_bandlimited_signal(duration=0.5, f_max=50)
# Compute continuous spectrum (approximation)
dt = t_cont[1] - t_cont[0]
X_cont = np.fft.fft(x_cont)
f_cont = np.fft.fftfreq(len(x_cont), dt)
# ============================================================
# PART 2: PROPER SAMPLING (AT NYQUIST RATE)
# ============================================================
f_nyquist = 2 * B # Nyquist rate = 2 * bandwidth
T_nyquist = 1 / f_nyquist
# Sample at exactly Nyquist rate
n_samples_nyquist = int(t_cont[-1] / T_nyquist)
indices_nyquist = np.arange(n_samples_nyquist)
t_nyquist = indices_nyquist * T_nyquist
x_nyquist = np.sin(2*np.pi*10*t_nyquist) + \
0.5*np.sin(2*np.pi*30*t_nyquist) + \
0.3*np.sin(2*np.pi*45*t_nyquist)
# Compute sampled spectrum (DFT)
X_nyquist = np.fft.fft(x_nyquist, n=2048)
f_nyquist_fft = np.fft.fftfreq(2048, T_nyquist)
# ============================================================
# PART 3: UNDERSAMPLING (ALIASING DEMONSTRATION)
# ============================================================
f_under = 70 # Undersample at 70 Hz (< 2B = 100 Hz)
T_under = 1 / f_under
indices_under = np.arange(int(t_cont[-1] / T_under))
t_under = indices_under * T_under
x_under = np.sin(2*np.pi*10*t_under) + \
0.5*np.sin(2*np.pi*30*t_under) + \
0.3*np.sin(2*np.pi*45*t_under)
X_under = np.fft.fft(x_under, n=2048)
f_under_fft = np.fft.fftfreq(2048, T_under)
# ============================================================
# PART 4: OVERSAMPLING (SAFE SAMPLING)
# ============================================================
f_over = 300 # Oversample at 300 Hz (>> 2B)
T_over = 1 / f_over
indices_over = np.arange(int(t_cont[-1] / T_over))
t_over = indices_over * T_over
x_over = np.sin(2*np.pi*10*t_over) + \
0.5*np.sin(2*np.pi*30*t_over) + \
0.3*np.sin(2*np.pi*45*t_over)
X_over = np.fft.fft(x_over, n=2048)
f_over_fft = np.fft.fftfreq(2048, T_over)
# ============================================================
# VISUALIZATION
# ============================================================
fig, axes = plt.subplots(3, 2, figsize=(14, 12))
# Row 1: Nyquist Rate (f_s = 2B)
ax = axes[0, 0]
ax.plot(f_cont[:len(f_cont)//2], np.abs(X_cont[:len(X_cont)//2]),
'b-', alpha=0.7, linewidth=2, label='Original spectrum')
ax.axvline(B, color='r', linestyle='--', linewidth=2, label=f'Bandwidth B = {B} Hz')
ax.set_xlim([0, 150])
ax.set_title(f'Original Bandlimited Signal\n(Bandwidth B = {B} Hz)', fontsize=11, fontweight='bold')
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Magnitude')
ax.legend()
ax.grid(True, alpha=0.3)
ax = axes[0, 1]
ax.stem(t_nyquist[:20], x_nyquist[:20], basefmt=' ')
ax.plot(t_cont[:500], x_cont[:500], 'b-', alpha=0.3, label='Original signal')
ax.set_title(f'Nyquist Sampled: f_s = {f_nyquist} Hz = 2B\n✓ NO ALIASING',
fontsize=11, fontweight='bold', color='green')
ax.set_xlabel('Time (s)')
ax.set_ylabel('Amplitude')
ax.legend()
ax.grid(True, alpha=0.3)
ax.set_xlim([0, 0.1])
# Row 2: Undersampling (f_s < 2B)
ax = axes[1, 0]
# Show spectral copies for undersampled case
freq_range = np.linspace(-300, 300, 1000)
X_aliases = np.zeros_like(freq_range)
# Original spectrum
for f_idx, f in enumerate(freq_range):
if -B <= f <= B:
X_aliases[f_idx] += np.interp(f, f_cont[:len(f_cont)//2][::-1],
np.abs(X_cont[:len(X_cont)//2])[::-1])
X_aliases[f_idx] += np.interp(-f, f_cont[:len(f_cont)//2][::-1],
np.abs(X_cont[:len(X_cont)//2])[::-1])
# Aliases
for k in [-2, -1, 1, 2]:
f_shifted = f - k * f_under
if -B <= f_shifted <= B:
X_aliases[f_idx] += np.interp(f_shifted, f_cont[:len(f_cont)//2][::-1],
np.abs(X_cont[:len(X_cont)//2])[::-1])
ax.plot(freq_range, X_aliases, 'r-', linewidth=2)
ax.axvline(B, color='b', linestyle='--', linewidth=2, label=f'Bandwidth B')
ax.axvline(f_under/2, color='g', linestyle='--', linewidth=2, label=f'f_s/2 = {f_under/2} Hz')
ax.fill_between([0, B], -5, 100, alpha=0.1, color='blue', label='Signal band')
ax.fill_between([B, f_under/2], -5, 100, alpha=0.1, color='red', label='Alias band')
ax.set_xlim([0, 150])
ax.set_ylim([0, np.max(X_aliases)*1.5])
ax.set_title(f'ALIASING: f_s = {f_under} Hz < 2B\n✗ Spectral Copies OVERLAP',
fontsize=11, fontweight='bold', color='red')
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Magnitude')
ax.legend()
ax.grid(True, alpha=0.3)
ax = axes[1, 1]
ax.stem(t_under[:20], x_under[:20], basefmt=' ')
ax.plot(t_cont[:500], x_cont[:500], 'b-', alpha=0.3, label='Original signal')
ax.set_title(f'Undersampled: f_s = {f_under} Hz < 2B\n✗ ALIASES PRESENT',
fontsize=11, fontweight='bold', color='red')
ax.set_xlabel('Time (s)')
ax.set_ylabel('Amplitude')
ax.legend()
ax.grid(True, alpha=0.3)
ax.set_xlim([0, 0.1])
# Row 3: Oversampling (f_s >> 2B)
ax = axes[2, 0]
positive_mask = f_over_fft > 0
ax.plot(f_over_fft[positive_mask], np.abs(X_over[positive_mask]), 'g-', linewidth=2)
ax.axvline(B, color='r', linestyle='--', linewidth=2, label=f'Bandwidth B = {B} Hz')
ax.axvline(f_over/2, color='g', linestyle='--', linewidth=2, label=f'f_s/2 = {f_over/2} Hz')
ax.fill_between([0, B], 0, np.max(np.abs(X_over[positive_mask])),
alpha=0.1, color='blue', label='Signal band')
ax.fill_between([f_over/2-f_over/8, f_over/2], 0, np.max(np.abs(X_over[positive_mask])),
alpha=0.1, color='green', label='Guard band (alias-free)')
ax.set_xlim([0, 200])
ax.set_title(f'Oversampled: f_s = {f_over} Hz >> 2B\n✓ MAXIMUM SAFETY',
fontsize=11, fontweight='bold', color='green')
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Magnitude')
ax.legend()
ax.grid(True, alpha=0.3)
ax = axes[2, 1]
ax.stem(t_over[:50], x_over[:50], basefmt=' ')
ax.plot(t_cont[:500], x_cont[:500], 'b-', alpha=0.3, linewidth=2, label='Original signal')
ax.set_title(f'Oversampled: f_s = {f_over} Hz >> 2B\n✓ CLEAN RECONSTRUCTION',
fontsize=11, fontweight='bold', color='green')
ax.set_xlabel('Time (s)')
ax.set_ylabel('Amplitude')
ax.legend()
ax.grid(True, alpha=0.3)
ax.set_xlim([0, 0.05])
plt.tight_layout()
plt.savefig('nyquist_sampling.png', dpi=300, bbox_inches='tight')
plt.show()
print("=" * 70)
print("NYQUIST-SHANNON SAMPLING THEOREM ANALYSIS")
print("=" * 70)
print(f"\nSignal Specifications:")
print(f" • Bandwidth: B = {B} Hz")
print(f" • Nyquist Rate: f_N = 2B = {f_nyquist} Hz")
print(f" • Nyquist Frequency: f_N/2 = {f_nyquist/2} Hz")
print(f"\nSampling Rates Tested:")
print(f" 1. Nyquist Rate: f_s = {f_nyquist} Hz = 2B")
print(f" → Status: ✓ NO ALIASING (Critical sampling)")
print(f" 2. Undersampling: f_s = {f_under} Hz < 2B")
print(f" → Status: ✗ ALIASING OCCURS (f_s/2 = {f_under/2} Hz < B)")
print(f" 3. Oversampling: f_s = {f_over} Hz > 2B")
print(f" → Status: ✓ SAFE MARGIN (Guard band exists)")
4. Analytical Proof of No-Aliasing Condition
Spectral Overlap Criterion
For bandit-limited signal with X(f) = 0 for |f| > B:
Sampled spectrum contains copies at:
- Original: [−B, B]
- k = +1: [f_s − B, f_s + B]
- k = −1: [−f_s − B, −f_s + B]
For no overlap (no aliasing):
B≤fs−B
fs≥2B
This is the Nyquist criterion.
5. Perfect Reconstruction Theorem
Ideal Low-Pass Filter Recovery
Applying a brick-wall filter with cutoff f_c where B < f_c < f_s − B:
H(f)={1/fs
Yields:
Xrec(f)=Xs(f)⋅
Perfect time-domain reconstruction via sinc interpolation:
x(t)=n=−∞∑
6. Proof of Sinc Interpolation
The sinc function satisfies the orthogonality property:
sinc(n)={10n=
Verification at sample times:
x(mT)=∑n=−∞∞x(nT)
- When m = n: sinc(0) = 1 ✓
- When m ≠ n: sinc(π integer) = 0 ✓
7. Advanced Visualization: Aliasing Mechanism
# Detailed alias visualization
def plot_alias_folding():
"""Show how high frequencies fold back as low frequencies."""
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5))
# Undersampling case
f_s = 70 # Sampling rate
f = np.linspace(0, 150, 1000)
# True spectrum
B_true = 50
spectrum = np.where(f <= B_true, np.exp(-(f-30)**2/100) +
0.5*np.exp(-(f-45)**2/50), 0)
# Alias mapping
ax1.plot(f, spectrum, 'b-', linewidth=2.5, label='Original spectrum')
ax1.axvline(B_true, color='b', linestyle='--', alpha=0.5)
ax1.axvline(f_s/2, color='r', linestyle='--', linewidth=2, label=f'f_s/2 = {f_s/2} Hz')
# Show folding mechanism
for f_alias in f[f > f_s/2]:
f_folded = f_s - f_alias # Alias frequency
if 0 <= f_folded <= f_s/2:
ax1.arrow(f_alias, spectrum[np.argmin(np.abs(f - f_alias))]*0.8,
f_folded - f_alias, 0, head_width=0.3, head_length=5,
fc='red', ec='red', alpha=0.3)
ax1.fill_between(f[f <= f_s/2], 0, spectrum[f <= f_s/2],
alpha=0.2, color='blue', label='Valid band')
ax1.fill_between(f[f > f_s/2], 0, spectrum[f > f_s/2],
alpha=0.2, color='red', label='Folded band')
ax1.set_xlim([0, 150])
ax1.set_xlabel('Frequency (Hz)', fontsize=12)
ax1.set_ylabel('Magnitude', fontsize=12)
ax1.set_title('Alias Folding: How High Frequencies Map onto Low Frequencies',
fontsize=12, fontweight='bold')
ax1.legend(fontsize=11)
ax1.grid(True, alpha=0.3)
# Freq axis mapping
ax2.plot([0, 150], [0, 150], 'k--', alpha=0.3, label='Identity')
# Map showing aliasing
for k in [-2, -1, 0, 1, 2]:
f_original = np.linspace(0, 100, 100)
f_sampled = f_original + k*f_s
if k == 0:
ax2.plot(f_original, f_sampled, 'b-', linewidth=2.5, label='k=0 (original)')
else:
ax2.plot(f_original + k*f_s/2, f_sampled, '--', alpha=0.5, label=f'k={k}')
# Highlight Nyquist zone
ax2.fill_betweenx([0, 150], 0, f_s/2, alpha=0.1, color='green')
ax2.text(f_s/4, 120, 'Nyquist Zone', fontsize=11, ha='center',
bbox=dict(boxstyle='round', facecolor='green', alpha=0.3))
ax2.set_xlim([0, 150])
ax2.set_ylim([0, 150])
ax2.set_xlabel('Actual Frequency (Hz)', fontsize=12)
ax2.set_ylabel('Apparent Frequency (Hz)', fontsize=12)
ax2.set_title('Frequency Mapping Under Sampling', fontsize=12, fontweight='bold')
ax2.legend(fontsize=10)
ax2.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig('alias_folding.png', dpi=300, bbox_inches='tight')
plt.show()
plot_alias_folding()
8. Key Takeaways
| Condition | Sampling Rate | Result | Formula |
|---|
| Critical | f_s = 2B | Perfect reconstruction | Sinc interpolation |
| Oversample | f_s > 2B | Perfect + guard band | Extra filter design freedom |
| Undersample | f_s < 2B | ✗ IRREVERSIBLE aliasing | Irrecoverable information loss |
Summary of the Proof
- Sampling creates spectral copies at multiples of f_s
- No-aliasing requires B ≤ f_s/2 → f_s ≥ 2B
- Perfect recovery uses sinc interpolation with orthogonal property
- Undersampling is irreversible — high frequencies alias into signal band permanently
This completes the rigorous proof of the Nyquist-Shannon theorem! 🎯