Lagrangian and energy forms for retrieving the impulse response of the Earth due to random electromagnetic forcing