Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Oscillating Discontinuity in atan2

202 views
Skip to first unread message

Sable Campbell

unread,
Apr 13, 2011, 10:55:23 AM4/13/11
to
Dear All,

I am having a problem with the atan2 function and unwrap.
My Simulink model contains a feedback control system for a vehicle which is required to make turns.
When the required turning angle exceeds +/- pi radians (e.g. 3*pi/2 radians or three quarters of a full revolution in either direction) I am getting constant oscillation between the limits of +/- pi instead of a step.

I tried to unwrap this oscillating data coming out of my atan2 function, so that the output would extend beyond these limits, but it simply unwraps to an extremely large number.

Please advise.

Roger Stafford

unread,
Apr 13, 2011, 1:38:05 PM4/13/11
to
"Sable Campbell" wrote in message <io4dgr$6m3$1...@fred.mathworks.com>...
- - - - - - - - - -
From your description it sounds as though you are expecting more from 'atan2' and 'unwrap' than is logically possible, given the information they receive. When you expect an angle to suddenly change by 3/2*pi, for example, how can any function possibly know that unless you provide more information than just the point-to-point x-y coordinates? You will have to think of some way of augmenting the information you are providing in order to make such a decision even theoretically possible.

Roger Stafford

Sable Campbell

unread,
Apr 14, 2011, 9:28:19 AM4/14/11
to
"Roger Stafford" wrote in message <io4n1t$t34$1...@fred.mathworks.com>...

Thank you very much for providing me with a better understanding of the problem. I shall go back to the drawing board.

Matt J

unread,
Apr 14, 2011, 9:49:05 AM4/14/11
to
"Sable Campbell" wrote in message <io4dgr$6m3$1...@fred.mathworks.com>...
>
> I tried to unwrap this oscillating data coming out of my atan2 function, so that the output would extend beyond these limits, but it simply unwraps to an extremely large number.
>
> Please advise.

The ANGLE function is discontinuous in the neighbourhood of the negative real axis. This means that any numerical noise in the input X to angle(X) will can cause the values of X to jitter back and forth across the real axis with corresponding discontinuous jumps in angle(X) between pi and -pi.

Bottom line. You must insert code to detect when X gets close, within some tolerance, to the negative real axis and manually round it to a desired value (pi or -pi).

Matt J

unread,
Apr 14, 2011, 10:02:03 AM4/14/11
to
"Matt J" wrote in message <io6u0h$kst$1...@fred.mathworks.com>...

> "Sable Campbell" wrote in message <io4dgr$6m3$1...@fred.mathworks.com>...
>
> The ANGLE function is discontinuous in the neighbourhood of the negative real axis. This means that any numerical noise in the input X to angle(X) will can cause the values of X to jitter back and forth across the real axis with corresponding discontinuous jumps in angle(X) between pi and -pi.
>
> Bottom line. You must insert code to detect when X gets close, within some tolerance, to the negative real axis and manually round it to a desired value (pi or -pi).
========================

Sorry, you were talking about ATAN2 as opposed to ANGLE. But the same discontinuity is present in ATAN2, so the same remarks apply:

>> tinyError = 1e-20;

>> atan2(0,-1)

ans =

3.1416

>> atan2(0 + tinyError,-1)

ans =

3.1416

>> atan2( 0 - tinyError,-1)

ans =

-3.1416

0 new messages