Professional Documents
Culture Documents
Tone Identification
Using Cross Correlation
Prepared By:
The idea is that one signal x(t) is fixed and the other y(t) sweeps
through it.
Each sweep is a value of the cross correlation Rxy(T). T being the
sweep.
So at T = 0, Rxy = integral of x(t)y(t)
At T = 1, Rxy(1) = integral of x(t)y(t+1)
Rxy gives peaks at which x(t) and y(t) are most similar
Step wise Detail:
1. First we read test audio file and store it in a vector ‘x’
2. Now read first sample audio file and store its sample sequence in a vector ‘y1’.
3. Now we use xcorr() function to obtain correlation sequence and store it in ‘z1’.
4. Now we find the length of correlation sequence i.e ‘l1’ and maximum value in z1
where intensity of frequencies is high i.e ‘m1’.
Step wise Detail:
5. Now we make plot between t1 and z1 and similarly using above steps we find
t2…tn and z1…zn and find plots for all.
6. Now by the plots obtained we can determine that which sample is matching with
test file . By just observing the peaks in graphs one can say if they are similar or not.
A peak in plot indicates high similarity between two signals.
Some of the plot examples are given below.
5
Matlab Code:
clc;
clear all;
close all;
filename = 'sounds/test.wav';
[voice, Fs] = audioread(filename);
fs = 45000;
x = voice;
x = x';
x = x(1,:);
x = x';
% dt = 1/Fs;
% t = 0:dt:(length(y)*dt)-dt;
% plot(t,y); xlabel('Seconds'); ylabel('Amplitude');
a = [m1 m2 m3 m4 m5];
m = max(a);
% h = audioread('allow.wav');
if m <= m1
fprintf("Sound matched with file 1");
end
if m <= m2
fprintf("Sound matched with file 2");
end
if m <= m3
fprintf("Sound matched with file 3");
end
if m <= m4
fprintf("Sound matched with file 4");
end
if m <= m5
fprintf("Sound matched with file 5");
end
%else
% fprintf("Failed");
Thank You!