A common function to 'unwrap' a list of data which has had a modulus operation working on it is still absent from the Wolfram Language. This also quite commonly happens when you measure something in the lab which is for example an angle that jumps back to '0' after every rotation. To solve this, I wrote my own function, hopefully this is helpful for you. Here it is:
Unwrap[lst_List]:=Unwrap[lst,2Pi] (* phase jumps of 2Pi is the default because of trigonometric funtions *)
Unwrap[lst_List,\[CapitalDelta]_]:=Unwrap[lst,\[CapitalDelta],Scaled[0.5]] (* default tolerance is half the phase jump \[CapitalDelta] *)
When a list is given, the default period is assumed to be 2Pi, and the tolerance Pi. But one can specify any one likes with the second and third arguments.
So let's create some data and plot it:
Now, let's take the modulus of the data and plot it:
Now we indeed have many sharp jumps, but with the above function we can undo this:
So we return now to our original data; great!
With some tricks we can also do it with 2D-data, here i create some data, plot it, mod it (what a mess!), plot it, unmod it, plot it:
Hope you enjoy it and find it useful!
- Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming!
Here is my function for phase unwrapping, just 1 line long:
Unwrap[a_] := a - Tau Prepend[Accumulate[Round[Differences[a]/Tau]], 0];
Nice way to do this!
I just noticed that Sander made this available as a resource function:
Yes I did a while ago. Thanks for noticing and promoting Gustavo!
Hello, I am having some troubles with an exercise, maybe can you help me?
I have a function that I have to wrap and then unwrap to show that I have the original phase
Can your function help me with that? Thanks!
Hi Nicolas, I guess it could! Have a look at the examples here:
There you can also copy the resourcefunction so you can directly use it.
Sander thank you for your answer,
I have the following function:
That is the function that i have to wrapp and then unwrapp
How can i use it with your code?