<?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>Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105124/digital-mems-microphone-im72d128v01-interface-with-nrf5430-via-pdm</link><description>Hi, 
 Iam currently working with NRF5340 module for the integration of MEMS microphone (IM72D128V01). need to configure PCM sampling rate as 2KHz. 
 . min_pdm_clk_freq = 120000, 
 . max_pdm_clk_freq = 160000 , 
 
 
 
 this is the configuration that I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 Oct 2023 09:15:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105124/digital-mems-microphone-im72d128v01-interface-with-nrf5430-via-pdm" /><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/453197?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2023 09:15:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79d9b4cd-1d32-4ace-a815-c26c5c481665</guid><dc:creator>sensorbee-dev</dc:creator><description>&lt;p&gt;Unfortunately I cannot help you with the down scaling of the signal.&lt;/p&gt;
&lt;p&gt;Regarding &amp;quot;recording&amp;quot; the data into a .wav file. It does not really matter what format you send the data in, as long as you process it correctly on the receiving end. But outputting it as binary will make the parsing of the data on the receiving end easier. In the sample, you can see that you can configure it to output the data in either ASCII or binary format.&lt;/p&gt;
&lt;p&gt;This part of the code outputs the data in binary format:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	unsigned char pcm_l, pcm_h;
	int j;

	for (i = 0; i &amp;lt; NUM_MS; i++) {
		uint16_t *pcm_out = rx_block[i];

		for (j = 0; j &amp;lt; rx_size/2; j++) {
			pcm_l = (char)(pcm_out[j] &amp;amp; 0xFF);
			pcm_h = (char)((pcm_out[j] &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);

			z_impl_k_str_out(&amp;amp;pcm_l, 1);
			z_impl_k_str_out(&amp;amp;pcm_h, 1);
		}
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;They seem to be using &lt;span style="font-family:courier new, courier;"&gt;z_impl_k_str_out&lt;/span&gt;, not sure if this will work I haven&amp;#39;t used it myself. Otherwise I think you will have to use the uart API directly. You should be able to get a device pointer to the console (uart0 if using the default board) and use &lt;span style="font-family:courier new, courier;"&gt;uart_poll_out&lt;/span&gt; instead of &lt;span style="font-family:courier new, courier;"&gt;z_impl_k_str_out&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	const struct device *uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
	if (!device_is_ready(uart)) {
	    printk(&amp;quot;failed to retrieve uart device&amp;quot;);
	    return -1;
	}
	// ... 
	
	unsigned char pcm_l, pcm_h;
	int j;

	for (i = 0; i &amp;lt; NUM_MS; i++) {
		uint16_t *pcm_out = rx_block[i];

		for (j = 0; j &amp;lt; rx_size/2; j++) {
			pcm_l = (char)(pcm_out[j] &amp;amp; 0xFF);
			pcm_h = (char)((pcm_out[j] &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);

            uart_poll_out(uart, pcm_l);
            uart_poll_out(uart, pcm_h)
		}
	}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/453175?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2023 06:07:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eaeb3f98-3959-40e0-b5fe-22e818dc2f6a</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;1) currently iam using the pcm sampling rate as 8khz (because 2khz is not supported by the mems microphone).&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.1) aim:&amp;nbsp; Any way to manually down&amp;nbsp;sample to 2khz after reading 8khz. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;we may need to implement&amp;nbsp;&lt;/span&gt;&lt;span&gt;down conversion&amp;nbsp;in our code. is it possible? &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;can you guide me on it, any&amp;nbsp;sample code&amp;nbsp;&lt;/span&gt;&lt;span&gt;available?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;2) have referred the link&amp;nbsp;that&amp;nbsp;you have provided&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;If you want an example of how to get the audio data to your PC, refer to this example:&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/latest/samples/shields/x_nucleo_iks02a1/microphone/README.html#x-nucleo-iks02a1-mic"&gt;https://docs.zephyrproject.org/latest/samples/shields/x_nucleo_iks02a1/microphone/README.html#x-nucleo-iks02a1-mic&amp;nbsp;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;it does not explain how to convert ASCII PCM data to binary. can u guide me on it step by step.&lt;/p&gt;
