Matlab function for calculating phase of complex number
8 ビュー (過去 30 日間)
古いコメントを表示
Hello and good day to all,
Matlab has a built in function to calculate amplitude and phase of a complex number using abs(number) and angle(number) funstions. I have a question regarding phase part. Lets suppose we have a complex number in the form z=x+jy (x being your real and y your imaginary part). When you want to calculate the phase of this number the formula is phase=arctan(y/x). In addition to this formula we have to take care of sign's of real and imaginary part (especially real part)and correspondingly we add (+/-) pi to the calculated value. Does matlab "angle function" consider this thing because all examples I saw have only positive real parts. Thank you
0 件のコメント
回答 (1 件)
John D'Errico
2016 年 8 月 9 日
編集済み: John D'Errico
2016 年 8 月 9 日
Actually, the formula is
atan2(y,x)
atan2 handles the problem properly, working in all 4 quadrants. If you don't believe me, just look in the angle function itself. There you will find only one line of code:
p = atan2(imag(h), real(h));
Yep.
angle(-1-0.5i)
ans =
-2.67794504458899
4 件のコメント
Walter Roberson
2016 年 8 月 10 日
That would not work correctly for (0,0) because the 0/0 would give rise to NaN and atan(NaN) is NaN which would pollute the rest of the calculation.
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!