Challenge - 5 Problems
Spectrum Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of magnitude spectrum calculation
What is the output of the following Python code that computes the magnitude spectrum of a signal?
Signal Processing
import numpy as np signal = np.array([1, 2, 3, 4]) fft_result = np.fft.fft(signal) magnitude = np.abs(fft_result) print(np.round(magnitude, 2))
Attempts:
2 left
💡 Hint
Recall that magnitude is the absolute value of the FFT complex output.
✗ Incorrect
The FFT of [1,2,3,4] is [10+0j, -2+2j, -2+0j, -2-2j]. The magnitudes are [10, sqrt(2^2+2^2), 2, sqrt(2^2+2^2)] = [10, 2.83, 2, 2.83].
❓ data_output
intermediatePhase spectrum values from FFT
Given the signal array and its FFT, what is the phase spectrum output (in radians) from the code below?
Signal Processing
import numpy as np signal = np.array([0, 1, 0, -1]) fft_result = np.fft.fft(signal) phase = np.angle(fft_result) print(np.round(phase, 2))
Attempts:
2 left
💡 Hint
Phase is the angle of the complex FFT output, use np.angle.
✗ Incorrect
The FFT of [0,1,0,-1] is [0+0j, 0-2j, 0+0j, 0+2j]. The phases are [0, -pi/2, pi, pi/2] which rounds to [0, -1.57, 3.14, 1.57].
❓ visualization
advancedIdentify the correct magnitude spectrum plot
Which plot correctly shows the magnitude spectrum of a 1-second 5 Hz sine wave sampled at 50 Hz?
Signal Processing
import numpy as np import matplotlib.pyplot as plt fs = 50 f = 5 t = np.arange(0, 1, 1/fs) signal = np.sin(2 * np.pi * f * t) fft_result = np.fft.fft(signal) magnitude = np.abs(fft_result) / len(signal) freq = np.fft.fftfreq(len(signal), 1/fs) plt.stem(freq[:len(freq)//2], magnitude[:len(magnitude)//2]) plt.xlabel('Frequency (Hz)') plt.ylabel('Magnitude') plt.title('Magnitude Spectrum') plt.show()
Attempts:
2 left
💡 Hint
Remember FFT frequency bins include negative frequencies represented as high positive frequencies.
✗ Incorrect
The FFT of a real sine wave shows two peaks: one at the positive frequency (5 Hz) and one at the negative frequency (which appears at 45 Hz due to FFT frequency wrapping).
🧠 Conceptual
advancedEffect of zero-padding on magnitude spectrum resolution
What is the main effect of zero-padding a time-domain signal before computing its FFT magnitude spectrum?
Attempts:
2 left
💡 Hint
Think about how zero-padding affects the FFT length and frequency bins.
✗ Incorrect
Zero-padding adds extra zeros to the signal, increasing FFT length and producing more frequency bins, which interpolates the spectrum and improves frequency resolution visually without changing actual frequency content.
🔧 Debug
expertIdentify the error in phase spectrum calculation code
What error will the following code produce when calculating the phase spectrum of a signal?
Signal Processing
import numpy as np signal = np.array([1, 0, -1, 0]) fft_result = np.fft.fft(signal) phase = np.angle(fft_result.real) print(phase)
Attempts:
2 left
💡 Hint
Check what np.angle expects as input and what fft_result.real contains.
✗ Incorrect
np.angle expects complex numbers to compute phase. Passing only the real part (fft_result.real) removes imaginary parts, so phase is zero everywhere, losing phase information.
