Menu

Plot Running or Block Average Using gnuplot

Help
2005-06-21
2013-02-10
  • Angelo R. Rossi

    Angelo R. Rossi - 2005-06-21

    Hello:

    I would like to use gnuplot to plot a running average or sometimes called a block average. 

    Let's say there are 1000 values of y, and x runs from 1 to 1000. 

    I tried plotting that many points, and it doesn't work well with gnuplot.  Because of the density of points, it appears as if a given x value has two or more y values.

    But, I can use a running average where I take a number of y values (e.g 100) and average them over a length of an x interval:

    running average = (100 y values)/(length of interval)

    How do I plot this running average given that I have a simple data file with two columns consisting of x and y values?

    Regards,

    Angelo

     
    • Hans-Bernhard Broeker

      You can only do block averaging with gnuplot, not sliding-window averages.  For block averaging, you have to map all x coordinates inside the block:

      x_to_block(x) = factor*int(x/factor)

      then plot the file with this filter applied and the "smooth uniq" post-filter:

         plot 'data' using (x_to_block($1)):2 smooth uniq

       

Log in to post a comment.