Question

is there a way of ploting a moving standard deviation in gnuplot?

I have a large file from which I am plotting my regular signal. Now I would need to calculate/plot the standard devation for y based on a frame from x.

Any ideas?

Thanks

Added description:

That is how my data is set up:

I plot using this command: plot "Data.csv" using 1:3 title 'Sample' ls 1

Data File looks like this

#Value1;Value2;Time
0.1;0.2;1
0.11;0.2;1.5
0.12;0.3;1.9
0.11;0.2;2.1
0.3;0.21;2.2
0.2;0.31;2.9

The time series is irregular. To calculate the standard dev I need to take into account a fixed frame that is time depended. In this example I would use a time frame of 1. So for the value at time 1.9 I would need to take all values into account between 1.4to 2.4.

Was it helpful?

Solution

I agree with @Christoph that python makes this much easier. Here is an example of how to compute the running stdev in python:

#!/usr/bin/env python2.7

import argparse

parser = argparse.ArgumentParser(description='Computes a moving standard deviation for a data file')
parser.add_argument('--number', '-n', help='Window size (number of points to either side)', type=int)
parser.add_argument('dataFile', help='Name of data file', type=str)

args = parser.parse_args()
n = args.number

# I hope you have numpy, it makes things much easier
import numpy as np

# assuming two-column time/datum format
data = np.loadtxt(args.dataFile)

for ii in range(n,len(data)-n):
    print data[ii,0], np.std(data[ii-n:ii+n+1,1])

Now you can call the script on the data file from gnuplot:

plot '<python boxcarStdev.py -n 5 mydata.dat'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top