# NOT RUN {
## taken from Python scipy.signal.lfilter_zi documentation
h <- butter(5, 0.25)
zi <- filter_zi(h)
y <- filter(h, rep(1, 10), zi)
## output is all 1, as expected.
y2 <- filter(h, rep(1, 10))
## if the zi argument is not given, the output
## does not return the final conditions
x <- c(0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0)
y <- filter(h, x, zi = zi*x[1])
## Note that the zi argument to filter was computed using
## filter_zi and scaled by x[1]. Then the output y has no
## transient until the input drops from 0.5 to 0.0.
## obtain the same results with filtic
lab <- max(length(h$b), length(h$a)) - 1
ic <- filtic(h, rep(1, lab), rep(1, lab))
all.equal(zi, ic)
# }
Run the code above in your browser using DataLab