Contenu principal

Sound Pressure Measurement of Octave Frequency Bands

R2026b

This example shows how to measure sound pressure levels of octave frequency bands using splMeter. An interactive app lets you adjust the frequency weighting, bandwidth, and audio source while viewing live measurements.

Sound Pressure Measurement

Many applications involving acoustic measurements must take into account the non-linear characteristics of the human auditory system. For that reason, sound levels are generally reported in decibels (dB) on a log-spaced frequency scale. Frequency weighting adjusts levels to account for the ear's frequency-dependent sensitivity. A-weighting is the most common, as it attenuates low and high frequencies similarly to the auditory system at moderate levels. C-weighting is an alternative for measuring very loud sounds, as it mimics the human ear's flatter response at levels over 100 dB.

This example uses the splMeter System object to measure sound pressure levels (SPL). You can measure sound pressure levels of audio files or perform live SPL measurements with a microphone.

You can specify the weighting filter (Z/A/C) and frequency bandwidth used for the measurements. For more information on the weighting filters, see the Audio Weighting Filters example.

Audio Device I/O with audiostreamer

The application uses these audiostreamer (Audio Toolbox) features to simplify audio I/O logic:

  • Calling play in blocking mode keeps the I/O loop paced to real time.

  • Switching modes between "player" and "full-duplex" enables the application to use a single object to handle all audio I/O scenarios.

  • Calling release before switching modes avoids the warning issued when the device is reconfigured while still running.

Setting Up the SPL Meter

The splMeter System object measures sound pressure levels in octave frequency bands. Create an splMeter configured for 1-octave bandwidth with Z-weighting (no frequency weighting):

Fs = 44100;
meter = splMeter(SampleRate=Fs, Bandwidth="1 octave", ...
                 TimeWeighting="Fast", TimeInterval=0.5, ... 
                 FrequencyWeighting="Z-weighting");

Key properties of splMeter:

  • Bandwidth -- "1 octave", "2/3 octave", or "1/3 octave". Higher resolution reveals more spectral detail.

  • FrequencyWeighting -- "Z-weighting" (none), "A-weighting" (models human hearing at moderate levels), or "C-weighting" (models human hearing at loud levels).

  • TimeWeighting -- "Fast" (125 ms integration) or "Slow" (1 s integration).

  • TimeInterval -- Determines how often the meter produces output rows.

Use the meter to monitor a pink noise signal. Since TimeInterval is 0.5 seconds, the meter needs at least 22050 samples (about 6 frames of 4096) before it produces valid output:

source = dsp.ColoredNoise(Color="pink", SamplesPerFrame=4096);
numFrames = ceil(meter.TimeInterval * Fs / 4096);
for ii = 1:numFrames
    x = 0.25 * source();
    [LT,Leq,Lpeak,Lmax] = meter(x);
end

The meter returns four matrices. Each row corresponds to one time interval, and each column corresponds to a center frequency band. The outputs are:

  • LT -- Time-weighted SPL (the instantaneous level with exponential averaging)

  • Leq -- Equivalent continuous SPL (energy average over the entire measurement)

  • Lpeak -- Peak SPL (maximum instantaneous sample value)

  • Lmax -- Maximum time-weighted SPL observed so far

Retrieve the center frequencies and display the per-band levels:

cf = round(meter.getCenterFrequencies, 2, "significant");
disp(table(cf(:), Leq(end,:)', VariableNames=["Frequency (Hz)", "Leq (dB)"]));
    Frequency (Hz)    Leq (dB)
    ______________    ________

           32          76.552 
           63           76.85 
          130          76.362 
          250          76.475 
          500          77.244 
         1000          77.264 
         2000          77.301 
         4000          77.208 
         7900          76.906 
        16000          76.564 

Streaming Audio with audiostreamer

The audiostreamer object provides a simple blocking interface for real-time audio I/O. Create a player and examine it:

as = audiostreamer(Mode="player", SampleRate=Fs);

In "player" mode, play sends one frame to the audio device and blocks until the device is ready for the next frame. This blocking behavior paces the processing loop at real time without timers or callbacks:

for ii = 1:numFrames
    x = source();          % generate or read one frame
    [LT,~,~,~] = meter(x); % measure SPL
    play(as, x);           % blocks until device is ready
end

To record from a microphone, switch to "full-duplex" mode. Always call release before changing the mode to avoid device warnings:

release(as);
as.Mode = "full-duplex";
audioIn = playrec(as, zeros(frameSize,1), frameSize);

The playrec function simultaneously plays silence (or any signal) and records from the microphone, returning the recorded audio for analysis.

Clean up the objects created in this section before running the full application:

release(meter);
release(as);
release(source);

Run the Application

Execute soundPressureMeasurementExampleApp to run the demonstration. The application displays a bar chart of SPL measurements on the left with controls on the right.

Application Controls

The application provides the following controls:

  • Audio Source -- Select from pink noise, microphone input, or several built-in audio files. You can also load a custom audio file.

  • Mute -- Mute the audio output (disabled in microphone mode).

  • Weighting -- Select Z-weighting (none), A-weighting, or C-weighting.

  • Bandwidth -- Select 1 octave, 2/3 octave, or 1/3 octave band resolution.

The bar chart displays four measurements for each frequency band:

  • Green bars: LXf (time-weighted SPL)

  • Blue bars: LXeq (equivalent continuous SPL)

  • Orange markers: LXmax (maximum SPL)

  • Gray markers: LXpeak (peak SPL)

where X represents the selected frequency weighting (Z, A, or C).

See Also

|

Topics