Main Content

Acquire and Analyze Sound Pressure Data from an IEPE Microphone

This example shows how to acquire and display sound pressure data from a PCB® IEPE array microphone, Model 130E20. The sensor is recording sound pressure generated by a tuning fork at Middle C (261.626 Hz) frequency.

Discover Devices That Support Microphones

To discover a device that supports microphone measurements, access the device in the table returned by the daqlist command. For this example, the microphone is connected on channel 0 of National Instruments® device NI 9234 on CompactDAQ Chassis NI cDAQ-9178 with ID cDAQ1Mod3.

d = daqlist("ni")
d =

  12×4 table

     DeviceID                 Description                    Model             DeviceInfo     
    ___________    __________________________________    _____________    ____________________

    "cDAQ1Mod1"    "National Instruments NI 9205"        "NI 9205"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod2"    "National Instruments NI 9263"        "NI 9263"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod3"    "National Instruments NI 9234"        "NI 9234"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod4"    "National Instruments NI 9201"        "NI 9201"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod5"    "National Instruments NI 9402"        "NI 9402"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod6"    "National Instruments NI 9213"        "NI 9213"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod7"    "National Instruments NI 9219"        "NI 9219"        [1×1 daq.DeviceInfo]
    "cDAQ1Mod8"    "National Instruments NI 9265"        "NI 9265"        [1×1 daq.DeviceInfo]
    "Dev1"         "National Instruments PCIe-6363"      "PCIe-6363"      [1×1 daq.DeviceInfo]
    "Dev2"         "National Instruments NI ELVIS II"    "NI ELVIS II"    [1×1 daq.DeviceInfo]
    "Dev3"         "National Instruments PCIe-6363"      "PCIe-6363"      [1×1 daq.DeviceInfo]
    "Dev4"         "National Instruments PCIe-6363"      "PCIe-6363"      [1×1 daq.DeviceInfo]

deviceInfo = d{3, "DeviceInfo"}
deviceInfo = 

ni: National Instruments NI 9234 (Device ID: 'cDAQ1Mod3')
   Analog input supports:
      -5.0 to +5.0 Volts range
      Rates from 1000.0 to 51200.0 scans/sec
      4 channels ('ai0','ai1','ai2','ai3')
      'Voltage','Accelerometer','Microphone','IEPE' measurement types
   
This module is in slot 3 of the 'cDAQ-9178' chassis with the name 'cDAQ1'.


Create a DataAcquisition and Add Microphone Channel

Create a DataAcquisition and add a channel with Microphone measurement type.

dq = daq("ni");
ch = addinput(dq, "cDAQ1Mod3", "ai0", "Microphone");

Set Sensor Properties

Set the microphone channel Sensitivity property to the value specified in the sensor's data sheet. For this sensor, the Sensitivity value is 0.037 Volts/Pascal. Examine the channel properties to see the changes in the device configuration.

ch.Sensitivity = 0.037;
ch
ch = 

    Index    Type      Device       Channel     Measurement Type              Range                  Name      
    _____    ____    ___________    _______    ___________________    ______________________    _______________

      1      "ai"    "cDAQ1Mod3"     "ai0"     "Microphone (Diff)"    "-200 to +200 Pascals"    "cDAQ1Mod3_ai0"

Configure and Start Acquisition

Set the acquisition scan rate to 51200 scans per second, then use read to acquire four seconds of data.

dq.Rate = 51200;
tt = read(dq, seconds(4));
t = tt.Time;
data = tt.cDAQ1Mod3_ai0;

Analyze Data

Use audioplayer to play back the acquired microphone signal

p = audioplayer(data, dq.Rate);
play(p);

Examine the Data in the Time Domain

plot(t, data);
ylabel('Sound Pressure (pascals)');

Examine the Data in the Frequency Domain

Use fft and the following parameters to calculate the single-sided amplitude spectrum of the incoming data:

  • Calculate the length of signal (number of samples or entries in the table)

  • Calculate the nfft

  • Calculate amplitude and frequency

len = height(tt);
nfft = 2^nextpow2(len);
y = fft(data,nfft)/len;
f = dq.Rate/2*linspace(0,1,nfft/2+1);
A = 2*abs(y(1:nfft/2+1));

Plot the Single-Sided Amplitude Spectrum

plot(f,A);
xlim([0 1000]);
xlabel('Frequency (Hz)');
ylabel('Amplitude');

The plot shows a spike at 261.626 Hz. This matches the frequency of the tuning fork.