Mechanical shock detection and phase and frequency correction of a MEMS mirror