# Comparison using cross correlation [closed]

I have 2 stereo audio files to compare.

Comparison of files include change in frequency, amplitude, phase shift

Code:

a = wavread("C:\Users\Narendranath\Desktop\Recordings\Release_2\Chirp.wav",[2, 100]);

[cor1, lag1] = xcorr(a(2, :), b(2, :));
subplot(1,1,1);
plot2d(cor1(1,:));


I do not know how to proceed this further. Any ideas?

• MATLAB? Octave? something else? – robert bristow-johnson Jul 24 '17 at 6:00
• @robertbristow-johnson The question says scilab. – Peter K. Jul 24 '17 at 11:18
• my eyes missed it. i dunno scilab. – robert bristow-johnson Jul 24 '17 at 11:29
• How are we supposed to debug your code without seeing your code? Even if we saw the code, the question would, I'm afraid, be off-topic here. – Marcus Müller Jul 24 '17 at 18:07

A stereo audio file will have 2 channels. You will need to select each channel separately and do cross-correlation. The Xcorr function understands only real or complex vectors as input but you are probably passing both channels at the same time.

If audio.wav is your file :

[y,Fs,bits]=wavread("audio.wav");Fs,bits
audio_channel1= y(:,1)
audio_channel2= y(:,2)


Here audio_channel1 & audio_channel2 are the vectors you need to cross correlate with the reference audio/signal.

• Thank you!! But while for cross-correlation in scilab we use xcorr(x,y) where x and y are the two audio signal. Where to use audio_channel1 and audio_channel2 as arguments here – Sanjaya Jul 24 '17 at 9:53
• How to combine audio_channel1 & audio_channel2 into a single vector – Sanjaya Jul 24 '17 at 10:00
• To answer the second question : it might not be good idea to combine them. Rather you can either ignore one of the channels (if they are very similar) or get two xcorrelation outputs and see what fits your need. For 1st question in xcorr(x,y)... X is the audio_channel1 and Y is your reference signal for channel 1(or vice versa). If you have only one reference signal you can repeat the process xcorr(audio_channel2,Y) , again Y is your reference signal for channel2. – Perscitius Jul 24 '17 at 16:24
• a = wavread("C:\Users\Narendranath\Desktop\Chirp.wav",[2, 100]); b = wavread("C:\Users\Narendranath\Desktop\Chirp.wav",[2, 100]); cor1 = xcorr(a(2, :), b(2, :)); Now how can I compare the two waves to find the similarity – Sanjaya Jul 25 '17 at 4:38
• cor1 in your code gives the un-normalized cross correlation. If you normalise it, a value of 1 is where the signals are perfectly correlated. if you use [cor1,lag1]=xcorr(a(2,:),b(2,:) , lag1 gives you the lag. Ref: help.scilab.org/doc/5.5.2/en_US/xcorr.html To solve your problem try to understand what is correlation and how it will help you rather than using code mechanically. please refer to this: stackoverflow.com/questions/15371577/… and in.mathworks.com/help/signal/examples/… – Perscitius Jul 25 '17 at 12:13