Can using 'angle' to find S21 phase shift ever be done incorrectly?

8 visualizzazioni (ultimi 30 giorni)
My calculation of arctan(real/imaginary) for S21 gives a different answer. Can anyone explain what I am doing wrong (in one of these cases)? Thanks!

Risposte (1)

John D'Errico
John D'Errico il 15 Mar 2024
Modificato: John D'Errico il 15 Mar 2024
Hint: Learn about ATAN2, why it exists, and what it does differently.
Use of atan gives a 2 quadrant arc tangent. The point is, what is the difference between an angle of 45 degrees, and an angle of 225 degrees? They both lie on the same line through the origin. But they correspond to angles that are exactly 180 degrees apart. For example, if we have
x1 = 1;y1 = 1;
atan(y1/x1)
ans = 0.7854
BUT also
x2 = -1;y2 = -1;
atan(y2/x2)
ans = 0.7854
Do you see that both result in a 45 degree angle? (If you do not recognize that in terms of rdians, then try atand or atan2d, which will give you an angle in degrees.) Instead, try it with atan2.
atan2(y1,x1)
ans = 0.7854
atan2(y2,x2)
ans = -2.3562
Do you see that when you compute the ratio of y/x, the signs go away.
atan2 is as I said, a 4 quadrant version of the arc tangent.
What does angle do for those results?
angle(x1 + i*y1)
ans = 0.7854
angle(x2 + i*y2)
ans = -2.3562
SURPRISE! It works! And it yields the same result as atan2.
Plotted in the complex plane, we would see them as
plot([0 x1],[0,y1],'ro-',[0 x2],[0,y2],'bs-')
axis equal
axis square
So the same line, but the ray is pointing in opposite directions along that line, and therefore 180 degrees apart. ATAN2 can see the difference.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by