Time delay using xcorr function, two microphones

1 view (last 30 days)
Michal Rocinski
Michal Rocinski on 15 May 2020
Answered: Nikhil Sonavane on 18 May 2020
I need to determine the time difference in the signal arrival between two microphones. The microphones are 2m apart, I play two chrip audio signals and record it using 'audiorecorder'. As a result, I receive the plot below. One color is the signal recorded by one microphone, and the other color is the signal recored by the other one. So my question is how should I use xcorr function to get delay and is it even possible? I know vector of delays samples divided by sample frequency is equal to delay in seconds.
Thank you for any help.
close all;
clear all;
if true
clear;figure; grid on; hold on;
Fs = 4000; %sample frequency [Hz]
dt = 5; %time
r=audiorecorder(Fs,16,2); %recording
% convert to time (s)
tmax = length(my_Speech)/Fs;
t = linspace(0, tmax, dt*Fs);
axis([0 tmax*1000 -2 2]);
xlabel('time (ms)');
% analysis
j = 1;
for i=1:length(my_Speech)
if my_Speech(i)>0.15
pick(j) = 1000*i/Fs;
fprintf('%3d --> %8.1f ms\n',j, pick(j));

Answers (1)

Nikhil Sonavane
Nikhil Sonavane on 18 May 2020
You may refer another MATLAB answer which may help you solve your query.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!