Is there (open-source) toolboxes for state-space estimation via subspace estimation in Python? I know this is used in Matlab's n4sid function, but I didn't found any Python's implementation (even in Scipy's signal module or in Python Control Systems Library). It would really helps not to have to code it :)

  • $\begingroup$ You must be more specific about asking for algorithms. I can give you this list though, Awesome-python. $\endgroup$ Commented Jul 20, 2018 at 21:57
  • $\begingroup$ Is there an update on this? Like in the terms of a library in python i can use. I am also trying to achieve subspace state space estimation but I do not know how to estimate the initial states. It would very helpful if someone can help me out with the initial state estimation. $\endgroup$
    – Gopal Rao
    Commented Apr 8, 2020 at 11:25

1 Answer 1


You can use pyvib to do frequency based subspace identification. Beware that there is no estimation of the initial state. It is possible to do optimization of the identified model, if the data is not perfectly linear. See the implemenentation, maybe you can use it, in case you want to do your own implementation.

Somewhat incomplete example. Take a look at the example to get a working code:

git clone --depth 1 https://github.com/pawsen/pyvib.git
export PYTHONPATH=pyvib

from pyvib.subspace import Subspace
from pyvib.signal import Signal
# partion the data so the format is (npp,inputs/outputs,R,P)
sig = Signal(uest,yest,fs=fs)
sig.lines = lines  # which freq lines should be used
sig.bla()  # computer best linear approx.
nvec = [2,3]  # model size to scan over
maxr = 5  # max number of rows
model = Subspace(sig)
models, infodict = model.scan(nvec, maxr)
errvec = model.extract_model(yval, uval)  # extract best model on fresh data
model.estimate(n, r)  # or do direct estimation if you know sys size

I have written the code. You are more than welcome to criticize and suggest improvements.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.