# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Remove phase jumps from phase angle data

Contributed by:
Sander Huisman

ResourceFunction["PhaseUnwrap"][ removes phase jumps in consecutive elements of .π | |

ResourceFunction["PhaseUnwrap"][ removes phase jumps in consecutive elements of /2.τ | |

ResourceFunction["PhaseUnwrap"][ removes phase jumps in consecutive elements of tol. |

The default for *τ* is 2*π*.

Common settings for *τ* are 2*π* and 360 for the use of angles measured in radians and degrees, respectively.

The default tolerance *tol* is *τ*/2.

A tolerance *tol* smaller than *τ*/2 works effectively the same as a tolerance of *τ*/2.

ResourceFunction["PhaseUnwrap"] could be seen as the opposite of Mod for a time series as it "unwraps" the "wrapping around" in modular arithmetic.

Possible forms for *tol* are:

α | uses the tolerance α |

Scaled[]α | uses a tolerance of ατ |

Remove the discontinuity in the phase:

In[1]:= |

Out[3]= |

Correct phase jumps in a list of phase angles measured in degrees:

In[4]:= |

Out[6]= |

Supply a stricter tolerance:

In[7]:= |

Out[9]= |

Supply a tolerance as a scaled version of the modulus:

In[10]:= |

Out[12]= |

Jumps of multiple times the modulus * τ* are also removed:

In[13]:= |

Out[15]= |

Data measured from an angular encoder on a shaft:

In[16]:= |

Out[17]= |

Unwrap data to get the absolute angle of the shaft:

In[18]:= |

Out[18]= |

PhaseUnwrap is the opposite of Mod for time series of data:

In[19]:= |

Out[22]= |

If the tolerance is too high, steep parts of the function cannot be reconstructed, resulting in partial removal of the discontinuities:

In[23]:= |

Out[26]= |

Show some modulated data:

In[27]:= |

Out[28]= |

Interactively change the tolerance. For a scaled tolerance of 1, the original signal is returned:

In[29]:= |

Out[29]= |

Apply it to two-dimensional data by doing row-by-row unwrapping. First create some data:

In[30]:= |

Out[31]= |

Modulate the data:

In[32]:= |

Out[33]= |

Reconstruct the data:

In[34]:= |

Out[37]= |

Check that they are the same within machine precision:

In[38]:= |

Out[38]= |

Wolfram Language 11.3 (March 2018) or above

- 1.0.1 – 30 June 2023
- 1.0.0 – 20 March 2019

This work is licensed under a Creative Commons Attribution 4.0 International License