Can using 'angle' to find S21 phase shift ever be done incorrectly?
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
John D'Errico
2024-3-15
编辑:John D'Errico
2024-3-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Trigonometry 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!