Can using 'angle' to find S21 phase shift ever be done incorrectly?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
John D'Errico
am 15 Mär. 2024
Bearbeitet: John D'Errico
am 15 Mär. 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)
BUT also
x2 = -1;y2 = -1;
atan(y2/x2)
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)
atan2(y2,x2)
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)
angle(x2 + i*y2)
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Trigonometry finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!