Wrapping an angle

9 views (last 30 days)
Matlab2010
Matlab2010 on 8 Jun 2012
Where v is a vector between -1 and +1
I say
phi = acos(v); %returns phi varying 0->pi
I have also read: http://en.wikipedia.org/wiki/Inverse_trigonometric_functions#General_solutions and understand that acos is symmetrical in the range [-pi pi]. I merely want to view the transistion across 2pi in one montonic sweep.
I wish to view phi varying between -pi and +pi (as per angle.m returns). ie I wish to see the phase increase from 0% to 100% over the course of a full oscillation, when plotted against time.
When I try
phi2 = wrapToPi(phi);
or
phi2 = wrapToPi(nancumsum(phi));
where
function a1 = wrapToPi(a0)
num2pi = floor(a0/(2*pi) + 0.5);
a1 = a0 - num2pi*2*pi;
end
I get junk answers.
Can anyone help me out? thanks

Accepted Answer

Matlab2010
Matlab2010 on 8 Jun 2012
phiOut = wrapToPi(nancumsum(abs(diff(phi))));

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!