Comparing two matrices, as fast as possible

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

It seems to me the best way to compare two matrices is by computing the root mean square of the differences.
sqrt(sum(abs(b.^2-a.^2),'all'));%comparing matrix a to b
I really do not understand your question.
Walter Roberson
Walter Roberson el 12 de Mzo. de 2021
Sublimerickal Hypostatic Eka-metamimetic Classification gives the fastest possible comparisons. The technique is due to be invented in only 17.83 billion years, by some small furry creatures from Alpha Centauri. ( Never bet against the cleverness of small furry creatures from Alpha Centauri.)
Replace
X = extractBefore(Y,".")
with
[~,X] = fileparts(Y);
That file loading relies on a lot of magic. You should revise that code to use simpler, more robust data importing.
Altemur Çelikayar
Altemur Çelikayar el 12 de Mzo. de 2021
@David Hill I ve filtered spectrogram graph from Counting_Stars.mp3(figure1). Second graph is my random 5 second part from music which i recorded with my mic with spotify. Matrix 1 is 129x70774 and Matrix 2 is 129x1721. I need to find which part of Matrix1 similar to Matrix2 and where it begins
Altemur Çelikayar
Altemur Çelikayar el 12 de Mzo. de 2021
@Stephen Cobeldick Sure :D I will thx a lot
Altemur Çelikayar
Altemur Çelikayar el 12 de Mzo. de 2021
@Walter Roberson Unfortunately I ve 4 month :P lol
Walter Roberson
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.

Iniciar sesión para comentar.

Respuestas (1)

Shubham Rawat
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.
You may look into this documentation of intersect.
Hope this Helps!

Categorías

Productos

Versión

R2020a

Preguntada:

el 12 de Mzo. de 2021

Comentada:

el 16 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by