Main Content

splMeter

Measure sound pressure level of audio signal

Description

The splMeter System object™ computes sound pressure level measurements. The object returns measurements for:

  • frequency-weighted sound levels

  • fast or slow time-weighted sound levels

  • equivalent-continuous sound levels

  • peak sound levels

  • maximum sound levels

To implement SPL metering:

  1. Create the splMeter object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

SPL = splMeter creates a System object, SPL, that performs SPL metering.

SPL = splMeter(Name,Value) sets each property Name to the specified Value. Unspecified properties have default values.

Example: SPL = splMeter('FrequencyWeighting','C-weighting','SampleRate',12000) creates a System object, SPL, that performs C-weighting and operates at 12 kHz.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Width of analysis bands, specified as 'Full band', '1 octave', '2/3 octave', or '1/3 octave'. If Bandwidth is specified as 'Full band', the SPL meter returns one set of measurements for the whole frequency band. If Bandwidth is specified as '1 octave', '2/3 octave', or '1/3 octave', the SPL meter returns one set of measurements per octave or fractional-octave band.

Tunable: No

Data Types: char | string

Frequency range of the filter bank in Hz, specified as a two-element row vector of positive monotonically increasing values. Frequency bands centered above SampleRate/2 are excluded.

Tunable: No

Dependencies

To enable this property, set Bandwidth to '1 octave', '2/3 octave', or '1/3 octave'.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Order of the octave filter, specified as an even integer.

Tunable: No

Dependencies

To enable this property, set Bandwidth to '1 octave', '2/3 octave', or '1/3 octave'.

Data Types: single | double

Frequency weighting applied to input, specified as 'A-weighting', 'C-weighting', or 'Z-weighting', where Z-weighting corresponds to no weighting. The frequency weighting is designed and implemented using the weightingFilter System object.

Tunable: No

Data Types: char | string

Time weighting, in seconds, for calculation of time-weighted sound level and maximum time-weighted sound level, specified as 'Fast' or 'Slow'. The TimeWeighting property is used to specify the coefficient of a lowpass filter.

  • 'Fast' – 1/8

  • 'Slow' – 1

Tunable: Yes

Data Types: char | string

Reference pressure for dB calculations in Pa, specified as a positive scalar.

Tunable: Yes

Data Types: single | double

Time interval, in seconds, to report equivalent-continuous, peak, and maximum time-weighted sound levels, specified as a positive scalar.

Tunable: No

Data Types: single | double

Scalar (mono input) or vector (multichannel input) calibration factor multiplied by input.

To set the calibration factor using a reference tone, use calibrate.

Tunable: No

Data Types: single | double

Input sample rate in Hz, specified as a positive scalar.

Tunable: No

Data Types: single | double

Usage

Description

[Lt,Leq,Lpeak,Lmax] = SPL(audioIn) returns measurement values for the time-weighted (Lt) sound level of the current input frame, audioIn. The object also returns the equivalent-continuous (Leq), peak (Lpeak), and maximum time-weighted (Lmax) sound levels of the input to your SPL meter.

example

Input Arguments

expand all

Audio input to the SPL meter, specified as a column vector or matrix. The columns of the matrix are treated as independent audio channels.

Data Types: single | double

Output Arguments

expand all

Time-weighted sound level in dB, returned as a column vector, matrix, or 3-D array the same type as audioIn.

Size and interpretation of the outputs depend on what the Bandwidth property is set to:

  • 'Full band' (default) –– Lt, Leq, Lpeak, and Lmax are returned as column vectors or matrices the same size as audioIn.

  • '1 octave', '2/3 octave', or '1/3 octave' –– Lt, Leq, Lpeak, and Lmax are returned as L-by-B-by-C arrays.

    • L –– Number of rows in audioIn

    • B –– Number of octave bands

    • C –– Number of columns in audioIn

Data Types: single | double

Equivalent-continuous sound level in dB, returned as a column vector, matrix, or 3-D array the same type as audioIn.

Size and interpretation of the outputs depend on what the Bandwidth property is set to:

  • 'Full band' (default) –– Lt, Leq, Lpeak, and Lmax are returned as column vectors or matrices the same size as audioIn.

  • '1 octave', '2/3 octave', or '1/3 octave' –– Lt, Leq, Lpeak, and Lmax are returned as L-by-B-by-C arrays.

    • L –– Number of rows in audioIn

    • B –– Number of octave bands

    • C –– Number of columns in audioIn

Data Types: single | double

Peak sound level in dB, returned as a column vector, matrix, or 3-D array the same type as audioIn.

Size and interpretation of the outputs depend on what the Bandwidth property is set to:

  • 'Full band' (default) –– Lt, Leq, Lpeak, and Lmax are returned as column vectors or matrices the same size as audioIn.

  • '1 octave', '2/3 octave', or '1/3 octave' –– Lt, Leq, Lpeak, and Lmax are returned as L-by-B-by-C arrays.

    • L –– Number of rows in audioIn

    • B –– Number of octave bands

    • C –– Number of columns in audioIn

