|
From: Ethan A M. <sf...@us...> - 2014-01-30 17:55:05
|
On Thursday, 30 January, 2014 14:00:18 Jon Gjengset wrote: > Hi all! > > When plotting phase data in gnuplot, you often encounter "jumps" in a > graph when a value wraps around 2π. A common way of dealing with this is > to apply an unwrap[1] function. What this function does is add or remove > 2π from the next value to be plotted (v) as long as the difference > between v and the previous value (w) is outside the range [-π,π]. > > In pseudocode: > > unwrap(v, w): > do > diff = v - w > v += 2π if diff < -π > v -= 2π if diff > π > while abs(diff) > π > > It is also possible to implement a weighted unwrap which does the same > as the above, but instead of looking at the previous value w, it looks > at a weighted average of previous values instead. This works very well > for datasets with very low variance. > > I'd love to implement this feature in gnuplot myself, but it's not > entirely clear to me how I would go about it. Have a look at the running average demo: http://gnuplot.sourceforge.net/demo_4.6/running_avg.html Substituting an unwrap function for the avg5() function should do what you want. It would not require any changes to the executable code. One problem I see is that the resulting plot would not stable when zoomed. Each change in xrange would potentially shift the whole curve on y by some multiple of 2π. > It seems like > standard.{c,h} would be where to start, but from what I can tell, these > functions only receive the current data point, and does not have any > knowledge of previous points. Adding a static variable to track the > previous value seems like an ugly solution, so I was hoping someone here > could point me in the right direction? I don't think that adding a new function with a single argument is what you want. It seems to me this is more like a trivial smoothing operation, and the easiest fit into gnuplot's existing organization would be plot $DATA using 1:2 smooth unwrap with lines If you want to work on implementing this in the code, start by looking in plot2d.c for switch statements that handle SMOOTH_NONE or its alternatives. Ethan > Cheers, > Jon > > [1] http://www.mathworks.co.uk/help/matlab/ref/unwrap.html |