Skip to content

Instantly share code, notes, and snippets.

@rejuvyesh
Last active November 26, 2021 15:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rejuvyesh/9936599 to your computer and use it in GitHub Desktop.
Save rejuvyesh/9936599 to your computer and use it in GitHub Desktop.
gcc phat algo
for i = 1:3
tau(i) = gcc_phat(x{i}(1,:), x{i}(2,:))
end
function tau = gcc_phat(sig1, sig2)
% Find FFT for the signals
fft1 = fft(sig1, fftSize(sig1));
fft2 = fft(sig2, fftSize(sig2));
% Find R(\Tau)
G12 = fft1.*conj(fft2);
denom = abs(G12);
R = G12./denom;
% Maximize R ?
r = ifft(R);
d1 = real(r);
d2 = max(abs(r));
tau = find(abs(r)==d2);
end
function fftsz = fftSize(sig)
% Find 2^x such that 2^x>2*nSamples
nSamples = length(sig)
fftsz = 2;
while fftsz < 2*nSamples
fftsz = fftsz*2;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment