move mag and phase function to util