2 years, 8 months ago.

LPC 1768 Microphone Data Acquisition


I am new to the mbed environment, so please excuse me for asking this simple question. I am working with mbed LPC 1768 for sound acquisition. The microphone I am using is INMP401 (from Sparkfun - amplified).

I need real time visualization of the audio data that I got, so I tried using Labview interface (using this link: https://os.mbed.com/cookbook/Interfacing-with-LabVIEW). However, it did not work successfully - the mbed cannot read the data correctly and the sampling rate is way too low.

I know for sure that my microphone is not broken - since I could record the data successfully with an Arduino. Would you mind letting me know how to acquire the data from the microphone and display it in realtime? Just for the ballpark, the sampling frequency should be around 6 khz.

Thank you so much.

1 Answer

2 years, 8 months ago.

If you need 6k samples out in real time then you need to output as binary integer data, outputting as text or floats will be too slow.

You have 2 bytes of ADC data per sample and some basic data alignment method is needed. The simplest method that comes to mind is to put a 0 byte at the start of each value. The chances of the least significant byte being 0 are fairly small so as a first assumption the first non-zero byte is the start of a 3 byte data set. You then read sets of 3 bytes and convert them to data values. If at any point you get a first byte that is not 0 you throw it away and take the next non-zero byte as the first one.

This should align your data fairly quickly and not give too much data corruption if you lose a byte for any reason. It's not idea but assuming you are using a serial port you don't have that much extra bandwidth to play with for things like checksums.

6k samples, 3 bytes per sample = 6,000*3*10 = 180,000 minimum baud rate on the UART so you need to use at least 230400 baud..

Something like this should do for the mbed side: (not that I've tested it beyond checking for syntax errors)

#include "mbed.h"

AnalogIn micIn(p15);
Ticker SampleTicker;
volatile bool SampleNow;

void onTick()
    SampleNow = true;

main ()
    PC.baud(115200); // you need at least this baud rate
    SampleNow  = false;
    while(true) {
        if (SampleNow) {
            int16_t value = micIn.read_u16();
            SampleNow = false;
            PC.putc(value >> 8);
            PC.putc(value & 0x00ff);

On the PC side, read the bytes, check the first value is zero, convert the next two into a 16 bit integer and display it however you want.

A side though, one way to reduce the data rate would be to do some processing on the LPC first. I've previously run an ADC at 5 kHz into a 1024 sample buffer while running an FFT on the previous buffer of data. That allows you to output the spectrum of the input with a lag of 200 ms. It depends a lot on what you definition of real time is.

posted by Andy A 15 Oct 2018