maad.util.plot_spectrum

maad.util.plot_spectrum(pxx, f_idx, ax=None, flims=None, log_scale=False, fill=True, **kwargs)[source]

Plot power spectral density estimate (PSD).

Parameters:
pxx1d ndarray

Power spectral density estimate computed with maad.sound.spectrum.

f_idx1d ndarray

Index of frequencies associated with the PSD.

axmatplotlib.axes, optional

Pre-existing axes for the plot. The default is None.

flimstuple, optional

Minimum and maximum spectral limits for the display (min_f, max_f). Default is None.

log_scalebool, optional

Use a logarithmic scale to display amplitude values. The default is False.

fillbool, optional

Fill the area between the curve and the minimum value.

**kwargsmatplotlib figure properties

Other keyword arguments that are passed down to matplotlib.axes.

Returns:
axmatplotlib.axes

The matplotlib axes associated to plot.

Examples

Plot a spectrum of an audio signal.

>>> from maad import sound, util
>>> s, fs = sound.load('../data/spinetail.wav')
>>> pxx, f_idx = sound.spectrum(s, fs, nperseg=1024)
>>> util.plot_spectrum(pxx, f_idx)

Use plot_spectrum with predifined matplotlib axes.

>>> import matplotlib.pyplot as plt
>>> s, fs = sound.load('../data/spinetail.wav')
>>> s_slice = sound.trim(s, fs, 5, 8)
>>> pxx, f_idx = sound.spectrum(s_slice, fs, nperseg=1024)
>>> fig, ax = plt.subplots(2,1, figsize=(10,6))
>>> util.plot_wave(s_slice, fs, ax=ax[0])
>>> util.plot_spectrum(pxx, f_idx, ax=ax[1], log_scale=True)