&lt;p&gt;feel free to refer the attached code, suggest corrections if any.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/audio/dmic.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;

LOG_MODULE_REGISTER(dmic_sample);

#define MAX_SAMPLE_RATE	 8000
#define SAMPLE_BIT_WIDTH 16
#define BYTES_PER_SAMPLE sizeof(int16_t)
/* Milliseconds to wait for a block to be read. */
#define READ_TIMEOUT	 3000 // 1000

/* Size of a block for 100 ms of audio data. */
#define BLOCK_SIZE(_sample_rate, _number_of_channels)                                              \
	(BYTES_PER_SAMPLE * (_sample_rate / 10) * _number_of_channels)

/* Driver will allocate blocks from this slab to receive audio data into them.
 * Application, after getting a given block from the driver and processing its
 * data, needs to free that block.
 */
#define MAX_BLOCK_SIZE BLOCK_SIZE(MAX_SAMPLE_RATE, 2)
#define BLOCK_COUNT    30 // 50 //4
K_MEM_SLAB_DEFINE_STATIC(mem_slab, MAX_BLOCK_SIZE, BLOCK_COUNT, 4);

void *buffer[BLOCK_COUNT];
uint32_t size = MAX_BLOCK_SIZE;


static int do_pdm_transfer(const struct device *dmic_dev, struct dmic_cfg *cfg, size_t block_count)
{
	int ret;

	// LOG_INF(&amp;quot;PCM output rate: %u, channels: %u&amp;quot;, cfg-&amp;gt;streams[0].pcm_rate,cfg-&amp;gt;channel.req_num_chan);

	ret = dmic_configure(dmic_dev, cfg);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to configure the driver: %d&amp;quot;, ret);
		return ret;
	}

	ret = dmic_trigger(dmic_dev, DMIC_TRIGGER_START);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;START trigger failed: %d&amp;quot;, ret);
		return ret;
	}

	for (int i = 0; i &amp;lt; block_count; ++i) {

		int ret;

		ret = dmic_read(dmic_dev, 0, &amp;amp;buffer, &amp;amp;size, READ_TIMEOUT);
		if (ret &amp;lt; 0) {
			LOG_ERR(&amp;quot;%d - read failed: %d&amp;quot;, i, ret);
			return ret;
		}

		// LOG_INF(&amp;quot;%d - got buffer %p of %u bytes&amp;quot;, i, buffer, size);

		// Print buffer in hexadecimal using LOG_HEXDUMP_INF()
		// LOG_HEXDUMP_INF(buffer, size, &amp;quot;Buffer contents:&amp;quot;);

		// uint16_t *audio_data = (uint16_t *)buffer;
		// uint32_t num_samples = size / sizeof(uint16_t);
       
		// for (int j = 0; j &amp;lt; num_samples; ++j) {
		// printk(&amp;quot;0x%04x &amp;quot;, audio_data[j]);
		// k_sleep(K_MSEC(1));
        // }

		k_mem_slab_free(&amp;amp;mem_slab, &amp;amp;buffer);
	}

	// 	for (uint32_t ms = 0; ms &amp;lt; block_count; ms++) {
	// 	ret = dmic_read(dmic_dev, 0, &amp;amp;buffer[ms], &amp;amp;size, READ_TIMEOUT);
	// 	if (ret &amp;lt; 0) {
	// 		printk(&amp;quot;microphone audio read error\n&amp;quot;);
	// 		return 0;
	// 	}
	// }

	ret = dmic_trigger(dmic_dev, DMIC_TRIGGER_STOP);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;STOP trigger failed: %d&amp;quot;, ret);
		return ret;
	}

	printk(&amp;quot;-- start\n&amp;quot;);
	int j;

	for (int i = 0; i &amp;lt; BLOCK_COUNT; i++) {
		uint16_t *pcm_out = buffer[i];

		for (j = 0; j &amp;lt; size/2; j++) {
			// printk(&amp;quot;0x%04x,\n&amp;quot;, pcm_out[j]);
			printk(&amp;quot;0x%04x&amp;quot;, pcm_out[j]);
			k_sleep(K_MSEC(1));
		}
	}
	printk(&amp;quot;-- end\n&amp;quot;);
	
	return ret;
}

