Skip to content

spectrum_plot

MATLAB equivalent: sidSpectrumPlot

spectrum_plot

Power spectrum plot with confidence bands.

spectrum_plot

spectrum_plot(result: FreqResult, *, confidence: float = 3.0, frequency_unit: str = 'rad/s', color: str | tuple = None, line_width: float = 1.5, ax=None) -> dict

Power spectrum plot with shaded confidence bands.

This is the Python port of sidSpectrumPlot.m.

Plots the noise spectrum (or output spectrum in time-series mode) in dB with an optional shaded +/- confidence-sigma band.

Parameters:

Name Type Description Default
result FreqResult

Result struct returned by :func:sid.freq_bt, :func:sid.freq_etfe, or :func:sid.freq_btfdr.

required
confidence float

Number of standard deviations for the shaded confidence band. Set to 0 to hide the bands. Default is 3.0.

3.0
frequency_unit str

'rad/s' (default) or 'Hz'.

'rad/s'
color str or tuple

Line and fill colour. Default is '#D95319' (MATLAB orange).

None
line_width float

Line width. Default is 1.5.

1.5
ax matplotlib Axes or None

Existing axes to plot into. If None, a new figure is created.

None

Returns:

Type Description
dict

Dictionary with the following keys:

  • 'fig' -- matplotlib Figure handle.
  • 'ax' -- Axes handle.
  • 'line' -- Line2D handle for the spectrum trace.

Examples:

>>> import numpy as np
>>> import sid
>>> y = np.random.randn(500)
>>> result = sid.freq_bt(y, None)
>>> h = sid.spectrum_plot(result, confidence=3)
Notes

Specification: (Spectrum plotting -- not yet in SPEC.md)

For MIMO systems only the first output channel is plotted.

See Also

sid.freq_bt : Blackman-Tukey spectral analysis. sid.bode_plot : Bode diagram for frequency-response data.

Changelog

2026-04-09 : First version (Python port) by Pedro Lourenco.