Challenge - 5 Problems
PSD Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of PSD estimation using Welch's method
What is the shape of the output array
psd after running Welch's method on a 1D signal of length 1024 with nperseg=1024?Signal Processing
import numpy as np from scipy.signal import welch fs = 1000 # Sampling frequency signal = np.random.randn(1024) frequencies, psd = welch(signal, fs=fs, nperseg=1024) print(psd.shape)
Attempts:
2 left
💡 Hint
Welch's method returns half the FFT length plus one for the frequency bins.
✗ Incorrect
Welch's method with nperseg=1024 uses an FFT length of 1024 (same as signal length). The output PSD array length is nfft/2 + 1 = 512 + 1 = 513.
❓ data_output
intermediate2:00remaining
Number of frequency bins in periodogram
Given a signal of length 2048 sampled at 500 Hz, what is the number of frequency bins returned by the periodogram method with default FFT length?
Signal Processing
import numpy as np from scipy.signal import periodogram fs = 500 signal = np.random.randn(2048) frequencies, psd = periodogram(signal, fs=fs) print(len(frequencies))
Attempts:
2 left
💡 Hint
Periodogram returns nfft/2 + 1 frequency bins for real signals.
✗ Incorrect
The default FFT length is the signal length (2048). The number of frequency bins is nfft/2 + 1 = 1024 + 1 = 1025.
❓ visualization
advanced3:00remaining
Identifying the correct PSD plot
Which plot correctly shows the power spectral density of a noisy sine wave at 50 Hz using Welch's method?
Signal Processing
import numpy as np import matplotlib.pyplot as plt from scipy.signal import welch fs = 500 T = 2 t = np.linspace(0, T, int(T*fs), endpoint=False) signal = np.sin(2*np.pi*50*t) + 0.5*np.random.randn(len(t)) frequencies, psd = welch(signal, fs=fs, nperseg=256) plt.figure(figsize=(8,4)) plt.semilogy(frequencies, psd) plt.xlabel('Frequency (Hz)') plt.ylabel('PSD (V**2/Hz)') plt.title('Power Spectral Density using Welch') plt.grid(True) plt.show()
Attempts:
2 left
💡 Hint
The sine wave frequency should appear as a peak in the PSD.
✗ Incorrect
The noisy sine wave at 50 Hz produces a PSD with a clear peak near 50 Hz. Noise contributes to a flat noise floor.
🧠 Conceptual
advanced2:00remaining
Effect of segment length on PSD resolution
How does increasing the segment length (nperseg) in Welch's method affect the frequency resolution and variance of the PSD estimate?
Attempts:
2 left
💡 Hint
Longer segments give finer frequency bins but fewer averages.
✗ Incorrect
Longer segments increase frequency resolution (smaller frequency bins) but reduce the number of segments averaged, increasing variance.
🔧 Debug
expert2:00remaining
Identifying error in PSD calculation code
What error will this code raise when calculating PSD using Welch's method?
import numpy as np from scipy.signal import welch fs = 1000 signal = np.random.randn(500) frequencies, psd = welch(signal, fs=fs, nperseg=1024) print(psd)
Attempts:
2 left
💡 Hint
Check if segment length is valid for the signal length.
✗ Incorrect
Welch's method requires nperseg to be less than or equal to the signal length. Here, nperseg=1024 > 500 causes ValueError.