calculate dynamic range of mp3 in matlab

You can use the audioread function in MATLAB to read the mp3 file and get the audio data. Then you can calculate the dynamic range of the audio using the peak2rms function.

Here's an example code snippet:

main.m
% read audio
[x, fs] = audioread('example.mp3');

% convert to mono if necessary
if size(x,2) > 1
    x = mean(x,2);
end

% calculate dynamic range
rms_val = rms(x);
peak_val = max(abs(x));
dynamic_range = 20*log10(peak_val/rms_val);
234 chars
13 lines

In this code, by calculating dynamic_range, we get the dynamic range of the audio in decibels (dB) which describes the difference between the loudest and quietest parts of the audio signal.

Note that the peak2rms function can also be used instead of calculating this manually. This function returns the dynamic range in dB directly.

related categories

gistlibby LogSnag