/autocorrelation

C and Python interfaces to calculate the autocorrelation vs. lag of a signal. Supports considering only a certain bit of the input bytes. Useful for max_lag << input size. Tries to be somewhat memory efficient. Uses MPRF for precision, OpenMP for speed.

Primary LanguageC

autocorrelation.{c, py}

C and Python interfaces to compute the autocorrelation vs. lag of a signal.

Description

autocorrelation.c provides functions to compute the autocorrelation of a signal for the k first lags/delays. autocorrelation.py is a python interface for the C code.

Algorithm and optimisation

The algorithm used is the following:

,

where is the point of the signal, is its length, is its mean, and is its variance.

We re-express it as :

,

with

,

in order to speed up calculations with simple parallelizable forms for and and correcting for the induced errors using the relatively simple and .

In the case, it falls back to the variance normalized by itself (a.k.a. 1) and the corrections vanish.

Other details

  • It can comput the autocorrelations using the whole bytes or for each bits of every byte.
  • The whole input file is loaded into memory, but it's otherwise trying to be memory efficient.
  • MPFR is used for precision when working with big numbers.
  • openMP is used for parallelisation; some of the code might be suboptimal for single threaded execution.

Compiling

Using make

Simply execute make all

Manually

  • To compile a binary: gcc -O3 autocorrelation.c -o autocorrelation.out -Wall -lmpfr -lgmp -fopenmp
  • To compile a shared library: gcc -O3 -fPIC -shared autocorrelation.c -o autocorrelation.so -Wall -lmpfr -lgmp -fopenmp

For linux, add -DUNIX.