Skip to content

bode_plot

MATLAB equivalent: sidBodePlot

bode_plot

Bode diagram with confidence bands.

bode_plot

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

Bode diagram (magnitude and phase) with shaded confidence bands.

This is the Python port of sidBodePlot.m.

Plots the magnitude (dB) and phase (degrees) of the estimated frequency response. When uncertainty information is available, a shaded region shows the +/- 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. Must contain a non-None response field (input-output mode).

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 '#0072BD' (MATLAB blue).

None
line_width float

Line width. Default is 1.5.

1.5
ax tuple of (ax_mag, ax_phase) or None

Existing matplotlib axes to plot into. If None, a new figure with two vertically-stacked subplots is created.

None

Returns:

Type Description
dict

Dictionary with the following keys:

  • 'fig' -- matplotlib Figure handle.
  • 'ax_mag' -- Axes handle for the magnitude subplot.
  • 'ax_phase' -- Axes handle for the phase subplot.
  • 'line_mag' -- Line2D handle for the magnitude trace.
  • 'line_phase' -- Line2D handle for the phase trace.

Raises:

Type Description
SidError

If result.response is None (time-series mode). Use :func:sid.spectrum_plot instead (code: 'no_response').

Examples:

>>> import numpy as np
>>> import sid
>>> N = 1000; u = np.random.randn(N)
>>> y = np.convolve(u, [1, -0.9])[:N] + 0.1 * np.random.randn(N)
>>> result = sid.freq_bt(y, u)
>>> h = sid.bode_plot(result, confidence=3)
Notes

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

For MIMO systems only the first SISO channel pair (0, 0) is plotted.

See Also

sid.freq_bt : Blackman-Tukey spectral analysis. sid.spectrum_plot : Noise / output spectrum plot.

Changelog

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