lfilter_zi(b, a)
Compute an initial state :None:None:`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.
A linear filter with order m has a state space representation (A, B, C, D), for which the output y of the filter can be expressed as:
z(n+1) = A*z(n) + B*x(n) y(n) = C*z(n) + D*x(n)
where z(n) is a vector of length m, A has shape (m, m), B has shape (m, 1), C has shape (1, m) and D has shape (1, 1) (assuming x(n) is a scalar). lfilter_zi solves:
zi = A*zi + B
In other words, it finds the initial condition for which the response to an input of all ones is a constant.
Given the filter coefficients a
and b
, the state space matrices for the transposed direct form II implementation of the linear filter, which is the implementation used by scipy.signal.lfilter, are:
A = scipy.linalg.companion(a).T B = b[1:] - a[1:]*b[0]
assuming :None:None:`a[0]`
is 1.0; if :None:None:`a[0]`
is not 1, a
and b
are first divided by a[0].
The initial state for the filter.
Construct initial conditions for lfilter for step response steady-state.
The following code creates a lowpass Butterworth filter. Then it applies that filter to an array whose values are all 1.0; the output is also all 1.0, as expected for a lowpass filter. If the :None:None:`zi`
argument of lfilter
had not been given, the output would have shown the transient signal.
>>> from numpy import array, ones
... from scipy.signal import lfilter, lfilter_zi, butter
... b, a = butter(5, 0.25)
... zi = lfilter_zi(b, a)
... y, zo = lfilter(b, a, ones(10), zi=zi)
... y array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
Another example:
>>> x = array([0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0])
... y, zf = lfilter(b, a, x, zi=zi*x[0])
... y array([ 0.5 , 0.5 , 0.5 , 0.49836039, 0.48610528, 0.44399389, 0.35505241])
Note that the :None:None:`zi`
argument to lfilter
was computed using lfilter_zi
and scaled by :None:None:`x[0]`
. Then the output :None:None:`y`
has no transient until the input drops from 0.5 to 0.0.
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.signal._signaltools.lfilter_zi
scipy.signal._signaltools.lfilter
scipy.signal._signaltools.lfiltic
scipy.signal._signaltools.filtfilt
scipy.signal._signaltools.sosfilt
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them