'How to find time shift in large noisy samples without FFT

Context: I have two sound recordings that come from two seperated mics. The goal is to find the angle of the source using a DOA (direction of arrival) algorithm. Sample frequency is 44100 Hz and DOA algorithm is meant to run with buffers of 1024, 2048 or 4096 samples.

Data is bit noisy (the source is someone speaking in a room) but I don't think it matters too much anyway.

enter image description here

What I have done: Using previously asked questions, I managed to write a decent algorithm which makes use of a "cross correlation using FFT" algorithm.

def cross_correlation(buf1: np.ndarray, buf2: np.ndarray) -> np.ndarray:
    
    # FFT on buffer 1
    f1 = np.fft.fft(buf1)
    
    # FFT on flipped buffer 2
    f2 = np.fft.fft(np.flipud(buf2))
    
    # Multiply the two FFTs, then IFFT
    cc = np.real(np.fft.ifft(f1 * f2))
    
    # Shift result (not shifted by default)
    return np.fft.fftshift(cc)

def compute_shift(buf1: np.ndarray, buf2: np.ndarray) -> int:
    
    # Cross correlation using FFT
    cc = cross_correlation(buf1, buf2)
    
    # Account for shift (zero index in the middle)
    zero_index = int(buf1.size / 2) - 1
    
    # Get and return shift 
    shift = zero_index - np.argmax(cc)
    return shift

What I want: A similar algorithm that doesn't use the FFT

After some research I found this formula but I am having a hard time working with it:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source