Opposite of numpy.unwrap

后端 未结 3 1370
Happy的楠姐
Happy的楠姐 2021-02-01 16:01

In Python numpy, there is an unwrap function that:

Unwrap radian phase p by changing absolute jumps greater than discont to their 2*pi complement along

3条回答
  •  梦谈多话
    2021-02-01 16:32

    This answer is a slight variation to sega_sai answer which is:

    phases = ( phases + np.pi) % (2 * np.pi ) - np.pi
    

    This maps phases to [-pi, pi) -> which means pi is mapped to -pi

    Shown here:

    In [27]: phases = np.pi
    
    In [28]: phases = ( phases + np.pi) % (2 * np.pi ) - np.pi
    
    In [29]: print phases
    -3.14159265359
    

    Which is perfectly legitimate but if you want a mapping of (-pi, pi] then

    Times the input and output of the operation buy -1. Like so:

    phases =  (( -phases + np.pi) % (2.0 * np.pi ) - np.pi) * -1.0
    

提交回复
热议问题