Contents

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 Microphones, click the name of the device in the list in the Command window, or access the device in the array returned by daq.getDevices command. For this example, the microphone is connected on channel 0 of National Instruments® device 9234 on CompactDAQ Chassis NI cDAQ-9174 with ID cDAQ1Mod3.

devices = daq.getDevices
devices(3)
devices = 

Data acquisition devices:

index Vendor Device ID           Description           
----- ------ --------- --------------------------------
1     ni     cDAQ1Mod1 National Instruments NI 9205
2     ni     cDAQ1Mod2 National Instruments NI 9263
3     ni     cDAQ1Mod3 National Instruments NI 9234
4     ni     cDAQ1Mod4 National Instruments NI 9201
5     ni     cDAQ1Mod5 National Instruments NI 9402
6     ni     cDAQ1Mod6 National Instruments NI 9213
7     ni     cDAQ1Mod7 National Instruments NI 9219
8     ni     cDAQ1Mod8 National Instruments NI 9265
9     ni     Dev1      National Instruments PCIe-6363
10    ni     Dev2      National Instruments NI ELVIS II


ans = 

ni: National Instruments NI 9234 (Device ID: 'cDAQ1Mod3')
   Analog input subsystem 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 Session and Add Microphone Channel

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

s = daq.createSession('ni');
addAnalogInputChannel(s,'cDAQ1Mod3', 0, 'Microphone');

Set Sensor Properties

Set the microphone's Sensitivity 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 changes device configuration.

s.Channels.Sensitivity = 0.037;
s.Channels
ans = 

Data acquisition analog input microphone channel 'ai0' on device 'cDAQ1Mod3':

          Sensitivity: 0.037
MaxSoundPressureLevel: 136
    ExcitationCurrent: 0.001
     ExcitationSource: None
             Coupling: DC
       TerminalConfig: Differential
                Range: -200 to +200 Pascals
                 Name: ''
                   ID: 'ai0'
               Device: [1x1 daq.ni.CompactDAQModule]
      MeasurementType: 'Microphone'
        ADCTimingMode: ''


Configure And Start Acquisition

Set the duration to 4 seconds and the rate to 51200 scans per second and start acquisition.

s.DurationInSeconds = 4;
s.Rate = 51200;
[data,time] = s.startForeground();

Analyze Data

Use audioplayer to Playback the Acquisition

p = audioplayer(data, s.Rate);
play(p);
Warning: Unable to play audio because no audio outputs were found. 
Warning: Unable to play audio because no audio outputs were found. 

Examine Data in Time Domain

plot(time,data)
xlabel('Time (secs)');
ylabel('Sound Pressure (pascals)');

Examine the Data in Frequency Domain

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

  • Calculate the length of signal

  • Calculate the nfft

  • Calculate amplitude and frequency

length = double(s.NumberOfScans);
nfft = 2^nextpow2(length);
y = fft(data,nfft)/length;
frequency = s.Rate/2*linspace(0,1,nfft/2+1);
amplitude = 2*abs(y(1:nfft/2+1));

Plot the Single-Sided Amplitude Spectrum

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

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

Was this topic helpful?