Initial implementation of phase calculation