Challenge - 5 Problems
Frequency Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of fftfreq with default d=1.0
What is the output of the following code snippet?
SciPy
from scipy.fft import fftfreq freqs = fftfreq(6) print(freqs)
Attempts:
2 left
💡 Hint
Remember that fftfreq returns frequencies in cycles per unit sample spacing, with negative frequencies after the Nyquist frequency.
✗ Incorrect
fftfreq(n) returns an array of length n with frequencies starting at 0, increasing to the positive Nyquist frequency, then negative frequencies in increasing order. For n=6 and default d=1.0, the output matches option C.
❓ data_output
intermediate2:00remaining
Frequency array with custom sample spacing
Given sample spacing d=0.5 and n=4, what is the output of fftfreq?
SciPy
from scipy.fft import fftfreq freqs = fftfreq(4, d=0.5) print(freqs)
Attempts:
2 left
💡 Hint
Frequency values scale inversely with sample spacing d.
✗ Incorrect
With n=4 and d=0.5, fftfreq returns frequencies [0, 1/(4*0.5), -1/(2*0.5), -1/(4*0.5)] = [0, 0.5, -1, -0.5].
🧠 Conceptual
advanced2:00remaining
Understanding negative frequencies in fftfreq output
Why does fftfreq return negative frequency values in its output array?
Attempts:
2 left
💡 Hint
Think about how complex sinusoids represent signals in both positive and negative directions.
✗ Incorrect
In Fourier analysis, negative frequencies correspond to complex conjugate components and represent direction of rotation in the complex plane. They are essential for reconstructing real-valued signals.
🔧 Debug
advanced2:00remaining
Identify the error in fftfreq usage
What error will the following code produce?
SciPy
from scipy.fft import fftfreq freqs = fftfreq(-5) print(freqs)
Attempts:
2 left
💡 Hint
Check the parameter constraints for fftfreq's n argument.
✗ Incorrect
The fftfreq function requires n to be a non-negative integer. Passing a negative value raises a ValueError.
🚀 Application
expert3:00remaining
Using fftfreq to find the dominant frequency index
Given a signal sampled at 100 Hz with 8 samples, which index corresponds to the dominant frequency 12.5 Hz using fftfreq?
SciPy
from scipy.fft import fftfreq sample_rate = 100 n = 8 freqs = fftfreq(n, d=1/sample_rate) print(freqs)
Attempts:
2 left
💡 Hint
Calculate frequency bins as k * sample_rate / n for k in [0..n-1], considering fftfreq output order.
✗ Incorrect
With n=8 and sample_rate=100 Hz, fftfreq returns frequencies: [0, 12.5, 25, 37.5, -50, -37.5, -25, -12.5]. The frequency 12.5 Hz is at index 1.