0
0
SciPydata~10 mins

Spectrogram generation in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the spectrogram function from scipy.signal.

SciPy
from scipy.signal import [1]

# Now you can use spectrogram() to generate spectrograms.
Drag options to blanks, or click blank then click option'
Aspectrogram
Bfft
Cstft
Dwelch
Attempts:
3 left
💡 Hint
Common Mistakes
Importing fft instead of spectrogram
Using stft or welch which are different functions
2fill in blank
medium

Complete the code to generate a spectrogram from the signal array using the spectrogram function.

SciPy
frequencies, times, Sxx = spectrogram([1])

# frequencies: frequency bins
# times: time bins
# Sxx: spectrogram intensity
Drag options to blanks, or click blank then click option'
Aaudio
Bnp.array
Cdata
Dsignal
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable like np.array or data
Passing the function name instead of the signal variable
3fill in blank
hard

Fix the error in the code to correctly generate a spectrogram with a window size of 256 samples.

SciPy
frequencies, times, Sxx = spectrogram(signal, nperseg=[1])
Drag options to blanks, or click blank then click option'
A512
B128
C256
D1024
Attempts:
3 left
💡 Hint
Common Mistakes
Using a window size too large or too small
Not setting nperseg at all
4fill in blank
hard

Fill both blanks to generate a spectrogram with a sampling frequency of 1000 Hz and a window size of 128 samples.

SciPy
frequencies, times, Sxx = spectrogram(signal, fs=[1], nperseg=[2])
Drag options to blanks, or click blank then click option'
A1000
B500
C128
D256
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up fs and nperseg values
Using wrong values for sampling frequency or window size
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each frequency to its maximum spectrogram intensity if the intensity is greater than 0.5.

SciPy
max_intensity = { [1]: max(Sxx[i]) for i, [2] in enumerate(frequencies) if max(Sxx[i]) [3] 0.5 }
Drag options to blanks, or click blank then click option'
Afreq
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Using '<' instead of '>' in the condition
Not using max(Sxx[i]) correctly