Oscillating Discontinuity in atan2

Discussion in 'MATLAB' started by Sable Campbell, Apr 13, 2011.

  1. 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.
    Sable Campbell, Apr 13, 2011
    1. Advertisements

  2. - - - - - - - - - -
    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
    Roger Stafford, Apr 13, 2011
    1. Advertisements

  3. in message <io4n1t$t34$>...

    Thank you very much for providing me with a better understanding of the problem. I shall go back to the drawing board.
    Sable Campbell, Apr 14, 2011
  4. Sable Campbell

    Matt J Guest

    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, Apr 14, 2011
  5. Sable Campbell

    Matt J Guest


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

    ans =


    ans =


    ans =

    Matt J, Apr 14, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.