BPM detection using Gamedev algorithm
5 ビュー (過去 30 日間)
古いコメントを表示
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
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!