how to redefine atan2 function from -inf to inf in matlab?
Question
I have a rotating vector R(x(t), y(t))
and I want to find an angle as a function of time. The atan2
is determined between -pi
and pi
, however it is inconvenient for me to analyse all dynamics. So, is there any way to expand atan2
from -inf
to inf
?
Solution
Your question is not very clear, but I guess you are searching for the function unwrap. This will correct all the 2 pi
jumps you get when your vector rotates through the negative x-axis. You use it like so:
t = linspace(0,3,1000);
x = cos(2*pi*t);
y = sin(2*pi*t);
phi = atan2(y,x);
unwrapped_phi = unwrap(phi);
plot(t, phi, t, unwrapped_phi)
xlabel('time (s)')
ylabel('angle (rad)')
legend('wrapped angle','unwrapped angle')
OTHER TIPS
I believe you are looking for phase unwrapping. Matlab has a 1D solution ready, see unwrap for more details.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow