Skip to content
RFrftools.io
Unit ConversionAugust 18, 20263 min read

The 180° Error: Why arctan(b/a) Flips Your Impedance

arctan of a ratio cannot tell 3 + j4 from −3 − j4. That single-argument shortcut turns inductive loads capacitive and sends matching networks in the wrong direction. Here is why atan2 exists.

Contents

Two numbers, same ratio

Take 3+j43 + j4 and 3j4-3 - j4. They point in opposite directions in the complex plane. Now compute the ratio b/ab/a for each:

  • 4 / 3 = 1.333
  • (−4) / (−3) = 1.333

Identical. Every bit of information distinguishing those two vectors was destroyed by the division, because the two minus signs cancelled.

So arctan(b/a)\arctan(b/a) returns 53.13°53.13° for both. One of those answers is right and the other is off by exactly 180°180°.

What the single-argument form can and cannot do

arctan\arctan takes one number and returns an angle between −90° and +90°. That range covers half the plane — quadrants I and IV. It has no way to reach quadrants II and III, because no ratio maps there.

Given a point in quadrant II, arctan reports the quadrant IV mirror. Given a point in quadrant III, it reports the quadrant I mirror.

atan2(b,a)\operatorname{atan2}(b, a) takes the two components separately, so the signs survive. It inspects them and returns the correct angle over the full −180° to +180° range:
  • 3 + j4 → 53.1301°
  • −3 + j4 → 126.8699°
  • −3 − j4 → −126.8699°
  • 3 − j4 → −53.1301°

All four have magnitude 5. Only the angle tells them apart, and only atan2 gets it right.

Why this bites in RF specifically

An impedance is Z=R+jXZ = R + jX. In polar form it is Zθ|Z|\angle\theta, and the sign of θ\theta carries the entire physical meaning:

  • θ>0\theta > 0: inductive
  • θ<0\theta < 0: capacitive
  • θ=0\theta = 0: resistive

Get the quadrant wrong and an inductive load reads as capacitive. A matching network designed from that reading adds the wrong element — series inductance where the load already had too much, or shunt capacitance where the load needed the opposite. The match gets worse, and it gets worse in a way that looks like a component tolerance problem rather than a sign error.

For a passive load with R>0R > 0, the point is in quadrant I or IV, where arctan happens to be correct. That is why the bug survives so long: passive impedances hide it. It surfaces the moment you handle a reflection coefficient, where the real part is routinely negative, or an active device with negative resistance, or a de-embedded measurement that swung past the imaginary axis.

The convention question

atan2 returns −180° to +180°. Many instruments and file readers present 0° to 360° instead. The two are the same angle; negative results differ by exactly 360°360°.

That becomes a real problem when you compare or average. The mean of 179° and −179° is 0° by arithmetic and 180° in reality. Any averaging, interpolation, or curve fit across the wrap point needs the phase unwrapped first — a step that gets skipped constantly in measurement post-processing.

Which convention you use is a choice. Not knowing which one your data is in is not.

Touchstone formats

S-parameter files store the same complex numbers three ways, declared on the option line:

  • MA — magnitude and angle in degrees
  • DB — magnitude in dB and angle in degrees
  • RI — real and imaginary parts

RI needs no conversion at all. MA and DB need the polar-to-rectangular step before any arithmetic that is not pure multiplication. Reading a DB file as if it were MA gives magnitudes wrong by a logarithm — a mistake that produces plausible-looking but entirely wrong plots.

Habits worth having

Use atan2 always. There is no case where the single-argument form is safer, and it costs nothing. Round-trip anything suspicious. Convert to polar, convert straight back, compare with the original. A quadrant error shows up immediately as a sign flip; a units error shows up as a scale factor. Read the angle sign before the magnitude when looking at an impedance. It tells you which direction to move before any arithmetic. Keep full precision through cascades. Rounding 53.13010235° to 53.1° looks harmless and accumulates into visible magnitude error after a handful of chained multiplications. Treat a negative magnitude as an error, not a result. A magnitude of −r describes the same vector as +r rotated by 180°, and downstream tools that assume a non-negative magnitude will misread it.

The rectangular to polar converter runs both directions at once with atan2, and reports the angle in radians, in ±180°\pm 180°, and in 00 to 360°360° so you never have to add or subtract 360 by hand.

Related Articles