Effacer les filtres
Effacer les filtres

Wrapping an angle

5 vues (au cours des 30 derniers jours)
Matlab2010 le 8 Juin 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);
phi2 = wrapToPi(nancumsum(phi));
function a1 = wrapToPi(a0)
num2pi = floor(a0/(2*pi) + 0.5);
a1 = a0 - num2pi*2*pi;
I get junk answers.
Can anyone help me out? thanks

Réponse acceptée

Matlab2010 le 8 Juin 2012
phiOut = wrapToPi(nancumsum(abs(diff(phi))));

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by