Comparing two matrices, as fast as possible
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 12 de Mzo. de 2021
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.
Respuestas (1)
Shubham Rawat
el 16 de Mzo. de 2021
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.
Hope this Helps!
Ver también
Categorías
Más información sobre Time-Frequency Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!