Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Oscillating Discontinuity in atan2

Subject: Oscillating Discontinuity in atan2

From: Sable Campbell

Date: 13 Apr, 2011 14:55:23

Message: 1 of 5

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.

Subject: Oscillating Discontinuity in atan2

From: Roger Stafford

Date: 13 Apr, 2011 17:38:05

Message: 2 of 5

"Sable Campbell" wrote in message <io4dgr$6m3$1@fred.mathworks.com>...
> 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.
- - - - - - - - - -
  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

Subject: Oscillating Discontinuity in atan2

From: Sable Campbell

Date: 14 Apr, 2011 13:28:19

Message: 3 of 5

"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.

Subject: Oscillating Discontinuity in atan2

From: Matt J

Date: 14 Apr, 2011 13:49:05

Message: 4 of 5

"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).

Subject: Oscillating Discontinuity in atan2

From: Matt J

Date: 14 Apr, 2011 14:02:03

Message: 5 of 5

"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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us