diff --git a/bin/autocorr b/bin/autocorr new file mode 100755 index 0000000..fd17608 --- /dev/null +++ b/bin/autocorr @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +# autocorr.py +# Tal Wrii + +""" + This file is part of Datatools. + + Datatools is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Datatools is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Datatools. If not, see . +""" + +from __future__ import print_function + +import sys, os +import numpy + +name = os.path.basename(sys.argv[0]) +usage = \ +"""Usage: %s + +Work out the autocorrelation of the data. This can be used to detect +non-independence of samples (e.g periodicity, seasonal effects, +"continuity of data") + +Example: + cat tutorial/x.dat | %s | plot """ % (name,name) + +if __name__ == '__main__': + if '-h' in sys.argv or '--help' in sys.argv: + sys.exit(usage) + + data = [ float(x) for x in sys.stdin if x.strip() ] + convolution = numpy.correlate(data, data, mode='full') + correlation = convolution[convolution.size //2:] / numpy.inner(data, data) + for value in correlation: + print(value)