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
?
Asked
Active
Viewed 2,347 times
2
2 Answers
7
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')

Bas Swinckels
- 18,095
- 3
- 45
- 62
-
This command does not work if the jump is less than 2pi. For example, one of the vector coordinates abruptly changes sign. – dtn Mar 20 '23 at 12:54
1
I believe you are looking for phase unwrapping. Matlab has a 1D solution ready, see unwrap for more details.