Complete the code to import the library needed for plotting the spectrogram.
import matplotlib.pyplot as [1]
We use plt as the common alias for matplotlib.pyplot to plot graphs.
Complete the code to generate a spectrogram from the signal array using matplotlib.
frequencies, times, Sxx = plt.specgram(signal, NFFT=[1], Fs=fs)The NFFT parameter defines the number of data points used in each block for the FFT. 512 is a common choice for good resolution.
Fix the error in the code to correctly label the x-axis as 'Time [sec]'.
plt.xlabel([1])The label text must be a string enclosed in quotes. 'Time [sec]' is the correct label.
Fill both blanks to create a dictionary comprehension that maps each frequency to its power value if power is above 0.1.
freq_power = {freq: power[1] for freq, power in zip(frequencies, map(max, Sxx)) if power [2] 0.1}We square the power value with **2 and filter frequencies where power is greater than 0.1 using >.
Fill all three blanks to create a filtered dictionary of frequencies and powers where power is above 0.05, and keys are rounded frequencies.
filtered = { [1]: [2] for freq, power in freq_power.items() if power [3] 0.05}We round the frequency keys with round(freq), keep the power values, and filter powers greater than 0.05.