Bird
Raised Fist0
Signal Processingdata~10 mins

Sampling theorem (Nyquist-Shannon) in Signal Processing - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the Nyquist frequency given a sampling rate.

Signal Processing
sampling_rate = 1000  # in Hz
nyquist_freq = sampling_rate / [1]
Drag options to blanks, or click blank then click option'
A4
B2
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by 3 or other numbers instead of 2.
Multiplying instead of dividing.
2fill in blank
medium

Complete the code to check if a signal frequency is below the Nyquist frequency.

Signal Processing
signal_freq = 400  # in Hz
sampling_rate = 1000  # in Hz
nyquist_freq = sampling_rate / 2
is_valid = signal_freq [1] nyquist_freq
Drag options to blanks, or click blank then click option'
A>
B==
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or equal operators.
Checking equality instead of less than.
3fill in blank
hard

Fix the error in the code to compute the minimum sampling rate for a given max frequency.

Signal Processing
max_freq = 450  # in Hz
min_sampling_rate = max_freq * [1]
Drag options to blanks, or click blank then click option'
A0.5
B3
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.5 or 1 instead of 2.
Multiplying by 3 which is unnecessarily high.
4fill in blank
hard

Fill both blanks to create a dictionary mapping frequencies to a boolean indicating if they meet Nyquist criteria.

Signal Processing
frequencies = [100, 300, 600, 800]
sampling_rate = 1600
nyquist_freq = sampling_rate / 2
validity = {freq: freq [1] nyquist_freq for freq in frequencies if freq [2] nyquist_freq}
Drag options to blanks, or click blank then click option'
A<=
B>
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than operators which exclude valid frequencies.
Using less than or equal which might include edge cases.
5fill in blank
hard

Fill all three blanks to create a dictionary with frequency keys and boolean values showing if sampling rate is sufficient.

Signal Processing
frequencies = [200, 500, 900]
sampling_rate = 1800
nyquist_freq = sampling_rate / [1]
result = {freq: sampling_rate [2] freq * [3] for freq in frequencies}
Drag options to blanks, or click blank then click option'
A3
B>=
C2
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for division.
Using less than instead of greater than or equal.

Practice

(1/5)
1. What does the Nyquist-Shannon sampling theorem state about the sampling rate?
easy
A. Sample at the same rate as the highest frequency
B. Sample at half the highest frequency of the signal
C. Sample at any random rate
D. Sample at least twice the highest frequency of the signal

Solution

  1. Step 1: Understand the sampling theorem

    The Nyquist-Shannon theorem says to sample at least twice the highest frequency to capture all information.
  2. Step 2: Identify correct sampling rate

    Sampling below twice the highest frequency causes aliasing and loss of information.
  3. Final Answer:

    Sample at least twice the highest frequency of the signal -> Option D
  4. Quick Check:

    Sampling rate ≥ 2 x highest frequency [OK]
Hint: Remember: sample rate must be double highest frequency [OK]
Common Mistakes:
  • Thinking sampling rate can be less than highest frequency
  • Confusing sampling rate with signal frequency
  • Ignoring aliasing effects
2. Which of the following is the correct Python syntax to calculate the Nyquist frequency for a signal with sampling rate fs?
easy
A. nyquist = fs / 2
B. nyquist = fs * 2
C. nyquist = 2 / fs
D. nyquist = fs + 2

Solution

  1. Step 1: Recall Nyquist frequency formula

    The Nyquist frequency is half the sampling rate, so nyquist = fs / 2.
  2. Step 2: Match formula to options

    Only nyquist = fs / 2 correctly divides fs by 2.
  3. Final Answer:

    nyquist = fs / 2 -> Option A
  4. Quick Check:

    Nyquist frequency = sampling rate / 2 [OK]
Hint: Nyquist frequency is half the sampling rate [OK]
Common Mistakes:
  • Multiplying instead of dividing by 2
  • Confusing Nyquist frequency with sampling rate
  • Using addition or reciprocal incorrectly
3. Given a signal with highest frequency 500 Hz, what is the minimum sampling rate to avoid aliasing? Consider the code:
highest_freq = 500
sampling_rate = ?
medium
A. sampling_rate = 1000
B. sampling_rate = 750
C. sampling_rate = 250
D. sampling_rate = 500

Solution

  1. Step 1: Apply Nyquist theorem to highest frequency

    Minimum sampling rate = 2 x highest frequency = 2 x 500 = 1000 Hz.
  2. Step 2: Compare with options

    Only sampling_rate = 1000 matches 1000 Hz.
  3. Final Answer:

    sampling_rate = 1000 -> Option A
  4. Quick Check:

    Minimum sampling rate = 2 x 500 = 1000 [OK]
Hint: Double the highest frequency for minimum sampling rate [OK]
Common Mistakes:
  • Choosing sampling rate equal to highest frequency
  • Selecting a rate less than twice the frequency
  • Confusing frequency units
4. Identify the error in this Python code snippet that calculates the Nyquist frequency:
fs = 800
nyquist = fs * 0.5
print("Nyquist frequency is", nyquist)
medium
A. The multiplication should be division by 2
B. The variable fs should be lowercase
C. The code is correct and will print 400.0
D. The print statement syntax is wrong

Solution

  1. Step 1: Understand calculation of Nyquist frequency

    Nyquist frequency = sampling rate divided by 2, which equals fs * 0.5.
  2. Step 2: Check code correctness

    Code multiplies fs by 0.5 correctly and prints the value 400.0.
  3. Final Answer:

    The code is correct and will print 400.0 -> Option C
  4. Quick Check:

    fs * 0.5 = 400.0, print works fine [OK]
Hint: Multiplying by 0.5 equals dividing by 2 [OK]
Common Mistakes:
  • Thinking multiplication by 0.5 is wrong
  • Assuming variable case matters here
  • Believing print syntax is incorrect in Python 3
5. You have a signal with components up to 1200 Hz. You sample it at 2000 Hz. What problem will occur and why?

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
hard
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

  1. Step 1: Calculate minimum sampling rate needed

    Minimum sampling rate = 2 x 1200 Hz = 2400 Hz.
  2. Step 2: Compare given sampling rate with minimum

    Given sampling rate is 2000 Hz, which is less than 2400 Hz, so aliasing will occur.
  3. Step 3: Understand aliasing cause

    Sampling below twice the highest frequency causes signal distortion called aliasing.
  4. Final Answer:

    Aliasing will occur because sampling rate is less than twice highest frequency -> Option B
  5. Quick Check:

    Sampling rate < 2 x highest frequency causes aliasing [OK]
Hint: Sampling rate must be ≥ 2 x highest frequency to avoid aliasing [OK]
Common Mistakes:
  • Assuming 2000 Hz is enough for 1200 Hz signal
  • Confusing aliasing cause with oversampling
  • Thinking aliasing occurs when sampling rate is too high
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard