Go Down

Topic: Record wav file from PDM microphone (Read 390 times) previous topic - next topic

MohitB

Is it possible to create a wav file from PDM microphone. I am using Adafruit PDM Microphone Breakout with Arduino MKR zero. Is it necessary to convert PDM data to PCM format to save it in wav file?

DVDdoug

#1
Jun 01, 2018, 10:11 pm Last Edit: Jun 01, 2018, 10:38 pm by DVDdoug
Yes.  WAV files are PCM.

Virtually all digital audio is PCM, although it my be compressed/decompressed or converted to/from some other format.   

Almost all ADCs and DACs are integer-PCM.      Almost all audio editing/processing is done in PCM.   

PCM is a sequence of amplitude sample-values, sampled at a fixed sample-rate.    If you don't know what I'm talking about, the Audacity Website has a nice-gentile introduction to how digital audio works.

christop

PDM is a digital signal--it's either on or off--but it's not really like an ADC. It's more like a raw Sigma-Delta signal.

You could try sampling the signal with a digital input pin (at 1-3MHz) and then average a bunch of on-off samples in software into PCM samples, or you could add a hardware low-pass filter (a simple RC filter may do) and sample it with the ADC.

The first option seems like a difficult task to me (and is more suitable to low-level assembly programming), and the second option defeats the purpose of using PDM in the first place.

MarkT

#3
Jun 04, 2018, 04:30 pm Last Edit: Jun 04, 2018, 04:33 pm by MarkT
Some heavyweight DSP processing is needed to handle PDM - an I2S microphone is the sort to go
for if you don't want to handle that task and just want the samples.  PDM's advantage seems to be
only one signal wire is needed to send it.

You can crudely filter PDM with an analog RC filter and sample that, but don't expect hifi performance!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

el_supremo

The latest release (1.42) of Teensyduino can handle a PDM microphone. Don't know about its ability to record to SD card but have a look here about half way down the page.

Pete
Don't send me technical questions via Private Message.

pjrc

I wrote that PDM filter!  :)

It has much better passband flatness than the usual CIC approach, but even using a huge table lookup for pre-computed groups of 8 multiply-accumulate operations, it uses about 40% of the CPU time on a Teensy running at 96 MHz.

The remaining 60% is probably enough to get the data written to a SD card.  If you get a Teensy 3.x board to try this, in Arduino (with Teensy selected in the boards menu) click File > Examples > Audio > Recorder for code to continuously write incoming audio to a SD card.  The example uses normal I2S input, but it should be fairly straightforward to replace the I2S input object with the PDM one.

A Teensy 3.6 would be ideal for this sort of project, since the 180 MHz speed will let you run the filter in about half the time, and it has a SD card socket with native 4-bit SDIO which is faster than the SPI-based SD card interface used on most other boards.

Go Up