<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Get amplitude (dB) from PDM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28248/get-amplitude-db-from-pdm</link><description>Hi, 
 for my sound application, I want to get the amplitude, or dB, of the PDM samples. 
 Are there any existing function implemented? If not, how can I code it on my own? 
 I already read about PDM. Is it true, that I only need to count the ones in</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 16 Dec 2017 14:18:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28248/get-amplitude-db-from-pdm" /><item><title>RE: Get amplitude (dB) from PDM</title><link>https://devzone.nordicsemi.com/thread/111563?ContentTypeID=1</link><pubDate>Sat, 16 Dec 2017 14:18:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cadd7268-e2c8-4dc1-88a7-c385f74ad86c</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Oh, now it is all clear. The naming of the variables are kind of confusing. Thank you very much for the information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get amplitude (dB) from PDM</title><link>https://devzone.nordicsemi.com/thread/111561?ContentTypeID=1</link><pubDate>Fri, 15 Dec 2017 08:22:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a6a496f-8311-4ac7-aa46-bab122688638</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;Thanks for the details! In this code you have the PCM available directly. There is no need to consider that the audio was originally in PDM format.&lt;/p&gt;
&lt;p&gt;In drv_mic.c, m_audio_buffer_handler() is executed in interrupt context. To avoid blocking the interrupt with time-consuming audio processing, the audio buffer (p_buffer) is passed on to m_audio_process() via app_scheduler.&lt;/p&gt;
&lt;p&gt;I recommend doing your amplitude calculations in m_audio_process(). The pdm_buf_t typed variable in m_audio_process() does contain PCM, although the naming could have been more clear.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get amplitude (dB) from PDM</title><link>https://devzone.nordicsemi.com/thread/111562?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2017 21:41:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24c0cf40-ccff-416f-b37d-9d39bb49a463</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Hi!
yeah, I&amp;#39;m using the nRF52 PDM peripheral (I use a thingy:52 device) and a customized FW (&lt;a href="https://github.com/NordicSemiconductor/Nordic-Thingy52-FW"&gt;original&lt;/a&gt;). There I get a PDM buffer provided (&lt;a href="https://github.com/NordicSemiconductor/Nordic-Thingy52-FW/blob/master/source/drivers/drv_mic.c"&gt;here&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;So I have to convert the PDM signal to PCM and use this one for further use?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get amplitude (dB) from PDM</title><link>https://devzone.nordicsemi.com/thread/111560?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2017 09:15:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e914a90-3cc9-47bc-983d-95177d5b5ec8</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;Hi David,&lt;/p&gt;
&lt;p&gt;are you using, or planning to use, the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pdm.html?cp=2_1_0_42#concept_tyv_452_yr"&gt;nRF52 PDM peripheral&lt;/a&gt; functionality?
(It is possible to sample a PDM signal using for example SPI or I2S, but this is not the typical approach)&lt;/p&gt;
&lt;p&gt;When using the PDM peripheral, the nRF52 will in hardware convert the 1-bit PDM samples to 16-bit PCM. Your firmware will never see the original PDM signal, only the resulting 16-bit PCM.
Calculating the amplitude of a PCM signal is more straight-forward.&lt;/p&gt;
&lt;p&gt;As the resulting PCM is a digital signal with a range of [-32767, 32767] (16-bit signed values) you would typically use decibel relative to full scale (dBFS) for the amplitude:
&lt;strong&gt;amplitude = 20 * log10(abs(sample) / 32767) dBFS&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To answer your specific question: No, I don&amp;#39;t believe you can determine the amplitude by counting the ones in the PDM signal. At the very least you would have to count the number and width of pulses. However, note that PDM is a sigma-delta modulated signal which includes a lot of high frequency quantization noise. Estimating the amplitude from this signal without low-pass filtering means you will include this noise in the estimate, which is probably not desirable.&lt;/p&gt;
&lt;p&gt;Audun&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>