Mathematica Adapting Unwrapping Techniques for Plotting Phase Values

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
  • Tags Tags
    Phase Plot
AI Thread Summary
The discussion centers on the challenge of adapting a function to unwrap phase values for use in a Plot rather than ListPlot, specifically for creating a jump-free graph. The user is implementing a function, fnUnwrap2, which utilizes state information to track previous phase values and accumulated jumps. The current implementation produces spikes at jump points and an offset in the output, indicating that the approach may not be fully effective.The user suggests that the issue might stem from the plotting algorithm evaluating the phase in a non-sequential manner, leading to confusion in the calculations. They propose that storing additional information, such as the previous X value alongside the previous phase, could help mitigate this problem. The discussion invites suggestions for improving the function or alternative methods to achieve a smoother plot without jumps.
Swamp Thing
Insights Author
Messages
1,028
Reaction score
763
TL;DR Summary
Plotting Arg[ f[x] ] gives output that has jumps of +/- 2Pi and is limited to +-Pi.
Can we unwrap this into a jumpless plot?
This discussion https://community.wolfram.com/groups/-/m/t/1340126 includes some ideas to unwrap a list of wrapped-around values such as phase (e.g. Arg[ f[N] ] ). You can use this to ListPlot a jump-free graph.

I'm trying to adapt this to work in Plot rather than ListPlot. The idea is to plot fnUnwrap [ myPhase[t] ], where fnUnwrap is called whenever the plotter wants to evaluate the Y value.

Now fnUnwrap needs to use two successive phase values, and also maintain a cumulative total of all the jumps. So we store some "state information" in the variables unwrap`old and unwrap`cumu, i.e. the previous input and the accumulated jumps. Here is my attempt:
Code:
fnUnwrap2[new_,\[CapitalDelta]_,tol_]:=Module[{jmp},
                                    jmp=new-unwrap`old;
                                    jmp=-Sign[jmp] Unitize[        Chop [ Abs[jmp],tol      ]   ];
                                    jmp= jmp *  \[CapitalDelta];
                                    unwrap`cumu=unwrap`cumu+jmp;
                                    unwrap`old=new;
                                    new + unwrap`cumu
                                                                                  ]

This code "sort of" works, but has these spikes around the jump points and has an offset as well:

Code:
unwrap`old=0
unwrap`cumu=0

Plot[{ fnUnwrap2[Mod[ x, 2],2,1.75],
           x
        
    },{x,0,12},PlotRange->All,PlotPoints->250]

Output:
1635757404617.png


Can this be fixed , or is there a better approach?
 
Last edited:
Physics news on Phys.org
Perhaps part of the problem is that the plotting algorithm often evaluates Arg[f[x]] in a random sequence of X. Maybe we need to store not only old_Arg but also old_X, and somehow use that to avoid confusing the plotting algorithm.

Any suggestions much appreciated.
 
Last edited:

Similar threads

Replies
1
Views
2K
Replies
1
Views
6K
Replies
5
Views
3K
Replies
5
Views
3K
Replies
5
Views
3K
Replies
1
Views
3K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top