r This module provides several tools involving correlated noise.

There is a function for calculating auto-correlation coefficients and a class for use in generating random noise with specified auto-correlation characteristics.

>>> noise_gen = CorrelatedNoiseGenerator(acfcoeffs=[1.0, 0.5, 0.3, 0.1])
>>> test_noise = noise_gen.corr_normal(num_values=100000)
>>> autocorr(test_noise, lastlag=6)

autocorrtools.selfcorr(x, lag=1)

computes the self-correlation of a vector for a specified lag. This is a support function for autocorr.

x (float array): array to be correlated lag (int): specifies the lag for the correlation calculation
a single correlation coefficient at the specified lag.
autocorrtools.autocorr(x, lastlag=10)

computes the self-correlation coefficients of x from lag = 0 to lag = lastlag

x (float array): array to be correlated lastlag (int): the final lag value to be calculated
autocorrtools.build_acf_matrix(acfcoeffs, size)

builds a normalized auto-correlation matrix that has dimensions of size*size.

acfcoeffs (float array): the desired auto-correlation coefficients size (int): the size of the ultimate noise array
class autocorrtools.CorrelatedNoiseGenerator

This correlated noise generator class takes advantage of the fact that the entries in the cholesky decomposition of the acf matrix rapidly approach limiting values. This means that we do not need to build a large acf matrix: instead we make it large enough that the entries in the cholesky matrix have reached limiting values. We extract those limiting values along with a matching set of initial random numbers.


Uses acfcoeffs and cholesky decomposition to calculate final_coeffs, the limiting values in the cholesky matrix columns. There will be as many such values as there are entries in acfcoeffs.

An initial set of N[0,1] random numbers are generated and stored in r[]. With this setup completed, correlated random number can be generated by:

r[] dot final_coeffs[]

Calculates and returns a NumPy ndarray of length num_values. The values are normally distributed with a mean of zero, a standard deviation of 1, and an auto-correlation that closely approximates the values given by acfcoeffs when this object was instantiated.

num_values (int): the desired length of the output array