Nonlinear input design as optimal control of a Hamiltonian system