Skip to content

Generalized Cross Correlation Estimator implementation based on numpy.

License

Notifications You must be signed in to change notification settings

SiggiGue/gccestimating

Repository files navigation

Generalized Cross Correlation (GCC) Estimates

CodeFactor Coverage Status Documentation Status

This project provides estimators for the generalized cross correlation according to Knapp and Carter 1976 [KC76].

Implemented Estimators (compare [KC76])

The generalized Estimator can be described by

where denotes the cross power spectrum of and . In this project, all estimates are computed in the spectral domain using the Wiener-Kinchin relations (e.g. ).

Following estimators are implemented:

  • Cross Correlation

  • Roth; same as the estimator describing the Wiener-Hopf filter

  • Smoothed Coherence Transform (SCOT):

  • PHAse Transform (PHAT):

  • Eckart

  • Hanan Thomson (HT), Maximum Likelihood estimator with

Insalling

This repo uses a pyproject.toml file generated with the dependency and package managing tool poetry.

This package can be installed with an up to date pip pip install .

or using poetry poetry install

otherwise use your own favorite way to install/use the code in your environment.

Example

import numpy as np
import matplotlib.pylab as plt
from gccestimating import GCC, corrlags

 # generate some noise signals
nsamp = 1024

noise1 =  0.5*np.random.randn(nsamp)
sig1 = np.zeros(nsamp) + noise1

noise2 =  0.5*np.random.randn(nsamp)
sig2 = np.zeros_like(sig1) + noise2

noise_both = np.random.randn(256)

sig1[:256] = noise_both
sig2[500:756] = noise_both

# create a lags array
lags = corrlags(2*nsamp-1, samplerate=1)

# Create the a GCC instance    
gcc = GCC(sig1, sig2)

def mkplot(est, p):
    plt.subplot(p)
    plt.plot(lags, est.sig, label=est.name)
    plt.legend()

# calculate the standard cc estimate
cc_est = gcc.cc()

# plot it using the mkplot function
mkplot(cc_est, 611)

# plot the other estimates
mkplot(gcc.scot(), 612)
mkplot(gcc.phat(), 613)
mkplot(gcc.roth(), 614)
mkplot(gcc.ht(), 615)
mkplot(gcc.eckart(noise_both, noise1, noise2), 616)

# compare cc to the timedomain based 
# implementation from Numpy
# you will see: very close (errors < 1e-13)
plt.figure()
plt.plot(np.correlate(sig1, sig2, 'full'))
plt.plot(gcc.cc())
plt.show()

References

[KC76]: Knapp and Carter, "The Generalized Correlation Method for Estimation of Time Delay", IEEE Trans. Acoust., Speech, Signal Processing, August, 1976

About

Generalized Cross Correlation Estimator implementation based on numpy.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages