Comparing two matrices, as fast as possible

조회 수: 41 (최근 30일)
Altemur Çelikayar
Altemur Çelikayar 2021년 3월 12일
댓글: Altemur Çelikayar 2021년 3월 16일
Hello Everyone
I am currently writing a music comparing AI code on MATLAB. It is my graduation project.
Firstly, I printed filtered with grayscale 1,0 spectrogram graph of our saved music with the function i write and i recorded 5 second sound. I also processed same way to the sound I recorded from external mic.
SPECTROGRAM OF MUSIC:
5 SECOND RECORDED FILE:
They are both 129xSamples
How can i compare and search from the exact music matrix as fast as possible? I wrote the little function but i cant use with this way. It took apx 56 second and its too long for one song.
Here my little code:
function compare_algorithm(Music1,Sample1)
%Takes data from file
load("datas_audio/"+Music1)
load("datas_audio/"+Sample1)
%Deletes .mat part
Music1 = extractBefore(Music1,".");
Sample1 = extractBefore(Sample1,".");
M1=eval(Music1);
S1=eval(Sample1);
[a,b] = size(M1);
[c,d] = size(S1);
sira = 1;
list1=[];
%Comparing row by row until the finish to findout how long will it take
for SS = 1:b-d+1
count = 0;
for jj = sira:d+(sira-1)
for ii = 1:129
if M1(ii,jj)==S1(ii,jj-sira+1)
count=count+1;
end
end
end
sira=sira+1;
CC=count/(c*d);
list1(end+1) = CC;
end
MAX=max(list1)
end
What is the best way to compare two matrices?
I am planning to compare from 100 to 200 music sample as fast as possible. I am open to any recommendations.
Thanks a lot
Altemur :D
  댓글 수: 7
Altemur Çelikayar
Altemur Çelikayar 2021년 3월 12일
@Walter Roberson Unfortunately I ve 4 month :P lol
Walter Roberson
Walter Roberson 2021년 3월 12일
In that case I recommend that you do not worry as much about using a technique that is "as fast as possible". If you get into "as fast as possible" then your entire approach might have to be rewritten if you swap your SIMM chips into different banks, since that could affect the timing of caches. An approach that takes you 4 years to build and saves 3 nanoseconds per year is a better candidate for "as fast as possible" compared to an approach that only takes you 2 years to build.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shubham Rawat
Shubham Rawat 2021년 3월 16일
Hi Altemur,
I have written a code and I had done intersction of both the matrices column wise without using the for loop.
%loading matrices
load('counting_stars.mat');
load('girenfile.mat');
%transposing the matrices so that number of columns should be same.
a = counting_stars';
b = girenfile';
%intersecting both matrices
[c, ia, ib] = intersect(a, b, 'rows');
c will give the common columns, ia and ib will give all the indices which are common in both a and b.
You may look into this documentation of intersect.
Hope this Helps!
  댓글 수: 1
Altemur Çelikayar
Altemur Çelikayar 2021년 3월 16일
oh thanks a lot :D i ll use intersect for speed

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by