Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot average of noise values in Gnuplot

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

like image 269
Physther Avatar asked Feb 05 '15 15:02

Physther


1 Answers

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

like image 105
Miguel Avatar answered Oct 22 '22 10:10

Miguel