Data Types: single | double

Maximum time-weighted sound level in dB, returned as a column vector, matrix, or 3-D array the same type as audioIn.

Size and interpretation of the outputs depend on what the Bandwidth property is set to:

  • 'Full band' (default) –– Lt, Leq, Lpeak, and Lmax are returned as column vectors or matrices the same size as audioIn.

  • '1 octave', '2/3 octave', or '1/3 octave' –– Lt, Leq, Lpeak, and Lmax are returned as L-by-B-by-C arrays.

    • L –– Number of rows in audioIn

    • B –– Number of octave bands

    • C –– Number of columns in audioIn

Data Types: single | double

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

calibrateCalibrate meter using calibration tone with known level
getCenterFrequenciesCenter frequencies of filters
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Use the splMeter System object™ to measure the A-weighted sound pressure level of a streaming audio signal. Specify a two second time-interval for reporting and a fast time-weighting. Visualize the SPL measurements using the timescope object.

Create a dsp.AudioFileReader object to read in an audio file frame by frame. Create an audioDeviceWriter object to listen to the audio signal. Create a timescope object to visualize SPL measurements. Create an splMeter to measure the sound pressure level of the audio file. Use the default calibration factor of 1.

source = dsp.AudioFileReader("Ambiance-16-44p1-mono-12secs.wav");
fs = source.SampleRate;

player = audioDeviceWriter(SampleRate=fs);

scope  = timescope(SampleRate=fs, ...
    TimeSpanSource="property",TimeSpan=3, ...
    YLimits=[20 110], ...
    ShowLegend=true,BufferLength=4*3*fs, ...
    ChannelNames=["Lt_AF","Leq_A","Lpeak_A","Lmax_AF"], ...
    Name="Sound Pressure Level Meter");

SPL = splMeter(TimeWeighting="Fast", ...
    FrequencyWeighting="A-weighting", ...
    SampleRate=fs, ...
    TimeInterval=2);

In an audio stream loop:

  1. Read in the audio signal frame.

  2. Play the audio signal to your output device.

  3. Call the SPL meter to return the time-weighted, equivalent-continuous, peak, and maximum time-weighted sound levels in dB.

  4. Display the sound levels using the scope.

As a best practice, release your objects once complete.

while ~isDone(source)
    x = source();
    player(x);
    [Lt,Leq,Lpeak,Lmax] = SPL(x);
    scope([Lt,Leq,Lpeak,Lmax])
end

release(source)
release(player)
release(SPL)
release(scope)

The splMeter enables you to monitor sound pressure level for octave and fractional-octave bands. In this example, you monitor the equivalent-continuous sound pressure level of 1/3-octave bands.

Create a dsp.AudioFileReader object to read in an audio file frame by frame. Create an audioDeviceWriter object so you can listen to the audio signal. Create an splMeter to measure the octave sound pressure level of the audio file. Use the default calibration factor of 1. Create a dsp.ArrayPlot object to visualize the equivalent-continuous SPL for each octave band.

source = dsp.AudioFileReader('JetAirplane-16-11p025-mono-16secs.wav');
fs = source.SampleRate;

player = audioDeviceWriter('SampleRate',fs);

SPL = splMeter( ...
    'Bandwidth','1/3 octave', ...
    'SampleRate',fs);
centerFrequencies = getCenterFrequencies(SPL);

scope  = dsp.ArrayPlot(...
    'XDataMode','Custom', ...
    'CustomXData',centerFrequencies, ...
    'XLabel','Octave Band Center Frequencies (Hz)', ...
    'YLabel','Equivalent-Continuous Sound Level (dB)', ...
    'YLimits',[20 90], ...
    'ShowGrid',true, ...
    'Name','Sound Pressure Level Meter');

In an audio stream loop:

  1. Read in the audio signal frame.

  2. Play the audio signal to your output device.

  3. Call the SPL meter to return the equivalent-continuous sound pressure level in dB.

  4. Display the sound levels using the scope. Update the scope only when the equivalent-continuous sound pressure level has changed.

As a best practice, release your objects once complete.

LeqPrevious = zeros(size(centerFrequencies));
while ~isDone(source)
    x = source();
    player(x);
    [~,Leq] = SPL(x);

    for i = 1:size(Leq,1)
        if LeqPrevious ~= Leq(i,:)
            scope(Leq(i,:)')
            LeqPrevious = Leq(i,:);
        end
    end

end

release(source)
release(player)
release(SPL)
release(scope)

Algorithms

expand all

Sound pressure level calculations follow the algorithms described in [1]. You can specify property values to conform to standards [2] and [3].

References

[1] Harris, Cyril M. Handbook of Acoustical Measurements and Noise Control. 3rd ed. American Institute of Physics, 1998.

[2] International Electrotechnical Commission. Electroacoustics - Sound level meters - Part 1: Specifications. IEC 61672-1:2013.

[3] American National Standards Institute. ANSI S1.4: Specification for Sound Level Meters. 1983.

Extended Capabilities

Version History

Introduced in R2018a