def make_state_space_controller(Phi_x, Phi_u, n, p):
    '\n    Converts FIR transfer functions to a state\n    space realization of the dynamic controller,\n    mapping states to inputs.\n\n    '
    assert (len(Phi_x.shape) == 2)
    assert (len(Phi_u.shape) == 2)
    assert (Phi_x.shape[1] == n)
    assert (Phi_u.shape[1] == n)
    (nT, _) = Phi_x.shape
    (pT, _) = Phi_u.shape
    assert ((nT % n) == 0)
    assert ((pT % p) == 0)
    T = (nT // n)
    assert (T == (pT // p))
    Z = np.diag(np.ones((n * (T - 2))), k=(- n))
    assert (Z.shape == (((T - 1) * n), ((T - 1) * n)))
    calI = np.zeros(((n * (T - 1)), n))
    calI[:n, :] = np.eye(n)
    Rhat = np.hstack([Phi_x[(n * k):(n * (k + 1)), :] for k in range(1, T)])
    Mhat = np.hstack([Phi_u[(p * k):(p * (k + 1)), :] for k in range(1, T)])
    M1 = Phi_u[:p, :]
    R1 = Phi_x[:n, :]
    A = (Z - calI.dot(Rhat))
    B = (- calI)
    C = (M1.dot(Rhat) - Mhat)
    D = M1
    return (A, B, C, D)
Converts FIR transfer functions to a state
space realization of the dynamic controller,
mapping states to inputs.
def make_state_space_controller(Phi_x, Phi_u, n, p):
    '\n    Converts FIR transfer functions to a state\n    space realization of the dynamic controller,\n    mapping states to inputs.\n\n    '
    assert (len(Phi_x.shape) == 2)
    assert (len(Phi_u.shape) == 2)
    assert (Phi_x.shape[1] == n)
    assert (Phi_u.shape[1] == n)
    (nT, _) = Phi_x.shape
    (pT, _) = Phi_u.shape
    assert ((nT % n) == 0)
    assert ((pT % p) == 0)
    T = (nT // n)
    assert (T == (pT // p))
    Z = np.diag(np.ones((n * (T - 2))), k=(- n))
    assert (Z.shape == (((T - 1) * n), ((T - 1) * n)))
    calI = np.zeros(((n * (T - 1)), n))
    calI[:n, :] = np.eye(n)
    Rhat = np.hstack([Phi_x[(n * k):(n * (k + 1)), :] for k in range(1, T)])
    Mhat = np.hstack([Phi_u[(p * k):(p * (k + 1)), :] for k in range(1, T)])
    M1 = Phi_u[:p, :]
    R1 = Phi_x[:n, :]
    A = (Z - calI.dot(Rhat))
    B = (- calI)
    C = (M1.dot(Rhat) - Mhat)
    D = M1
    return (A, B, C, D)