Complete the code to compute the power spectral density (PSD) using Welch's method.
from scipy.signal import welch frequencies, psd = welch(signal, fs=[1])
The sampling frequency fs must match the signal's sampling rate. Here, 500 Hz is the correct value.
Complete the code to plot the PSD on a logarithmic scale.
import matplotlib.pyplot as plt plt.semilogy(frequencies, [1]) plt.xlabel('Frequency (Hz)') plt.ylabel('PSD (V**2/Hz)') plt.show()
The PSD values are plotted on the y-axis using psd. The semilogy function plots y-axis on a log scale.
Fix the error in the code to compute PSD with a Hamming window.
from scipy.signal import welch, [1] frequencies, psd = welch(signal, fs=500, window=[1](256))
The hamming window function is imported and used to create the window for Welch's method.
Fill both blanks to compute PSD with segment length 512 and overlap 256.
frequencies, psd = welch(signal, fs=500, nperseg=[1], noverlap=[2])
The segment length nperseg is 512 samples, and the overlap noverlap is 256 samples.
Fill all three blanks to create a dictionary of PSD values for frequencies above 100 Hz.
psd_dict = {f: p for f, p in zip(frequencies, psd) if f [1] 100}
filtered_freqs = [f for f in frequencies if f [2] 100]
filtered_psd = [p for f, p in zip(frequencies, psd) if f [3] 100]We filter frequencies and PSD values where frequency is greater than 100 Hz using the '>' operator.