BPM detection using Gamedev algorithm

조회 수: 5 (최근 30일)
Sagi Shtainman
Sagi Shtainman 2019년 7월 21일
댓글: Federico Dentesano 2020년 11월 22일
Hello everyone, I tried writing to use Gamedev algorithm in matlab to extract the BPM of a metronome but something isnt working.
I don't get the right BPM for the metronome used.
Hopefully someone can inspect my code and find whats the problem.
% CIRCULAR BUFFERING
filename='120 BPM 4_4 Wood Metronome HD.mp3';
format long;
[y,Fs] = audioread(filename);
yLeft=y(:,1);
yRight=y(:,2);
count=0;
len=length(yLeft);
numOfWin=len/(43*1024); % the length of window in samples (43*1024)
numOfWin=floor(numOfWin) ; %numOfWin- the num. of complete windows withn the song
newNumSamp=numOfWin*(43*1024);
yLeft=y(1:newNumSamp,1);
yRight=y(1:newNumSamp,2);
%CREATE LEFT & RIGHT MATRIX
LReshapeData=reshape(yLeft,[1024,numOfWin*43]);
RReshapeData=reshape(yRight,[1024,numOfWin*43]);
EWin=zeros(1,43);
% %create the energ buffer for the first window:
for segmentInd=43:-1:1
Eseg=sum((LReshapeData(:,segmentInd).^2)+(RReshapeData(:,segmentInd).^2) );
EWin((43-segmentInd)+1)=Eseg;
end
for segmentInd=44:numOfWin*43
Eseg=sum((LReshapeData(:,segmentInd).^2)+(RReshapeData(:,segmentInd).^2) );
avgE=sum(EWin)/43;
VarE=(1/43)*sum( (EWin-avgE).^2);
C=(-0.0025714*VarE)+1.5142857;
if EWin(1)> abs(C)*avgE
count=count+1;
end
EWin(1:end)=[Eseg,EWin(1:42)];%shift right the buffer in 1 segment
end
tsec=newNumSamp/Fs; % t=n*Ts- the total length in seconds
tmin=tsec/60;
numBPM=count/tmin;
  댓글 수: 1
Federico Dentesano
Federico Dentesano 2020년 11월 22일
Hi have you finished the code? I am trying to understand how BPM tracking works and this code was helpful, I would like to see it complete if you have it..

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

답변 (1개)

Dinesh Yadav
Dinesh Yadav 2019년 8월 5일
The missing points in the above implementation are as follows:-
  • The first sample points you have used for comparing average energy to "C" is 1:1024, but the second sample you have used for comparing is of 44th column i.e. 44032:43056 samples. Therefore, you are missing to compare energies of 2nd to 43rd column. Change your update "EWin" command code as shown below:
EWin(1: end)=[Ewin(2:43),Eseg];
  • The second one is related to flooring of sample points. Even after flooring you should store those extra sample points and compute and compare energies of those also. Here the sample points after flooring have been discarded so even if there is a beat at the ending the above algorithm won't detect that.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by