To get the root-mean-square (RMS) of a audio file in Matlab, you can use the rms function. Here's an example code:
main.m164 chars4 lines
Here, file_path is the path to your audio file. The audioread function is used to read the audio file and it returns two variables: y which is a vector containing the audio data, and fs which is the sampling frequency of the audio file.
Then, use rms function to compute RMS value of audio data y which will give you the RMS value of the audio signal. The variable rms_value will contain the computed RMS value.
Note: rms function can also operate on a single vector of audio data directly.
Here is the same code but to process multiple audio files together,
main.m384 chars10 lines
Here folder_path is the path to a folder which contains audio files of the same extension. file_list is the list of all audio files present in the folder of the specified extension. The dir function will list all the files with the specified extension. The fullfile function will combine folder path and filename to get the complete path of the file.
Then, use for loop to iterate through each file, read the file using audioread and compute the RMS value of audio data y using rms function. The fprintf function is used to print the computed RMS value.
gistlibby LogSnag