Delay Estimation (GCC-PHAT)

Generalized Cross-Correlation for estimating the time delay between two microphone signals that captured the same sound source. This is the basis of acoustic source localisation.

Algorithm:

  1. FFT both signals.

  2. Multiply one spectrum by the conjugate of the other (cross-spectrum).

  3. Apply a weighting (PHAT normalises by magnitude, sharpening the peak).

  4. Inverse-FFT back to the time domain.

  5. The position of the peak tells you the delay in samples.

pyminidsp.get_delay(sig_a, sig_b, margin, weighting=1)[source]

Estimate the delay between two signals using GCC.

Parameters:
  • sig_a – First signal.

  • sig_b – Second signal.

  • margin – Search +/- this many samples around zero-lag.

  • weighting – GCC_SIMP or GCC_PHAT.

Returns:

(delay, entropy) tuple. Delay in samples (positive = sig_b lags sig_a).

Estimate the delay between two signals.

Parameters:
  • sig_a – First signal.

  • sig_b – Second signal.

  • margin – Search ± this many samples around zero-lag.

  • weightingGCC_SIMP or GCC_PHAT.

Returns:

(delay, entropy) tuple. delay is in samples (positive = sig_b lags sig_a). entropy is normalised entropy of the correlation peak region (closer to 1.0 = less trustworthy).

import numpy as np
sig_a = md.sine_wave(1024, freq=440.0, sample_rate=44100.0)
sig_b = np.roll(sig_a, 5)
delay, ent = md.get_delay(sig_a, sig_b, margin=20, weighting=md.GCC_PHAT)
# delay == 5
pyminidsp.get_multiple_delays(signals, margin, weighting=1)[source]

Estimate delays between a reference signal and M-1 other signals.

Parameters:
  • signals – List of numpy arrays (signals[0] is reference).

  • margin – Search window in samples.

  • weighting – GCC_SIMP or GCC_PHAT.

Returns:

numpy array of M-1 delay values.

Estimate delays between a reference signal and M − 1 other signals.

Parameters:
  • signals – List of arrays (signals[0] is the reference).

  • margin – Search window in samples.

  • weightingGCC_SIMP or GCC_PHAT.

Returns:

Array of M - 1 delay values.

pyminidsp.gcc(sig_a, sig_b, weighting=1)[source]

Compute the full generalized cross-correlation between two signals.

Parameters:
  • sig_a – First signal.

  • sig_b – Second signal.

  • weighting – GCC_SIMP or GCC_PHAT.

Returns:

numpy array of N doubles (zero-lag at index ceil(N/2)).

Compute the full generalized cross-correlation between two signals.

Parameters:
  • sig_a – First signal.

  • sig_b – Second signal.

  • weightingGCC_SIMP or GCC_PHAT.

Returns:

Array of N doubles. The zero-lag value is at index ceil(N / 2).