Finite element formulation of the complex envelope analysis