MEMS Microphone PDM to SPL via simple counting - Page 1
Forum section: electronics / projects

author: Poe
author_rank: Frequent Contributor
timestamp: June 07, 2022, 03:57:10 pm
content: MEMS microphones with aPulseDensityModulated output appear perfect forroughdB/SPL measurements by simply counting. I just need a sanity check or for someone to tell me what I'm missing.First, I understand that MEMS microphones are not the best choice for a highly accurate SPL meter. All I want to do here is measure the intensity of a ~5KHz sound sample between 80 to 120dB with maybe about +/-8dB of accuracy.Now, It's my understanding of PDM signals that the density of 1's (over a sufficient duration) is proportional to the average SPL.So if I was to simply poll a PDM signal every MEMS clock pulse while adding up all the high states over 100mS, then that number would effectively be proportional to my SPL value. Does that sound correct?PICs have counting peripherals that might be useful for this. Does the ESP32 have any peripheral that would help with this? I've seen people use SPI modules to pull in the data in-sync with the clock they're sending to the microphone.

author: jonpaul
author_rank: Super Contributor
timestamp: June 07, 2022, 04:58:50 pm
content: Check the definition of SPL, you can see this scheme will not work at all.A true SPL uses a microphone, preamplifier, filter ( eg A or C weighting) then level detection with specific attack, decay time, and finally a log Conversion to get db.A $20 Radio Shack meter will be far more accurate.Jon

author: Poe
author_rank: Frequent Contributor
timestamp: June 07, 2022, 06:18:12 pm
content: Quote from: jonpaul on June 07, 2022, 04:58:50 pmThank you for your reply.Rechecked the definition, but I can't see why this scheme will not work. Please elaborate.The MEMS microphone is a microphone with a built-in preamp. No weighting should be needed for this application since there's a fairly singular ~5kHz signal and there's a loose accuracy requirement, right? Is there another concern you might have doing this?The SPL measurement needs added to an existing circuit design. I've already purchased a hand-held decibel meter on Amazon for $50. It's how I came up with the above requirements.

author: Poe
author_rank: Frequent Contributor
timestamp: June 08, 2022, 06:21:41 pm
content: Would this topic be better placed in the beginner section or is there just not much experience with PDM and SPL?

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 08, 2022, 07:18:22 pm
content: I think your project is "advanced" enough that it wouldn't really fit in a "beginner" section.Given your requirements (well, the ones you gave at least), a simple calibration scheme should be enough without requiring fancy filtering/processing.One first remark is that your target range (80-100 dB SPL) is highish. Have you checked the characteristics of typical MEMS microphones? Make sure you pick one that is reasonably linear in this range.As to PDM to SPL, haven't thought your proposed approach through, but it doesn't seem too good to me at first sight.If you just count pulse density over a certain period, you're gonna get the average value, so neither the peak-to-peak amplitude nor the RMS amplitude, and I would personally compute the RMS amplitude and convert it to SPL. Not sure how you could get the RMS value from the pulse count only without reconstructing the PCM signal first, but I haven't given it a lot of thought yet so maybe there's some possible "trick".

author: Poe
author_rank: Frequent Contributor
timestamp: June 10, 2022, 02:15:20 am
content: Quote from: SiliconWizard on June 08, 2022, 07:18:22 pmThank you so much!Been too busy to sit down and think about this, but I think your right. It highlights a huge problem with the idea. In the back of my head I was going to do something like subtract out the average, but that's not possible is it. Summing more than ~10ms would just always give the same average reading.Dolp.Well thanks for saving me from hooking it up.Looks like the ESP32 has PDM inputs that will make this easy.

author: jonpaul
author_rank: Super Contributor
timestamp: June 10, 2022, 09:05:59 am
content: A single freq 5 kHz tone will fall outside the peak of the A weighted SPL.See sound weighting curves to see if SPL is the correct parameter.https://en.wikipedia.org/wiki/Weighting_filterAlso check equal loundness, Fletcher-Munsen curves.https://en.wikipedia.org/wiki/Equal-loudness_contourJon

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 10, 2022, 06:01:48 pm
content: You should try and write equations for the RMS value and figure out how to approximate it (within your accuracy requirement which is not drastic) while not requiring a full PCM reconstruction. That may be possible. Haven't again thought about it much, but I'm guessing there may be some simplifications here.If not, you may implement a simple PDM to PCM conversion first, which is not that difficult especially if you don't need high accuracy. You'll find resources online about this.What I would do myself though is probably use a MEMS microphone with I2S output instead of PDM (you can find many decent such microphones these days), interface it to some MCU with an I2S peripheral (a lot of choice as well), and then you'd have to deal with sample values directly. Then computing the RMS would be kinda trivial.