A General Formulation of the Optimal Frame Problem