The sampling theorem tells us how to convert a continuous signal into a set of samples without losing information. It helps us understand how often we need to measure a signal to keep it accurate.
Sampling theorem (Nyquist-Shannon) in Signal Processing
Fs >= 2 * Fmax where: Fs = Sampling frequency (how often we take samples) Fmax = Highest frequency in the signal
The sampling frequency must be at least twice the highest frequency present in the signal.
If sampling is done below this rate, the signal can be distorted (called aliasing).
Fmax = 1000 # highest frequency in Hz Fs = 2 * Fmax # minimum sampling frequency print(Fs) # Output: 2000
Fs = 1500 Fmax = 1000 if Fs >= 2 * Fmax: print("Sampling frequency is sufficient.") else: print("Sampling frequency is too low, aliasing may occur.")
This program shows a 5 Hz sine wave sampled at three different rates: below, at, and above the Nyquist rate (which is 10 Hz here). The plot helps visualize how undersampling causes distortion, while sampling at or above the Nyquist rate captures the signal correctly.
import numpy as np import matplotlib.pyplot as plt # Define a continuous signal: a sine wave with frequency 5 Hz f = 5 # frequency in Hz T = 1 # duration in seconds t_continuous = np.linspace(0, T, 1000) # continuous time points signal_continuous = np.sin(2 * np.pi * f * t_continuous) # Sampling frequency less than Nyquist rate (undersampling) Fs_low = 8 # sampling frequency in Hz (less than 2*f=10) n_samples_low = int(Fs_low * T) t_samples_low = np.linspace(0, T, n_samples_low, endpoint=False) samples_low = np.sin(2 * np.pi * f * t_samples_low) # Sampling frequency equal to Nyquist rate Fs_nyquist = 2 * f # 10 Hz n_samples_nyquist = int(Fs_nyquist * T) t_samples_nyquist = np.linspace(0, T, n_samples_nyquist, endpoint=False) samples_nyquist = np.sin(2 * np.pi * f * t_samples_nyquist) # Sampling frequency higher than Nyquist rate Fs_high = 20 # 20 Hz n_samples_high = int(Fs_high * T) t_samples_high = np.linspace(0, T, n_samples_high, endpoint=False) samples_high = np.sin(2 * np.pi * f * t_samples_high) # Plotting plt.figure(figsize=(10, 6)) plt.plot(t_continuous, signal_continuous, label='Continuous Signal', color='black') plt.stem(t_samples_low, samples_low, linefmt='r-', markerfmt='ro', basefmt='r-', label='Undersampling (8 Hz)') plt.stem(t_samples_nyquist, samples_nyquist, linefmt='g-', markerfmt='go', basefmt='g-', label='Nyquist Rate (10 Hz)') plt.stem(t_samples_high, samples_high, linefmt='b-', markerfmt='bo', basefmt='b-', label='Oversampling (20 Hz)') plt.title('Sampling Theorem (Nyquist-Shannon) Example') plt.xlabel('Time (seconds)') plt.ylabel('Amplitude') plt.legend() plt.grid(True) plt.show()
Sampling below the Nyquist rate causes aliasing, which means the signal looks like a different frequency.
In practice, signals are often filtered to remove frequencies above half the sampling rate before sampling.
Nyquist rate is the theoretical minimum; sampling faster can improve quality and simplify processing.
The sampling theorem tells us how often to measure a signal to keep all information.
Sampling frequency must be at least twice the highest frequency in the signal.
Sampling below this rate causes errors called aliasing.
Practice
Solution
Step 1: Understand the sampling theorem
The Nyquist-Shannon theorem says to sample at least twice the highest frequency to capture all information.Step 2: Identify correct sampling rate
Sampling below twice the highest frequency causes aliasing and loss of information.Final Answer:
Sample at least twice the highest frequency of the signal -> Option DQuick Check:
Sampling rate ≥ 2 x highest frequency [OK]
- Thinking sampling rate can be less than highest frequency
- Confusing sampling rate with signal frequency
- Ignoring aliasing effects
fs?Solution
Step 1: Recall Nyquist frequency formula
The Nyquist frequency is half the sampling rate, so nyquist = fs / 2.Step 2: Match formula to options
Only nyquist = fs / 2 correctly divides fs by 2.Final Answer:
nyquist = fs / 2 -> Option AQuick Check:
Nyquist frequency = sampling rate / 2 [OK]
- Multiplying instead of dividing by 2
- Confusing Nyquist frequency with sampling rate
- Using addition or reciprocal incorrectly
highest_freq = 500 sampling_rate = ?
Solution
Step 1: Apply Nyquist theorem to highest frequency
Minimum sampling rate = 2 x highest frequency = 2 x 500 = 1000 Hz.Step 2: Compare with options
Only sampling_rate = 1000 matches 1000 Hz.Final Answer:
sampling_rate = 1000 -> Option AQuick Check:
Minimum sampling rate = 2 x 500 = 1000 [OK]
- Choosing sampling rate equal to highest frequency
- Selecting a rate less than twice the frequency
- Confusing frequency units
fs = 800
nyquist = fs * 0.5
print("Nyquist frequency is", nyquist)Solution
Step 1: Understand calculation of Nyquist frequency
Nyquist frequency = sampling rate divided by 2, which equals fs * 0.5.Step 2: Check code correctness
Code multiplies fs by 0.5 correctly and prints the value 400.0.Final Answer:
The code is correct and will print 400.0 -> Option CQuick Check:
fs * 0.5 = 400.0, print works fine [OK]
- Thinking multiplication by 0.5 is wrong
- Assuming variable case matters here
- Believing print syntax is incorrect in Python 3
Options:
A) No problem, sampling rate is sufficient
B) Aliasing will occur because sampling rate is less than twice highest frequency
C) Aliasing will occur because sampling rate is more than twice highest frequency
D) Signal will be perfectly reconstructed without aliasing
Solution
Step 1: Calculate minimum sampling rate needed
Minimum sampling rate = 2 x 1200 Hz = 2400 Hz.Step 2: Compare given sampling rate with minimum
Given sampling rate is 2000 Hz, which is less than 2400 Hz, so aliasing will occur.Step 3: Understand aliasing cause
Sampling below twice the highest frequency causes signal distortion called aliasing.Final Answer:
Aliasing will occur because sampling rate is less than twice highest frequency -> Option BQuick Check:
Sampling rate < 2 x highest frequency causes aliasing [OK]
- Assuming 2000 Hz is enough for 1200 Hz signal
- Confusing aliasing cause with oversampling
- Thinking aliasing occurs when sampling rate is too high
Ready to prove it?
Pass the test and this pattern moves unknown
