Lesson 2 of 15
Sampling and the Nyquist Theorem
Sampling and the Nyquist Theorem
Digital signals are created by sampling a continuous signal at discrete time steps. The sampling rate (in Hz) determines what frequencies can be faithfully captured.
The Nyquist–Shannon Sampling Theorem
To perfectly reconstruct a signal with highest frequency , the sampling rate must satisfy:
The Nyquist rate is the minimum sufficient rate:
Example: CD audio captures frequencies up to 22,050 Hz, so it uses Hz — exactly the Nyquist rate.
Aliasing
When a signal is sampled below the Nyquist rate, aliasing occurs: high-frequency components are "folded" into lower frequencies and become indistinguishable from them.
A frequency sampled at rate aliases to:
Example: A 1300 Hz tone sampled at 1000 Hz aliases to Hz.
Your Task
Implement:
nyquist_rate(f_max)— returnsaliased_frequency(f, fs)— returns the aliased frequency when is sampled at
def nyquist_rate(f_max):
return 2 * f_max
def aliased_frequency(f, fs):
return abs(f - round(f / fs) * fs)
print(nyquist_rate(22050)) # 44100
print(aliased_frequency(1300, 1000)) # 300Python runtime loading...
Loading...
Click "Run" to execute your code.