Challenge - 5 Problems
Real-time DSP Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple real-time filter code
What is the output array after applying this simple moving average filter on the input signal?
Signal Processing
import numpy as np def moving_average(signal, window_size=3): filtered = [] for i in range(len(signal)): window = signal[max(0, i - window_size + 1):i + 1] filtered.append(sum(window) / len(window)) return np.array(filtered) input_signal = np.array([1, 2, 3, 4, 5]) output_signal = moving_average(input_signal) print(output_signal)
Attempts:
2 left
💡 Hint
Think about how the moving average window grows at the start of the signal.
✗ Incorrect
The moving average at each point is the average of the current and previous samples up to the window size. For the first element, only one sample is available, so average is 1.0. For the second, average of [1,2] = 1.5, and so on.
❓ data_output
intermediateNumber of samples after downsampling
Given a signal with 1000 samples, what is the length of the signal after downsampling by a factor of 4?
Attempts:
2 left
💡 Hint
Downsampling by 4 means keeping every 4th sample.
✗ Incorrect
Downsampling by 4 reduces the number of samples to one fourth, so 1000 / 4 = 250 samples remain.
❓ visualization
advancedIdentify the correct frequency spectrum plot
Which plot correctly shows the frequency spectrum of a 5 Hz sine wave sampled at 50 Hz?
Signal Processing
import numpy as np import matplotlib.pyplot as plt fs = 50 # Sampling frequency f = 5 # Signal frequency t = np.arange(0, 1, 1/fs) signal = np.sin(2 * np.pi * f * t) fft_vals = np.fft.fft(signal) fft_freq = np.fft.fftfreq(len(signal), 1/fs) plt.plot(fft_freq[:len(signal)//2], np.abs(fft_vals)[:len(signal)//2]) plt.xlabel('Frequency (Hz)') plt.ylabel('Magnitude') plt.title('Frequency Spectrum') plt.show()
Attempts:
2 left
💡 Hint
The sine wave frequency should appear as a peak in the spectrum.
✗ Incorrect
A pure sine wave at 5 Hz sampled at 50 Hz will show a single peak at 5 Hz in the frequency spectrum.
🔧 Debug
advancedIdentify the error in this real-time filter code snippet
What error will this code raise when run?
Signal Processing
def real_time_filter(signal): filtered = [] for i in range(len(signal)): filtered[i] = signal[i] * 0.5 return filtered print(real_time_filter([1, 2, 3]))
Attempts:
2 left
💡 Hint
Look at how the list 'filtered' is used before any elements are added.
✗ Incorrect
The code tries to assign to filtered[i] but filtered is empty, so this causes an IndexError.
🚀 Application
expertChoosing the best approach for real-time DSP latency reduction
Which approach best reduces latency in a real-time DSP pipeline processing audio signals?
Attempts:
2 left
💡 Hint
Lower latency means processing data faster with less delay.
✗ Incorrect
Smaller buffers reduce delay before processing starts, and optimized filters run faster, both reducing latency.
