# Checking order of two audio clips with a delay

4 visualizaciones (últimos 30 días)
Habib el 17 de Abr. de 2023
Respondida: Yash el 25 de Abr. de 2023
Suppose I have two audio arrays recorded from two microphones a distance d apart. I am trying to figure out which array is a delayed version of the other; I want to know which microphone started receiving the sound before the other one. I am trying to write a code to figure out where the sound is coming from. This must be done using correlation as the sounds obviously are not exact copies.
Thank you.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Walter Roberson el 17 de Abr. de 2023
See xcorr possibly with the lags output

Iniciar sesión para comentar.

### Respuestas (1)

Yash el 25 de Abr. de 2023
Hi Habib,
To determine which microphone received the sound first, you can use cross-correlation. The basic idea is to shift one of the audio signals by a certain time delay and then calculate the correlation between the two signals at each time delay. The time delay that results in the maximum correlation value indicates the time delay between the two signals, and thus which microphone received the sound first.
Here's some example code in MATLAB that demonstrates how to perform cross-correlation:
Note that this code assumes that the two signals have the same sample rate and are synchronized in time.
% Load the two audio signals
% Determine the length of the signals
n1 = length(mic1);
n2 = length(mic2);
% Determine the maximum possible time delay between the signals
maxdelay = abs(n1 - n2);
% Perform cross-correlation between the two signals
corr = xcorr(mic1, mic2);
% Find the time delay corresponding to the maximum correlation value
[~, delay] = max(corr);
delay = delay - (n1 + n2 - 1);
% Determine which microphone received the sound first
if delay > 0
disp('Microphone 1 received the sound first');
else
disp('Microphone 2 received the sound first');
end
In this code, mic1 and mic2 are the two audio signals recorded from the two microphones. The xcorr function is used to perform cross-correlation between the two signals, and the max function is used to find the maximum correlation value and its corresponding time delay. Finally, the time delay is compared to zero to determine which microphone received the sound first.
I hope this helps :)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Correlation and Convolution en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by