I am observing a error using atan2

8 次查看(过去 30 天)
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 个)

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 CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by