|
From: <pl...@pi...> - 2014-01-30 17:32:38
|
On 01/30/14 15:00, 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. 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?
>
> Cheers,
> Jon
>
> [1] http://www.mathworks.co.uk/help/matlab/ref/unwrap.html
>
You should be able to implement it as a gnuplot function and call it
form plot:
as an example this will plot the integral.
integ(x)=(last=last+x)
last=0; plot datafile using 1(integ($2))
Post if you write it , this is something I'd thought of but never got
round to.
Peter.
|