0
0
SciPydata~20 mins

Windowing before FFT in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Windowing FFT Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Effect of Windowing on FFT Magnitude

What is the output magnitude array when applying a Hamming window before FFT on a simple sine wave?

SciPy
import numpy as np
from scipy.signal import windows

fs = 1000
f = 50
N = 256

t = np.arange(N) / fs
signal = np.sin(2 * np.pi * f * t)
window = windows.hamming(N)
windowed_signal = signal * window
fft_result = np.fft.fft(windowed_signal)
magnitude = np.abs(fft_result)[:5]
print(np.round(magnitude, 2))
A[32.00 0. 0. 0. 0. ]
B[31.99 0. 0. 0. 0. ]
C[15.99 0. 0. 0. 0. ]
D[16.00 0. 0. 0. 0. ]
Attempts:
2 left
💡 Hint

Recall that the Hamming window reduces spectral leakage but scales the amplitude.

🧠 Conceptual
intermediate
1:30remaining
Purpose of Windowing Before FFT

Why do we apply a window function to a signal before computing its FFT?

ATo reduce spectral leakage caused by signal discontinuities at the edges.
BTo increase the frequency resolution of the FFT.
CTo remove noise from the signal before FFT.
DTo speed up the FFT computation.
Attempts:
2 left
💡 Hint

Think about what happens at the edges of a signal segment when FFT assumes periodicity.

data_output
advanced
2:30remaining
Comparing FFT Results With and Without Windowing

Given a noisy signal, which option shows the correct difference in FFT magnitude peak when using a rectangular window vs a Hann window?

SciPy
import numpy as np
from scipy.signal import windows

fs = 500
f = 60
N = 128

t = np.arange(N) / fs
signal = np.sin(2 * np.pi * f * t) + 0.5 * np.random.randn(N)

rect_window = np.ones(N)
hann_window = windows.hann(N)

fft_rect = np.fft.fft(signal * rect_window)
fft_hann = np.fft.fft(signal * hann_window)

peak_rect = np.max(np.abs(fft_rect))
peak_hann = np.max(np.abs(fft_hann))
diff = round(peak_rect - peak_hann, 2)
print(diff)
AApproximately 5.0
BApproximately 0.0
CApproximately 10.0
DApproximately -10.0
Attempts:
2 left
💡 Hint

Windowing usually reduces the peak magnitude due to tapering.

🔧 Debug
advanced
1:30remaining
Identify the Error in Windowing Application

What error occurs when this code tries to apply a window before FFT?

SciPy
import numpy as np
from scipy.signal import windows

signal = np.array([1, 2, 3, 4, 5])
window = windows.hann(10)
windowed_signal = signal * window
fft_result = np.fft.fft(windowed_signal)
print(np.round(np.abs(fft_result), 2))
AValueError due to shape mismatch in multiplication
BTypeError because window is not a numpy array
CNo error, prints FFT magnitude
DIndexError accessing window elements
Attempts:
2 left
💡 Hint

Check the sizes of the signal and window arrays before multiplying.

🚀 Application
expert
3:00remaining
Choosing the Best Window for Frequency Resolution

You want to detect two close frequencies in a signal using FFT. Which window choice helps best to resolve them?

AHamming window for lowest side lobes
BBartlett window for fastest computation
CRectangular window for narrow main lobe and high resolution
DBlackman window for widest main lobe
Attempts:
2 left
💡 Hint

Frequency resolution depends on main lobe width in window's frequency response.