This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / signal / _signaltools / sosfilt_zi

function

scipy.signal._signaltools:sosfilt_zi

source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_signaltools.py:4636

Signature

def sosfilt_zi(sos)

Summary

Construct initial conditions for sosfilt for step response steady-state.

Extended Summary

Compute an initial state zi for the sosfilt function that corresponds to the steady state of the step response.

A typical use of this function is to set the initial state so that the output of the filter starts at the same value as the first element of the signal to be filtered.

Parameters

sos : array_like

Array of second-order filter coefficients, must have shape (n_sections, 6). See sosfilt for the SOS filter format specification.

Returns

zi : ndarray

Initial conditions suitable for use with sosfilt, shape (n_sections, 2).

Notes

Examples

Filter a rectangular pulse that begins at time 0, with and without the use of the `zi` argument of `scipy.signal.sosfilt`.
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
✓
sos = signal.butter(9, 0.125, output='sos')
zi = signal.sosfilt_zi(sos)
x = (np.arange(250) < 100).astype(int)
f1 = signal.sosfilt(sos, x)
f2, zo = signal.sosfilt(sos, x, zi=zi)
✓
plt.plot(x, 'k--', label='x')
plt.plot(f1, 'b', alpha=0.5, linewidth=2, label='filtered')
plt.plot(f2, 'g', alpha=0.25, linewidth=4, label='filtered with zi')
plt.legend(loc='best')
✗
<matplotlib.legend.Legend object at 0x7f3f6067d400>
plt.show()
✓
fig-4e3d2afba4080c8b.png

See also

sosfilt
zpk2sos

Aliases

  • scipy.signal.sosfilt_zi

Referenced by