[Robert Kern] > ... > ph3 = math.atan( ac3.imag / ac3.real ) > ... Don't do that: atan2 is the correct way to compute the angle, because the signs of both inputs are needed to determine the correct quadrant. So do: ph3 = math.atan2(ac3.imag, ac3.real) instead.