MATLAB code to evaluate audio loundness over time
Any audio recording is generally assumed to have units that are proportional to Pascals (Pa).  This is the instantaneous pressure of the sound wave above (positive) or below (negative) the ambient pressure.  

(To actually get Pascals from the WAV file, you need to know the calibration factor for your recording system.)  

Loudness of sound (in air) is generally reported as Sound Pressure Level (SPL) in decibels. SPL (in dB) and pascals are related as


Pa_ref = 20e-6;  %reference pressure for SPL
SPL_dB = 10*log10( (Pa / Pa_ref).^2 );


If you use the instantaneous pressure values (ie, the values straight from the WAV file), this equation will give you the instantaneous SPL.  Based on the graph that you showed, you don't want the instantaneous SPL.  You want a time-smoothed SPL.

To get a time-smoothed SPL, the standard approach is to extract the envelope of the pressure signal.  There are lots of ways of doing this.  One way is to rectify and low-pass filter the signal.  In this case, your processing might look like this:


%load and calibrate the data
[wav,fs_Hz]=audioread(myfilename);  %load the WAV file
my_cal_factor = 1.0;  %the value for your system to convert the WAV into Pascals
wav_Pa = wav * my_cal_factor;


%extract the envelope
smooth_sec = 0.125;  %"FAST" SPL is 1/8th of second.  "SLOW" is 1 second;
smooth_Hz = 1/smooth_sec;
[b,a]=butter(1,smooth_Hz/(fs_Hz/2),'low');  %design a Low-pass filter
wav_env_Pa = sqrt(filter(b,a,wav_Pa.^2));  %rectify, by squaring, and low-pass filter


%compute SPL
Pa_ref = 20e-6;  %reference pressure for SPL in Air
SPL_dB = 10.0*log10( (wav_env_Pa ./ Pa_ref).^2 ); % 10*log10 because signal is squared


%plot results
figure;
subplot(2,1,1);
t_sec = ([1:size(wav_Pa)]-1)/fs_Hz;
plot(t_sec,wav_Pa);
xlabel('Time (sec)');
ylabel('Pressure (Pa)');


subplot(2,1,2)
plot(t_sec,SPL_dB);
xlabel('Time (sec)');
ylabel('SPL (dB)');
yl=ylim;ylim(yl(2)+[-80 0]);