int main(void)
{
	const struct device *const dmic_dev = DEVICE_DT_GET(DT_NODELABEL(dmic_dev));
	int ret;

	// LOG_INF(&amp;quot;DMIC sample&amp;quot;);
	
	if (!device_is_ready(dmic_dev)) {
		LOG_ERR(&amp;quot;%s is not ready&amp;quot;, dmic_dev-&amp;gt;name);
		return 0;
	}

	struct pcm_stream_cfg stream = {
		.pcm_width = SAMPLE_BIT_WIDTH,
		.mem_slab = &amp;amp;mem_slab,
	};
	struct dmic_cfg cfg = {
		.io =
			{
				/* These fields can be used to limit the PDM clock
				 * configurations that the driver is allowed to use
				 * to those supported by the microphone.
				 */
				.min_pdm_clk_freq = 512000,
				.max_pdm_clk_freq = 640000,
				.min_pdm_clk_dc = 40,
				.max_pdm_clk_dc = 60,
			},
		.streams = &amp;amp;stream,
		.channel =
			{
				.req_num_streams = 1,
			},
	};

	// cfg.channel.req_num_chan = 1;
	// cfg.channel.req_chan_map_lo = dmic_build_channel_map(0, 0, PDM_CHAN_LEFT);
	// cfg.streams[0].pcm_rate = MAX_SAMPLE_RATE;
	// cfg.streams[0].block_size = BLOCK_SIZE(cfg.streams[0].pcm_rate,
	// cfg.channel.req_num_chan);

	// ret = do_pdm_transfer(dmic_dev, &amp;amp;cfg, 2 * BLOCK_COUNT);
	// if (ret &amp;lt; 0) {
	// 	return 0;
	// }

	cfg.channel.req_num_chan = 2;
	cfg.channel.req_chan_map_lo = dmic_build_channel_map(0, 0, PDM_CHAN_LEFT) |dmic_build_channel_map(1, 0, PDM_CHAN_RIGHT);
	cfg.streams[0].pcm_rate = MAX_SAMPLE_RATE;
	cfg.streams[0].block_size = BLOCK_SIZE(cfg.streams[0].pcm_rate, cfg.channel.req_num_chan);

	ret = do_pdm_transfer(dmic_dev, &amp;amp;cfg, 2 * BLOCK_COUNT);
	if (ret &amp;lt; 0) {
		return 0;
	}

	// LOG_INF(&amp;quot;Exiting&amp;quot;);
	return 0;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/453075?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 14:23:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28519f57-5669-4ef1-8740-53117d2f5f4a</guid><dc:creator>sensorbee-dev</dc:creator><description>&lt;p&gt;I&amp;#39;m not entirely certain about your intentions. Are you looking to utilize a sampling rate of 2 KHz or 8 KHz?&lt;/p&gt;
&lt;p&gt;Upon reviewing your code, I noticed you adjust the minimum and maximum clock frequency based on the sampling rate. However, this isn&amp;#39;t necessary. The min and max sampling rates are determined by the microphone&amp;#39;s specifications, so they remain constant regardless of your chosen sampling rate.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re aiming to minimize memory usage without altering the sampling rate, consider adjusting the size of each sample block. Currently, with a block width of 100 ms, it seems you&amp;#39;re consuming 6400 bytes of data. By reducing the block width to 50 ms, you can bring this down to 3200 bytes. Do note, however, that reducing the block width will lead to more frequent thread switches, potentially increasing the relative overhead and leaving less time for data processing in each cycle.&lt;/p&gt;
&lt;p&gt;Regarding the down sampling, are you unable to set the PCM rate to 2 KHz and this is why you want to down sample the data? In that case I cannot help you as I do not know how to do this or if there is an API for it, but surely there must be some code available online that can do this for you.&lt;/p&gt;
&lt;p&gt;If you want an example of how to get the audio data to your PC, refer to this example:&lt;br /&gt;&lt;a href="https://docs.zephyrproject.org/latest/samples/shields/x_nucleo_iks02a1/microphone/README.html#x-nucleo-iks02a1-mic"&gt;https://docs.zephyrproject.org/latest/samples/shields/x_nucleo_iks02a1/microphone/README.html#x-nucleo-iks02a1-mic&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;EDIT: Regarding this statement: &amp;quot;how to build the binary file using the attached code&amp;quot;, are you referring to the python code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/453060?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 13:43:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a773794-95a7-4a41-a4fd-315238b01024</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;iam using the sample code of Dmic in nrf5340 .&lt;br /&gt;attaching the code below.(currently&amp;nbsp;trying to work on PCM sampling rate as 8khz ).&lt;br /&gt;&lt;br /&gt;1) is there any down sampling method / api . so that i can use&amp;nbsp;PCM sampling as 2Khz. because if i increase the pcm sampling rate memory is a big constrain.&lt;br /&gt;&lt;br /&gt;2) how to build the binary file using the attached code and use the above python code generate the audio file . please refer the attached code and feel free to guide me in detail.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;note: using windows machine.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/audio/dmic.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;

LOG_MODULE_REGISTER(dmic_sample);

// #define MAX_SAMPLE_RATE  16000
#define MAX_SAMPLE_RATE	 8000
#define SAMPLE_BIT_WIDTH 16
#define BYTES_PER_SAMPLE sizeof(int16_t)
/* Milliseconds to wait for a block to be read. */
#define READ_TIMEOUT	 3000 // 1000

/* Size of a block for 100 ms of audio data. */
#define BLOCK_SIZE(_sample_rate, _number_of_channels)                                              \
	(BYTES_PER_SAMPLE * (_sample_rate / 10) * _number_of_channels)

/* Driver will allocate blocks from this slab to receive audio data into them.
 * Application, after getting a given block from the driver and processing its
 * data, needs to free that block.
 */
#define MAX_BLOCK_SIZE BLOCK_SIZE(MAX_SAMPLE_RATE, 2)
#define BLOCK_COUNT    30 // 50 //4
K_MEM_SLAB_DEFINE_STATIC(mem_slab, MAX_BLOCK_SIZE, BLOCK_COUNT, 4);

static int do_pdm_transfer(const struct device *dmic_dev, struct dmic_cfg *cfg, size_t block_count)
{
	int ret;

	LOG_INF(&amp;quot;PCM output rate: %u, channels: %u&amp;quot;, cfg-&amp;gt;streams[0].pcm_rate,
		cfg-&amp;gt;channel.req_num_chan);

	ret = dmic_configure(dmic_dev, cfg);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to configure the driver: %d&amp;quot;, ret);
		return ret;
	}

	ret = dmic_trigger(dmic_dev, DMIC_TRIGGER_START);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;START trigger failed: %d&amp;quot;, ret);
		return ret;
	}

	for (int i = 0; i &amp;lt; block_count; ++i) {
		void *buffer;
		uint32_t size;
		int ret;

		ret = dmic_read(dmic_dev, 0, &amp;amp;buffer, &amp;amp;size, READ_TIMEOUT);
		if (ret &amp;lt; 0) {
			LOG_ERR(&amp;quot;%d - read failed: %d&amp;quot;, i, ret);
			return ret;
		}

		// LOG_INF(&amp;quot;%d - got buffer %p of %u bytes&amp;quot;, i, buffer, size);

		uint16_t *audio_data = (uint16_t *)buffer;
		uint32_t num_samples = size / sizeof(uint16_t);



		for (uint32_t j = 0; j &amp;lt; num_samples ; ++j)
		{
		 	uint32_t sample = audio_data[j];

		 	printk(&amp;quot;%04x &amp;quot;, audio_data[j]);

		 }


		k_mem_slab_free(&amp;amp;mem_slab, &amp;amp;buffer);
	}

	ret = dmic_trigger(dmic_dev, DMIC_TRIGGER_STOP);
	if (ret &amp;lt; 0) {
		LOG_ERR(&amp;quot;STOP trigger failed: %d&amp;quot;, ret);
		return ret;
	}

	return ret;
}

