phase_calculation function: inputs are phase gradient