Challenge - 5 Problems
SNR Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateCalculate SNR from signal and noise arrays
Given the following Python code that calculates the signal-to-noise ratio (SNR) in decibels, what is the output?
Signal Processing
import numpy as np signal = np.array([2, 4, 6, 8, 10]) noise = np.array([1, 1, 1, 1, 1]) snr = 10 * np.log10(np.mean(signal**2) / np.mean(noise**2)) print(round(snr, 2))
Attempts:
2 left
💡 Hint
Remember that SNR in decibels is 10 times the log base 10 of the power ratio.
✗ Incorrect
The mean power of the signal is higher than noise. Calculating 10 * log10(mean(signal^2)/mean(noise^2)) gives approximately 16.43 dB.
❓ data_output
intermediateNumber of samples with SNR above threshold
You have a signal array and noise array. Which option shows the number of samples where the instantaneous SNR (signal power divided by noise power) is greater than 4?
Signal Processing
import numpy as np signal = np.array([1, 5, 2, 8, 3]) noise = np.array([1, 1, 1, 2, 1]) inst_snr = (signal**2) / (noise**2) count = np.sum(inst_snr > 4) print(count)
Attempts:
2 left
💡 Hint
Calculate (signal^2)/(noise^2) for each element and count how many exceed 4.
✗ Incorrect
The instantaneous SNR values are [1, 25, 4, 16, 9]. Values greater than 4 are 25, 16, and 9, so count is 3.
❓ visualization
advancedPlot signal and noise power over time
Which option produces a plot with two lines: signal power and noise power over time, correctly labeled and with a legend?
Signal Processing
import matplotlib.pyplot as plt import numpy as np time = np.arange(5) signal = np.array([2, 4, 6, 8, 10]) noise = np.array([1, 1, 1, 1, 1]) signal_power = signal**2 noise_power = noise**2 plt.plot(time, signal_power, label='Signal Power') plt.plot(time, noise_power, label='Noise Power') plt.xlabel('Time') plt.ylabel('Power') plt.legend() plt.show()
Attempts:
2 left
💡 Hint
Check if both lines are plotted and legend is included.
✗ Incorrect
Option B correctly plots both powers with labels and legend. Others miss lines, labels, or have syntax errors.
🧠 Conceptual
advancedInterpretation of SNR value
If a signal has an SNR of 0 dB, what does this mean about the signal and noise powers?
Attempts:
2 left
💡 Hint
Recall that SNR in dB = 10 * log10(signal power / noise power).
✗ Incorrect
0 dB means the ratio signal power / noise power is 1, so they are equal.
🔧 Debug
expertIdentify error in SNR calculation code
What error will the following code produce when calculating SNR, and why?
import numpy as np
signal = np.array([1, 2, 3])
noise = np.array([0, 0, 0])
snr = 10 * np.log10(np.mean(signal**2) / np.mean(noise**2))
print(snr)
Attempts:
2 left
💡 Hint
Check the denominator in the division inside log10.
✗ Incorrect
Noise array is all zeros, so mean(noise**2) is zero. NumPy returns inf for division by zero (with a warning), log10(inf) is inf, so no exception is raised and it prints inf (very large SNR).
