how to redefine atan2 function from -inf to inf in matlab?

atan2, matlab, phase

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')

Problem

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`?

Original source