2

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?

Shai
  • 111,146
  • 38
  • 238
  • 371
anatoly
  • 327
  • 2
  • 13

2 Answers2

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

enter image description here

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.

paddy
  • 60,864
  • 6
  • 61
  • 103
Shai
  • 111,146
  • 38
  • 238
  • 371