Challenge - 5 Problems
FFT Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of FFT on a simple signal
What is the output of the following code that computes the FFT of a simple signal?
NumPy
import numpy as np signal = np.array([1, 0, -1, 0]) fft_result = np.fft.fft(signal) print(np.round(fft_result, 2))
Attempts:
2 left
💡 Hint
Recall that FFT output is complex and symmetric for real inputs.
✗ Incorrect
The FFT of the signal [1, 0, -1, 0] results in complex values with imaginary parts at certain frequencies. The output shows non-zero imaginary parts at indices 1 and 3.
❓ data_output
intermediate1:00remaining
Length of FFT output array
Given a real input array of length 8, what is the length of the output array from np.fft.fft?
NumPy
import numpy as np x = np.arange(8) fft_x = np.fft.fft(x) print(len(fft_x))
Attempts:
2 left
💡 Hint
FFT output length equals input length for np.fft.fft.
✗ Incorrect
The FFT output array length is the same as the input array length when using np.fft.fft.
🔧 Debug
advanced1:30remaining
Identify the error in FFT frequency calculation
What error does the following code raise when trying to compute FFT frequencies for a signal of length 5?
import numpy as np
freqs = np.fft.fftfreq(5, d=0)
print(freqs)
NumPy
import numpy as np freqs = np.fft.fftfreq(5, d=0) print(freqs)
Attempts:
2 left
💡 Hint
Check the meaning of the parameter d in fftfreq.
✗ Incorrect
The parameter d is the sample spacing. Setting d=0 causes division by zero inside fftfreq, raising ZeroDivisionError.
🚀 Application
advanced2:30remaining
Using FFT to find dominant frequency
Given a noisy signal composed of two sine waves at 5 Hz and 20 Hz sampled at 100 Hz, which code snippet correctly identifies the dominant frequency using FFT?
NumPy
import numpy as np fs = 100 T = 1/fs t = np.linspace(0, 1, fs, endpoint=False) signal = np.sin(2*np.pi*5*t) + 0.5*np.sin(2*np.pi*20*t) + 0.1*np.random.randn(fs)
Attempts:
2 left
💡 Hint
Sample spacing d should be the inverse of sampling frequency fs.
✗ Incorrect
The sample spacing d must be 1/fs to get correct frequency values. Option A uses d=T=1/fs correctly.
🧠 Conceptual
expert2:00remaining
Interpretation of FFT output symmetry
For a real-valued input signal of length N, which statement about the FFT output from np.fft.fft is true?
Attempts:
2 left
💡 Hint
Think about properties of FFT for real inputs.
✗ Incorrect
For real inputs, FFT output is symmetric: the second half is the complex conjugate of the first half reversed. This is called Hermitian symmetry.