brainmass.viz.plot_power_spectrum

brainmass.viz.plot_power_spectrum#

brainmass.viz.plot_power_spectrum(signal, dt, *, ax=None, loglog=True, **kwargs)[source]#

Plot the power spectral density of a 1-D signal.

The PSD is computed via braintools.metric.power_spectral_density().

Parameters:
  • signal (array_like or brainunit.Quantity) – (time,) signal. Units are stripped before the transform.

  • dt (float or brainunit.Quantity) – The sampling step. A brainunit.Quantity is converted to milliseconds; a plain float is used as-is.

  • ax (matplotlib.axes.Axes, optional) – Axes to draw on. A new figure/axes is created when None.

  • loglog (bool, optional) – Use log-log axes. Default True.

  • **kwargs – Forwarded to matplotlib.axes.Axes.plot().

Returns:

The axes drawn on.

Return type:

matplotlib.axes.Axes

See also

braintools.metric.power_spectral_density

the surfaced metric.

Examples

>>> import numpy as np
>>> import brainunit as u
>>> import brainmass
>>> t = np.linspace(0, 1, 200)
>>> sig = np.sin(2 * np.pi * 10 * t)
>>> ax = brainmass.viz.plot_power_spectrum(sig, dt=5.0 * u.ms)
>>> ax.get_xlabel()
'frequency'