5

Is it possible to filter the noise in Gnuplot and get a plot with average values of different sets? The plot can be seen below.

2 by 3 grid of noise plots with time along the x-axis and temperature along the y axis

Community
  • 1
  • 1
Physther
  • 246
  • 3
  • 10
  • Do you want a single plot as average of the four curves, or do you want to filter each curve? – Christoph Feb 05 '15 at 16:19
  • Hey Christoph, I would like to average the values in each plot. But I would like to average on different segments and therefore follow the trend. I don't want a fixed average value between t_init to t_final. – Physther Feb 06 '15 at 17:21

1 Answers1

5

To smooth noisy curves you have at least two strategies: one is to use a smoothing kernel, for example Gaussian functions, which gives you local averages. The other one is to calculate total averages or interpolation functions if you know the functional form of your data. Both can be done with gnuplot.

Since you do not provide your data files I have generated the following file filled with 1000 random values obtained from the $RANDOM bash variable:

for i in `seq 1 1 1000`; do echo $RANDOM >> data; done

This should generate random data in the range 0 - 32767, that is the average value should be 16383.5 for a sufficiently representative data sample. Let's plot it to see how the raw data looks:

plot "data" t "data", 16383.5 t "theoretical average"

enter image description here

The first strategy is to use a Gaussian kernel to smooth the data (smooth kdensity):

plot "data" smooth kdensity t "data", 16383.5 t "theoretical average"

enter image description here

As you see, this method gives you a good smoothing in the middle but also takes into account the lack of data points at the edges.

To prevent this from happening I can increase the "locality" of the smoothing by supplying a third column with the bandwidth (equals to 10 in this case):

plot "data" u 0:1:(10) smooth kdensity t "data", 16383.5 t "theoretical average"

enter image description here

The averaging of fitting requires a fit:

fit a "data" via a
plot "data" t "data", a t "calculated average"

enter image description here

Miguel
  • 7,497
  • 2
  • 27
  • 46
  • Hey Miguel, Thank you very nice for the nice answer. It is definitely helpful if one would average over the entire time interval. Is it possible to have short time sequences where one can average? For example an average value between t=0 and t=5, then continuing with t=5, t=10. Basically to go from average to average. Is this possible? – Physther Feb 06 '15 at 17:23
  • You can set the interval like this `fit [0:5] a ...` – Miguel Feb 06 '15 at 18:15