Interpreting the angle from the angle obtained by atan2 function

98 Views Asked by At

I have two signals ($x$ and $y$) whose absolute phases I'm calculating by using the atan2 function. Then subtracting both I'm getting the relative phase between two signals.

Because the absolute phase is calculated by atan2, its range is $[-\pi,\pi]$. Now the relative phase I got after subtracting the absolute phase, how do I convert this to $[0,2\pi]$?

My efforts: On the final relative phase obtained by atan2. I'm doing this

if phase >= 0 then
phase = 360 - phase;
else
phase = abs(phase);
end

This is yielding good results and matches with the phase between the signals $x$ and $y$, except in the ranges $[0,10]$ and $[350,360]$.

Other methods:

Method1 = abs(rad2deg(mod(phase1,2*pi) - mod(phase2,2*pi)))
%%%% 2nd Method %%%%%
Angles360 = @(a) rem(360+a, 360);
X_2pi = Angles360(rad2deg(X));
Y_2pi = Angles360(rad2deg(Y));
Method2 = abs(X_2pi - Y_2pi);

But all three methods have the same problem, if I'm giving initial phase difference as $1$ and run the simulation for $1000$ trials, I'm getting o/p as $357,359,1,5,8,\ldots$. Why is it getting wrapped to $357,359$?