필터 지우기
필터 지우기

Extract BPM from audio file

조회 수: 20 (최근 30일)
Rita Campos
Rita Campos 2023년 10월 3일
댓글: Ana Campos 2023년 10월 17일
Hi,
I have a code that extracts several features from audio signals. I managed to make everything work so far but the extraction of the BPM.
Any tips on how to write code for that? I looked online before asking here but couldn't find anything that worked. An example of part of my code is shown below. The idea would be to write the code in a way that it integrates the BPM feature calculation in a similar way to what was done for spectral centroid and others. Please see code below. I've got Audio toolbox (if relevant to mention).
Thanks in advance
% select the folder path where audio files are located
folderPath = 'C:\Users\xxxxx\Documents\MATLAB\xxxxExperiment3';
%get a list of all audio files in the folder
fileList = dir(fullfile(folderPath,'*.wav')); % Change the file extension if needed
%Specify the chosen audio features
chosenFeatures = {'mfcc','spectralCentroid','spectralRolloff','BPMinute'};
% Loop through each audio file
for i = 1:length(fileList)
% Read the audio file
filePath = fullfile(folderPath,fileList(i).name);
[audio,sampleRate] = audioread(filePath);
% Extract chosen audio features
features = extractAudioFeatures(audio,sampleRate,chosenFeatures);
% Do something with extracted features (e.g. save to a file)
saveFilePath = fullfile(folderPath,[fileList(i).name '_features.mat']);
save(saveFilePath,'features');
end
% Function to extract the chosen audio features
function features = extractAudioFeatures(audio,sampleRate,chosenFeatures)
% Convert audio to mono if it is stereo
if size(audio,2) > 1
audio = mean(audio,2);
end
% Normalize the audio signal
audio = audio / max(abs(audio));
% Extract the chosen audio features
features = struct();
if ismember('mfcc', chosenFeatures)
mfccCoeffs = mfcc(audio,sampleRate);
features.mfcc = mean(mfccCoeffs,2); % Take the mean across time
end
if ismember('spectralCentroid',chosenFeatures)
spectCentroid = spectralCentroid(audio,sampleRate);
features.spectCentroid = mean(spectCentroid); %single value
end
end
  댓글 수: 3
Ana Campos
Ana Campos 2023년 10월 17일
Thanks all for your help! And apologies for the delay.

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

답변 (1개)

akshatsood
akshatsood 2023년 10월 13일
편집: akshatsood 2023년 10월 13일
Hi Rita,
I understand that you want to extract BPM from an audio file. Since you have the Audio Toolbox, you can leverage the Beat Detector plugin from the Audio Plugin Example Gallery that estimates and displays a BPM decision using the specified onset detection method. All the example plugins including the Beat Detector can be accessed as follows
Redirect to the above page and scroll down to the Beat Detector plugin
The above plugin can be executed by running the following in the MATLAB command window
>> audioTestBench('audiopluginexample.BeatDetector')
It will open up the Audio Test Bench. Now, from the Test Bench View, the required audio file can be selected by clicking on the gear icon in the Input block
To visualize the BPM value, follow these steps:
  1. Select the desired onset detection method from the available options.
  2. Click the 'Run' button to initiate the analysis.
  3. Click on the 'Visualize Plugin' button located in the Toolstrip.
The results will be displayed in the following format:
I hope this helps.
  댓글 수: 1
Ana Campos
Ana Campos 2023년 10월 17일
Thanks very much! And sorry for the delay.

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

카테고리

Help CenterFile Exchange에서 Audio Plugin Creation and Hosting에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by