0
0
SciPydata~20 mins

Frequency array generation (fftfreq) in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Frequency Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[0. 0.2 0.4 0.6 0.8 1. ]
B[ 0. 0.16666667 0.33333333 0.5 -0.33333333 -0.16666667]
C[ 0. 0.16666667 0.33333333 -0.5 -0.33333333 -0.16666667]
D[ 0. 0.16666667 0.33333333 -0.33333333 -0.16666667 -0.5 ]
Attempts:
2 left
💡 Hint
Remember that fftfreq returns frequencies in cycles per unit sample spacing, with negative frequencies after the Nyquist frequency.
data_output
intermediate
2: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)
A[ 0. 0.25 -1. -0.5]
B[ 0. 0.25 -0.5 -0.25]
C[ 0. 0.5 -0.5 -0.25]
D[ 0. 0.5 -1. -0.5]
Attempts:
2 left
💡 Hint
Frequency values scale inversely with sample spacing d.
🧠 Conceptual
advanced
2:00remaining
Understanding negative frequencies in fftfreq output
Why does fftfreq return negative frequency values in its output array?
ANegative frequencies represent the direction of rotation in complex exponentials and are necessary for representing real signals in the frequency domain.
BNegative frequencies are errors and should be ignored when analyzing FFT results.
CNegative frequencies indicate frequencies below zero Hertz, which physically do not exist.
DNegative frequencies are placeholders for missing data points in the FFT output.
Attempts:
2 left
💡 Hint
Think about how complex sinusoids represent signals in both positive and negative directions.
🔧 Debug
advanced
2: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)
ATypeError: fftfreq() missing required positional argument
BValueError: n must be non-negative
CSyntaxError: invalid syntax
DNo error, outputs an empty array
Attempts:
2 left
💡 Hint
Check the parameter constraints for fftfreq's n argument.
🚀 Application
expert
3: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)
AIndex 1
BIndex 3
CIndex 2
DIndex 4
Attempts:
2 left
💡 Hint
Calculate frequency bins as k * sample_rate / n for k in [0..n-1], considering fftfreq output order.