There are 2 audio signals, X & Y.
X is of 15 second duration. The duration of Y is not given.
Y is a part of signal X (ie a small part of audio X is extracted & made into audio Y)
I have to find the starting & ending location, in seconds, in the signal X from where signal Y is derived.
I was told to NOT use built-in MATLAB functions like conv, xcorr etc.
So I wrote a MATLAB code which compares sample by sample of X & Y starting from the 1st sample.
clear;
[A1,FS1,NBITS1]=wavread('x.wav');
[A2,FS2,NBITS2]=wavread('y.wav');
for i=1:(length(A1)-length(A2)),
if(A1(i:i+length(A2)-1) == A2)
found = 1;
time1 = i/FS1;
time2 = (i+length(A2))/FS1;
break;
else
found=0;
end
end
A1 has 120000 samples, FS1 = 8000, NBITS1 = 16
A2 has 20000 samples, FS2 = 8000, NBITS2 = 16
Therefore,
120000/8000 = 15 sec(length of audio X)
20000/8000 = 2.5 sec(length of audio Y)
time1(starting time) = 6.5001 sec
time2(ending time) = 9.0001 sec
Just to make sure the code was correct, I plotted the impulse response of X & Y using fvtool & found that the impulse response of Y matches that of X between 6.5 to 9 seconds.
Now I want to verify the result using built-in MATLAB functions, namely xcorr
So I used
A3 = xcorr(A1,A2);
plot(A3);
A3 is 239999 samples long. Then using
[max idx] = max(A3)
Using the above index location I found the location of maximum correlation value to be at sample 172000. which gives the midpoint at 172000/8000=21.5sec(clearly wrong). However, the location of the maximum correlation value must come to 7.7501 samples. How do I obtain that from the above value?