You are on page 1of 11

PROJECT REPORT

Tone Identification
Using Cross Correlation

Prepared By:

Sourabh Khandelwal 2019UEE1278


Mahendra Jeengar 2019UEE1272
Vishal Kumar 2019UEE1271
Objective:
Our aim is to find out that from the several given
audio signal, which audio matches with our test audio
signals.

Project Deliverable: From a given set of digit audio


clips (1-5), we’ve to verify the matching tone by
providing a digit audio clip (any) and then plot the
correlation of each sample with test audio signal.
Flow Chart with expected
Input-Output :

Expected Input: One Test Audio Signal


4-5 sample audio signal

Expected Ouput: Cross Correlation sequence between


every sample and test signal
Output Examples:
Working Algorithm:
The similarity between two signals are measured by means of taking
auto correlation between two signals. In zeroth time , the amplitude
is maximum. Then you find out , the two signals are highly similar.

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 is sampling frequency of audio file.


% fs is sampling frequency we're considering.

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');

% Read the first sample file.


[y1, Fs1] = audioread('sounds/one.wav');
y1 = y1';
y1 = y1(1,:);
y1 = y1';
% Correlation between sample file and test file
z1 = xcorr(x,y1);

% Maximum value where intensity of frequencies is high 6


m1 = max(z1);
l1 = length(z1);
t1 = -((l1-1)/2):1:((l1-1)/2);
t1 = t1';
figure;
plot(t1,z1); grid on;
title('Cross Correlation between Test File and First Sample');
Matlab Code:
% Read second sample file
y2 = audioread('sounds/two.wav');
y2 = y2';
y2 = y2(1,:);
y2 = y2';
z2 = xcorr(x,y2);
m2 = max(z2);
l2 = length(z2);
t2 = -((l2-1)/2):1:((l2-1)/2);
t2 = t2';
figure;
plot(t2,z2); grid on;
title('Cross Correlation between Test File and Second Sample');
% Read the third sample file
y3 = audioread('sounds/three.wav');
y3 = y3';
y3 = y3(1,:);
y3 = y3';
z3 = xcorr(x,y3);
m3 = max(z3);
l3 = length(z3);
t3 = -((l3-1)/2):1:((l3-1)/2);
t3 = t3';
figure;
plot(t3,z3); grid on;
title('Cross Correlation between Test File and Third Sample');

% Read forth sample file


y4 = audioread('sounds/four.wav');
y4 = y4';
y4 = y4(1,:);
y4 = y4';
z4 = xcorr(x,y4);
m4 = max(z4);
l4 = length(z4);
t4 = -((l4-1)/2):1:((l4-1)/2);
t4 = t4';
figure;
plot(t4,z4); grid on;
title('Cross Correlation between Test File and Fourth Sample');
Matlab Code:
% Read the fifth file
y5 = audioread('sounds/five.wav');
y5 = y5';
y5 = y5(1,:);
y5 = y5';
z5 = xcorr(x,y5);
m5 = max(z5);
l5 = length(z5);
t5 = -((l5-1)/2):1:((l5-1)/2);
t5 = t5';
figure;
plot(t5,z5); grid on;
title('Cross Correlation between Test File and Fifth Sample');

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!

You might also like