Sound Pressure Level Calculator
by
Chad Greene
28 Mar 2012
Function calculates sound pressure level in decibels, given a pressure signal in pascals.

spl(p_Pa,ref)

function [SPL] = spl(p_Pa,ref)
% Calculate sound pressure level (in dB) of given pressure signal 'p_Pa'.
% Chad Greene 2012
% Pressure signal input p_Pa must be in units of pascals.
% Pressure signal vector should be long enough to capture nature of the
% signal. In other words, a single pressure value is not sufficient for
% rootmeansquare calculation.
% Note that this does account for frequency content. Aweighted decibels
% (dBA) are frequencydependent. This function does not compute dBA.
%
% Example using Matlab's builtin train whistle sound:
%
% load train % (let's assume y is has pascals as its units)
% spl(y,'air')
% ans =
% 84.6
%
% The example above gives the same as the following:
% load train % (let's assume y is has pascals as its units)
% spl(y,20*10^6)
% ans =
% 84.6
%
% Note: Typically we only write decibels to integer values or one decimal
% place. Anything on the hundredthofadecibel level is probably just
% noise and can be ignored.
% Calculate root mean square value of pressure signal
p_rms = sqrt(mean(p_Pa.^2));
% Define the correct reference pressure:
switch ref
case {'air','Air','AIR','gas','Gas','GAS'}
p_ref = 20*1e6; % reference pressure in air is typically 20 uPa
case {'water','Water','WATER','liquid','Liquid','LIQUID','SALTWATER','saltwater','Saltwater'}
p_ref = 1*1e6; % reference pressure in water is typically 1 uPa
otherwise
p_ref = ref; % reference pressure can be any userdefined value 'ref'
end
SPL = 20*log10(p_rms/p_ref);
end


Contact us