direct_data_driven_mpc.utilities.initial_state_estimation#

Functions for estimating the initial state of LTI systems.

This module provides functions related to state estimation for LTI systems, which include:

  • Calculation of Observability and Toeplitz matrices,

  • Estimation of initial states from input-output data,

  • Calculation of equilibrium input-output pairs for steady-state conditions.

Functions

calculate_equilibrium_input_from_output(A, ...)

Calculate the equilibrium input u_eq corresponding to an output y_eq so they represent an equilibrium pair of the system defined by matrices A (state), B (input), C (output) and D (feedforward).

calculate_equilibrium_output_from_input(A, ...)

Calculate the equilibrium output y_eq corresponding to an input u_eq so they represent an equilibrium pair of the system defined by matrices A (state), B (input), C (output) and D (feedforward).

estimate_initial_state(Ot, Tt, U, Y)

Estimate the initial state of an observable system based on its input-output history using a least squares observer with the Toeplitz input-output and observability matrices of the system.

observability_matrix(A, C)

Calculate the observability matrix for a state-space system defined by state matrix A and output matrix C.

toeplitz_input_output_matrix(A, B, C, D, t)

Construct a Toeplitz matrix that maps inputs to outputs for a state-space system defined by matrices A (state), B (input), C (output) and D (feedforward), over the time interval [0, t-1].

observability_matrix(A: ndarray, C: ndarray) ndarray[source]#

Calculate the observability matrix for a state-space system defined by state matrix A and output matrix C.

The observability matrix is constructed over n time steps, where n is the number of states in the system, which corresponds to the dimension of the A matrix.

Parameters:
Returns:

np.ndarray – The observability matrix of the system.

toeplitz_input_output_matrix(A: ndarray, B: ndarray, C: ndarray, D: ndarray, t: int) ndarray[source]#

Construct a Toeplitz matrix that maps inputs to outputs for a state-space system defined by matrices A (state), B (input), C (output) and D (feedforward), over the time interval [0, t-1].

This matrix is used to express the linear response of the system outputs to the system inputs, extended over t time steps.

For t = 3, this matrix takes the form:

     [D   0   0]
Tt = [CB  D   0]
     [CAB CB  D]
Parameters:
  • A (numpy.ndarray) – The state matrix of the system.

  • B (numpy.ndarray) – The input matrix of the system.

  • C (numpy.ndarray) – The output matrix of the system.

  • D (numpy.ndarray) – The feedforward matrix of the system.

  • t (int) – The number of time steps for the Toeplitz matrix extension.

Returns:

np.ndarray – The Toeplitz input-output matrix of the system over t steps.

Examples

>>> import numpy as np
>>> A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> B = np.array([[1], [1], [0]])
>>> C = np.array([[1, 0, 2], [0, 1, 0]])
>>> D = np.array([[0], [1]])
>>> t = 3
>>> print(toeplitz_input_output_matrix(A, B, C, D, t))
[[ 0.  0.  0.]
 [ 1.  0.  0.]
 [ 1.  0.  0.]
 [ 1.  1.  0.]
 [33.  1.  0.]
 [ 9.  1.  1.]]
estimate_initial_state(Ot: ndarray, Tt: ndarray, U: ndarray, Y: ndarray) ndarray[source]#

Estimate the initial state of an observable system based on its input-output history using a least squares observer with the Toeplitz input-output and observability matrices of the system.

Parameters:
  • Ot (numpy.ndarray) – The observability matrix of the system.

  • Tt (numpy.ndarray) – The Toeplitz input-output matrix of the system over t steps.

  • U (numpy.ndarray) – The vector of inputs over the past t time steps.

  • Y (numpy.ndarray) – The vector of outputs over the past t time steps.

Returns:

np.ndarray – The estimated initial state.

Raises:

ValueError – If there is a dimension mismatch between the inputs.

calculate_equilibrium_output_from_input(A: ndarray, B: ndarray, C: ndarray, D: ndarray, u_eq: ndarray) ndarray[source]#

Calculate the equilibrium output y_eq corresponding to an input u_eq so they represent an equilibrium pair of the system defined by matrices A (state), B (input), C (output) and D (feedforward).

This function assumes a Linear Time-Invariant (LTI) system and that the equilibrium is calculated under zero initial conditions using the final value theorem.

Parameters:
Returns:

np.ndarray – The equilibrium output y_eq corresponding to the input u_eq.

calculate_equilibrium_input_from_output(A: ndarray, B: ndarray, C: ndarray, D: ndarray, y_eq: ndarray) ndarray[source]#

Calculate the equilibrium input u_eq corresponding to an output y_eq so they represent an equilibrium pair of the system defined by matrices A (state), B (input), C (output) and D (feedforward).

This function assumes a Linear Time-Invariant (LTI) system and that the equilibrium is calculated under zero initial conditions using the final value theorem.

Parameters:
Returns:

np.ndarray – The equilibrium input u_eq corresponding to the output y_eq.