0
0
Signal Processingdata~20 mins

Spectral leakage concept in Signal Processing - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spectral Leakage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What causes spectral leakage in signal processing?

Which of the following best explains the cause of spectral leakage when analyzing signals using the Fourier Transform?

ASampling a signal at a rate higher than the Nyquist frequency
BApplying a Fourier Transform to a perfectly periodic infinite signal
CUsing a window function that perfectly matches the signal frequency
DUsing a finite-length window on a signal that is not periodic within that window
Attempts:
2 left
💡 Hint

Think about what happens when you cut a signal into a short segment before transforming it.

Predict Output
intermediate
2:00remaining
Output of FFT magnitude with and without windowing

Given a pure sine wave sampled and transformed using FFT, what is the effect of applying a rectangular window versus a Hann window on the FFT magnitude?

Consider the code below:

import numpy as np
import matplotlib.pyplot as plt

fs = 1000
f = 50
N = 1000

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

fft_rect = np.fft.fft(signal)
window = np.hanning(N)
fft_hann = np.fft.fft(signal * window)

mag_rect = np.abs(fft_rect)[:N//2]
mag_hann = np.abs(fft_hann)[:N//2]

peak_rect = np.argmax(mag_rect)
peak_hann = np.argmax(mag_hann)

print(peak_rect, peak_hann)
ABoth peak_rect and peak_hann equal 50
Bpeak_rect equals 50, peak_hann equals 49
Cpeak_rect equals 50, peak_hann equals 50
Dpeak_rect equals 49, peak_hann equals 50
Attempts:
2 left
💡 Hint

Consider that the FFT bin index corresponds to frequency bins. The window affects leakage but not the peak frequency bin.

data_output
advanced
2:00remaining
Number of significant FFT bins after windowing

After applying a rectangular window and a Hann window to the same signal and computing their FFT magnitudes, how does the number of bins with magnitude above 10% of the peak compare?

Signal Processing
import numpy as np
fs = 1000
f = 50
N = 1000
t = np.arange(N) / fs
signal = np.sin(2 * np.pi * f * t)

fft_rect = np.fft.fft(signal)
window = np.hanning(N)
fft_hann = np.fft.fft(signal * window)

mag_rect = np.abs(fft_rect)[:N//2]
mag_hann = np.abs(fft_hann)[:N//2]

threshold_rect = 0.1 * np.max(mag_rect)
threshold_hann = 0.1 * np.max(mag_hann)

count_rect = np.sum(mag_rect > threshold_rect)
count_hann = np.sum(mag_hann > threshold_hann)

print(count_rect, count_hann)
Acount_rect equals count_hann
Bcount_rect is larger than count_hann
Ccount_rect is smaller than count_hann
Dcount_rect is zero, count_hann is nonzero
Attempts:
2 left
💡 Hint

Think about how windowing affects the spread of energy in the frequency domain.

🔧 Debug
advanced
2:00remaining
Identify the error causing unexpected spectral leakage

Consider this code snippet that applies a window before FFT but shows unexpected spectral leakage:

import numpy as np
fs = 1000
f = 50
N = 1000
t = np.arange(N) / fs
signal = np.sin(2 * np.pi * f * t)
window = np.hanning(N)
fft_result = np.fft.fft(signal)
windowed_fft = fft_result * window
mag = np.abs(windowed_fft)[:N//2]
print(np.argmax(mag))

What is the main error causing incorrect spectral leakage behavior?

AThe window is applied after the FFT instead of before
BThe frequency f is not an integer
CThe signal length N is too small for FFT
DThe FFT is computed on the window instead of the signal
Attempts:
2 left
💡 Hint

Consider when the window should be applied relative to the FFT.

🚀 Application
expert
3:00remaining
Choosing window length to minimize spectral leakage

You have a signal with a frequency of 123.4 Hz sampled at 1000 Hz. You want to analyze it with FFT to minimize spectral leakage. Which window length (N) choice will best reduce leakage?

AN = 811 samples, which is an integer multiple of the signal period
BN = 1000 samples (1 second), which is not an integer multiple of the signal period
CN = 1000 samples with a rectangular window
DN = 1000 samples with zero padding to 2048 samples
Attempts:
2 left
💡 Hint

Think about how window length relates to the signal period and periodicity assumptions in FFT.