I am observing a error using atan2

2 ビュー (過去 30 日間)
AKHIL REDDY
AKHIL REDDY 2016 年 3 月 4 日
回答済み: Walter Roberson 2016 年 3 月 4 日
a warning of this kind is being observed
Warning: Imaginary parts of complex X and/or Y arguments ignored
and a
Error using atan2 Inputs must be real
is being observed.
I = (Ac/2)*real(exp(j*y));
Q = j*(Ac/2)*imag(exp(j*y));
where y is
y = modulate(x,200,1000,'fm');
arctanofy = unwrap(atan2(Q, I));
is to be found
help me out is rectifying the error
  1 件のコメント
KSSV
KSSV 2016 年 3 月 4 日
atan2 accepts only real numbers a input. Read the doc: http://in.mathworks.com/help/matlab/ref/atan2.html

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 3 月 4 日
Unless you have assigned a value to "j", the expression
Q = j*(Ac/2)*imag(exp(j*y));
will use the default meaning of "j", which is sqrt(-1) . The imag() part around the exp will return a real value, the Ac/2 is real valued, and then you multiply by that imaginary value "j". Your Q will therefore be imaginary. Meanwhile your I has been constructed to be real valued. You are taking atan2(some_complex_value, some_real_value) . And that is failing because atan2 only accepts real values. Which make sense if you think of it, since atan2() attempts to find the proper quadrant for the parameters, but complex values not going to be in the quadrants at all.
You could use
atan(Q/I)
If you do that then the Ac/2 are going to cancel out on the top and bottom, so you would be doing
atan(j*imag(exp(j*y))/real(exp(j*y))
By definition of complex exponentials, exp(j*y) for real y is going to be cos(y)+I*sin(y) so the real component is cos(y) and the imaginary part is sin(y), so you would be doing atan(j*sin(y)/cos(y)) which would be atan(j*tan(y)) . Is that your intent?
modulate() with 'fm' is going to transform its real-valued input into a real-valued output so it is not the case that y is complex itself.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by