Last active
November 26, 2021 15:17
-
-
Save rejuvyesh/9936599 to your computer and use it in GitHub Desktop.
gcc phat algo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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