I have two audio signals where x[n] is a farend signal and x1[n] is our nearend signal.
A part of the farend signal is coming into the nearend signal with a certain delay (echo.) I want to estimate that delay (echo delay estimation) for which I've used the 'cross correlation' xcorr function of MATLAB. When I take 5000 samples of both the nearend and farend signals and apply xcorr, it gives an accurate delay estimation in terms of index which in our case was 266.
Then I decreased the number of samples from 5000 to 4500 and used the same wav files for delay estimation using xcorr and it gave a delay of 167.
Why does the xcorr function of MATLAB only work accurately at 5000 or above samples? When we decrease the number of samples below 5000, why doesn't it give us an accurate delay estimation? Is there any particular reason behind this? Both of the audio wav files used, the graphs, and the MATLAB code are shared below.
Note:
Please consider the value of X in the graph for time delay.
Correct delay estimation code:
clear all
close all
[x, fs] = audioread('D:1.wav');
[x1, ~] = audioread('D:2.wav');
x = x(1:5000);
x1 = x1(1:5000);
[a,b] = xcorr(x,x1);
[~, index] = max(a);
delay = b(index);
Wrong delay estimation code:
clear all
close all
[x, fs] = audioread('D:1.wav');
[x1, ~] = audioread('D:2.wav');
x = x(1:4500);
x1 = x1(1:4500);
[a,b] = xcorr(x,x1);
[~, index] = max(a);
delay = b(index);