bundles / scipy latest / scipy / signal / _signaltools / lfilter_zi
function
scipy.signal._signaltools:lfilter_zi
source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_signaltools.py:4502
Signature
def lfilter_zi(b, a)Summary
Construct initial conditions for lfilter for step response steady-state.
Extended Summary
Compute an initial state zi for the lfilter 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
b: array_likeThe numerator coefficient vector as a 1-D sequence.
a: array_likeThe denominator coefficient vector as a 1-D sequence. If
a[0]is not 1, then bothaandbare normalized bya[0]. Hence,a[0] != 0must hold.
Returns
zi: 1-D ndarrayThe initial state for the filter.
Raises
: ValueErrorIf
a[0] == 0(invalid denominator polynomial) orsum(a) == 0(unstable filter).
Notes
The parameters b and a represent a transfer function which is defined in the tutorial_signal_TransferFunctionRepresentation section of the user_guide. As discussed in [1], the final value of filtering a step response , i.e., steady state, is given by
If the denominator is zero, has a pole at , which makes the filter unstable. For the transposed Direct Form II, which is implemented in lfilter, the initialization values for can be determined by the recurrence equation
with being the height of the input step function. Note that is assumed here, which is incorporated into this function by performing a normalization step.
Examples
The following code creates a lowpass Butterworth filter to filter a signal made up of ones. As expected of a lowpass filter, the output is also all ones. If the `zi` argument of `lfilter` had not been given, a transient signal would have been produced. The second signal illustrates that using the parameter `zi` suppresses transients at the beginning of the output signal:import numpy as np from scipy.signal import lfilter, lfilter_zi, butter b, a = butter(5, 0.25) zi = lfilter_zi(b, a) y0, zi0 = lfilter(b, a, np.ones(10), zi=zi)✓
y0
✗array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
x = np.array([0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0]) y1, zi1 = lfilter(b, a, x, zi=zi*x[0])✓
y1
✗array([0.5 , 0.5 , 0.5 , 0.49836039, 0.48610528,
0.44399389, 0.35505241])
Note that the `zi` argument to `lfilter` is computed using `lfilter_zi` and scaled
by ``x[0]``. As a result, the output `y1` has no transient until the input drops
from 0.5 to 0.See also
Aliases
scipy.signal.lfilter_zi