Main Content

calibrateMicrophone

R2026b

Calibration factor for microphone

Description

calibrationFactor = calibrateMicrophone(micRecording,fs,SPLreading) returns the calibration factor for the microphone used to create micRecording.

example

calibrationFactor = calibrateMicrophone(micRecording,fs,SPLreading,Name,Value) specifies options using one or more Name,Value pair arguments.

Example: calibrationFactor = calibrateMicrophone(micRecording,fs,SPLreading,'FrequencyWeighting','Z-weighting') returns the calibration factor for an SPL reading that applies Z-weighting.

Examples

collapse all

This diagram depicts the setup used in the example:

To run this example, you must connect a microphone and loudspeaker to a full-duplex sound card, and use an SPL meter to determine the true loudness level.

Create a 1 kHz sine wave at a sample rate of 48 kHz and a duration of 3 seconds.

fs = 48e3;
f0 = 1e3;
dur = 3;
t = (0:3*fs-1)'/fs;
tone = sin(2*pi*f0*t);

Create an audiostreamer object to write the sine wave to your loudspeaker and simultaneously read from your microphone.

streamer = audiostreamer(Mode="full-duplex",SampleRate=fs, ...
    PlayerChannels=1);

Play the 1 kHz sinusoid through your loudspeaker and simultaneously record audio from your microphone. While the tone plays, note the true SPL measurement as reported from your SPL meter.

micRecording = playrec(streamer,tone);
SPL = 78.2; % read from physical SPL meter

Compute the calibration factor for the microphone.

calibrationFactor = calibrateMicrophone(micRecording,fs,SPL);

The diagram depicts the example setup and data flow.

To run this example, you must connect a microphone to your audio card, generate a 1 kHz tone using an external device, and use an SPL meter to determine the true loudness level.

Specify a 48 kHz sample rate for your audio device and a 3-second duration for acquiring audio. Create an audiostreamer object to record from your audio device.

fs = 48e3;
dur = 3;

recorder = audiostreamer(Mode="recorder",SampleRate=fs);

Start the 1 kHz test tone using an external loudspeaker. Record from the microphone for the specified duration. While the recording runs, note the true SPL measurement as reported from your SPL meter.

record(recorder,dur*fs);
waitfor(recorder);

SPL = 77.7; % read from physical SPL meter

micRecording = read(recorder);
release(recorder);

Compute the calibration factor for the microphone.

calibrationFactor = calibrateMicrophone(micRecording,fs,SPL);

Input Arguments

collapse all

Audio signal used to calibrate microphone, specified as a column vector (mono) or matrix of independent channels (stereo). micRecording must be acquired from the microphone you want to calibrate. The recording should consist of a 1 kHz test tone.

Data Types: single | double

Sample rate of microphone recording in Hz, specified as a positive scalar. The recommended sample rate for new recordings is 48 kHz.

Data Types: single | double

Sound pressure level reported from meter in dB, specified as a scalar or vector. If SPLreading is specified as a vector, it must have the same number of elements as columns in micRecording.

Data Types: single | double

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: calibrateMicrophone(micRecording,fs,SPLReading,'PressureReference',22)

Reference pressure for dB calculation in pascals, specified as a positive scalar. The default reference pressure (20 micropascals) is the common value for air.

Data Types: single | double

Frequency weighting used by physical meter, specified as 'A-weighting', 'C-weighting', or 'Z-weighting'.

Data Types: char | string

Output Arguments

collapse all

Microphone calibration factor, returned as a scalar or row vector with the same number of elements as SPLreading.

Data Types: single | double

Algorithms

To determine the calibration factor for a microphone, the calibrateMicrophone function uses:

  • A calibration tone recorded from the microphone you want to calibrate.

  • The sample rate used by your sound card for AD conversion.

  • The known loudness, usually determined using a physical SPL meter.

  • The frequency weighting used by your physical SPL meter.

  • The atmospheric pressure at the recording location.

The diagram indicates a typical physical setup and the locations of required information.

The calibrationFactor is set according to the equation:

CalibrationFactor=10((SPLreadingk)/20)rms(x)

where x is the microphone recording passed through the weighting filter specified in the FrequencyWeighting argument. k is 1 pascal relative to the PressureReference calculated in dB:

k=20log10(1PressureReference).

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020a