int main(void)
{
	const struct device *const dmic_dev = DEVICE_DT_GET(DT_NODELABEL(dmic_dev));
	int ret;

	LOG_INF(&amp;quot;DMIC sample&amp;quot;);
	
	if (!device_is_ready(dmic_dev)) {
		LOG_ERR(&amp;quot;%s is not ready&amp;quot;, dmic_dev-&amp;gt;name);
		return 0;
	}

	struct pcm_stream_cfg stream = {
		.pcm_width = SAMPLE_BIT_WIDTH,
		.mem_slab = &amp;amp;mem_slab,
	};
	struct dmic_cfg cfg = {
		.io =
			{
				/* These fields can be used to limit the PDM clock
				 * configurations that the driver is allowed to use
				 * to those supported by the microphone.
				 */
				// .min_pdm_clk_freq = 120000,   //for 2khz
				// .max_pdm_clk_freq = 160000,   // for 2khz
				.min_pdm_clk_freq = 512000,      // for 8khz
				.max_pdm_clk_freq = 640000,      // for 8khz
				.min_pdm_clk_dc = 40,
				.max_pdm_clk_dc = 60,
			},
		.streams = &amp;amp;stream,
		.channel =
			{
				.req_num_streams = 1,
			},
	};

	// cfg.channel.req_num_chan = 1;
	// cfg.channel.req_chan_map_lo = dmic_build_channel_map(0, 0, PDM_CHAN_LEFT);
	// cfg.streams[0].pcm_rate = MAX_SAMPLE_RATE;
	// cfg.streams[0].block_size = BLOCK_SIZE(cfg.streams[0].pcm_rate,
	// cfg.channel.req_num_chan);

	// ret = do_pdm_transfer(dmic_dev, &amp;amp;cfg, 2 * BLOCK_COUNT);
	// if (ret &amp;lt; 0) {
	// 	return 0;
	// }

	cfg.channel.req_num_chan = 2;
	cfg.channel.req_chan_map_lo = dmic_build_channel_map(0, 0, PDM_CHAN_LEFT) |
				      dmic_build_channel_map(1, 0, PDM_CHAN_RIGHT);
	cfg.streams[0].pcm_rate = MAX_SAMPLE_RATE;
	cfg.streams[0].block_size = BLOCK_SIZE(cfg.streams[0].pcm_rate, cfg.channel.req_num_chan);

	ret = do_pdm_transfer(dmic_dev, &amp;amp;cfg, 2 * BLOCK_COUNT);
	if (ret &amp;lt; 0) {
		return 0;
	}

	LOG_INF(&amp;quot;Exiting&amp;quot;);
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/453011?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 11:52:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:940820b9-b57d-4cde-8ffc-9ee837348221</guid><dc:creator>sensorbee-dev</dc:creator><description>&lt;p&gt;This code should work, it has been a while since I used it. I think it expects binary data (not hex string). I hope this helps.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="python"&gt;import serial
import numpy as np
from scipy.io import wavfile

# Configuration: duration in seconds and sampling rate in Hz
duration = 5  # Record for 5 seconds
Fs = 2000    # Sampling rate of 2000 Hz

# Open the serial port
ser = serial.Serial(&amp;#39;/dev/ttyACM0&amp;#39;, baudrate=115200, timeout=1)

# Number of samples to read (calculated from duration and sampling rate)
num_samples = int(duration * Fs)

# Buffer to store audio data
audio_data = np.zeros(num_samples, dtype=np.int16)

bytes_per_sample = 2
samples_read = 0
i = 0

# Read audio data from the serial port
while i &amp;lt; num_samples:
    # Read two bytes (16-bit integer)
    data_bytes = ser.read_all()
    
    # Ensure there are exactly 2 bytes to read
    if len(data_bytes) % 2 != 0:
        print(f&amp;quot;Error: {len(data_bytes)} bytes read&amp;quot;)
        continue

    # Convert bytes to integer (little-endian)
    for j in range(0, len(data_bytes), bytes_per_sample):
        sample = int.from_bytes(data_bytes[j:j+bytes_per_sample], byteorder=&amp;#39;little&amp;#39;, signed=True)
        audio_data[i] = sample
        i += 1
    
    # Increment the number of samples read
    samples_read += len(data_bytes) / bytes_per_sample

# Close the serial port
ser.close()

# Path to the output file
output_file = &amp;#39;output.wav&amp;#39;

# Write to .wav file
wavfile.write(output_file, Fs, audio_data)

print(f&amp;quot;Audio data saved to {output_file}&amp;quot;)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/453004?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 11:34:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c5a511b-cb3d-4ddb-995d-6899d65419d3</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;how&amp;nbsp;we create the .wave file .. can u explain&amp;nbsp;in detail.&amp;nbsp;&lt;br /&gt;share example if any.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/452930?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 07:55:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c6524c8-082e-48b6-a41f-81d3ab2edbe3</guid><dc:creator>sensorbee-dev</dc:creator><description>&lt;p&gt;Are you referring to the conversion between PDM to PCM? Because the DMIC api will do this for you. &lt;span style="font-family:courier new, courier;"&gt;dmic_read&lt;/span&gt; will give you a &amp;quot;usable&amp;quot; format (PCM) that can be directly used to create a .wav file.&lt;/p&gt;
&lt;p&gt;Does this answer your question or did I misinterpet it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/452918?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 06:04:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f883881-4771-455b-829c-c370923e1021</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;thanks for the reply.&lt;br /&gt;&lt;br /&gt;1) is there any way to down sample (pcm) using any api?&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Digital MEMS microphone (IM72D128V01) interface with nrf5430 via PDM</title><link>https://devzone.nordicsemi.com/thread/452805?ContentTypeID=1</link><pubDate>Fri, 27 Oct 2023 13:45:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:200138c2-79b3-45d1-81cc-f5f351360615</guid><dc:creator>sensorbee-dev</dc:creator><description>&lt;p&gt;I have been able to use a similar MEMS microphone from Infineon with the 5340. If you want to configure the sampling rate to 2 KHz you should set the &lt;span style="font-family:courier new, courier;"&gt;pcm_rate&lt;/span&gt; field in the &lt;span style="font-family:courier new, courier;"&gt;dmic_cfg&lt;/span&gt; structure:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;cfg.streams[0].pcm_rate = &amp;lt;SAMPLE_RATE&amp;gt;;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regarding point number 2, you could stream the 16-bit data over the serial port and have a python script convert it into a .wav file. You should then be able to listen to the recorded data or analyze it using some kind of software.&lt;/p&gt;
&lt;p&gt;Also I think the maxmium and minimum clk frequencies you have specified are incorrect. They should reflect the microphone&amp;#39;s specification, which I think, if reading the datasheet correctly is 440 KHz to 5.04 Mhz.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>