cancel
Showing results for 
Search instead for 
Did you mean: 

Reading PDM data from MP34DT05-A with STM32F407 I2S

ArturasV
Senior

Hello, it is the first time when i have to deal with microphones and PDM interface. I just can't get correct data from the microphone, or the data is correct but i am doing something terribly wrong. I configure I2S to sample microphone with DMA. When DMA Rx callback is received, i do the processing of PDM data and send it to PC via USB VCP interface. Problem is that when i get the data in PC, there are some high frequency harmonics which are giving very anoying "beep" sound, even though in the background i can hear the "clap sound" that i am making with my hands. Could someone look at my code and tell me what am i doing wrong?

I attache the main file of my program, also the file where DMA controller of I2S is configured. I also attach pictures of how my signals look in frequency and time domains. Appreciate for the help if anyone could tell my what i am doing wrong.

By the way, i have read ST documents UM2372, AN5027. I do not see from them that i am doing something wrong.

I also add the recorded wav file. Listen it carefully and at low sound because the "beep" is really annoying. You can hear in the background that i am clap two times slowly, then one time i do a double clap quickly.

Will wait for the responses, cheers.

17 REPLIES 17
J Lee
Associate III

Hi, now it seems I can successfully sample audio data, below is the spectrum of 10KHz tone signal.

However, in an acoustically quiet room, the mic can still sample high freq noise, which confused me.

Now there are 2 things also confuse me:

  1. It seems the PDM sampling rate changes according to I2S audio freq(audio sampling rate), and PDM sampling rate/PCM sampling rate ratio seems to be a constant value, which is 32. i.e. user can not independently change PDM sampling rate and the decimation factor is fixed which is 32? So the decimation factor 64 in the sample project I don't know...
  2. In the example the output data format is uint16, however it seems int16 data type is more suitable?

I found that decimation factor should equals to # of PDM bits/# of PCM samples

ArturasV
Senior

J Lee, i still cant figure this one out. This just seems that it is not working the way it should work.

ArturasV
Senior

The best i can get is the photo attached. But still there is such a big noise in the signal, that when i listen it, i can barely hear the sound that i am doing by snapping my fingers near the microphone, even though i can see it in the time domain, but that is the best i can get, which still feels terrible...

ArturasV
Senior

I have noticed an interested thing. The I2S clock output frequency to the microphone is 1.024 MHz. My buffer to which i am getting data via DMA is declared as: uint16_t pdm_buff[32]. So my PDM buffer can accept 32*16 = 512 bits. Question: why do i keep getting I2S transfer complete interrupt every 1ms? It does not make sense to me. I attach my DMA configuration

    hdma_spi2_rx.Instance = DMA1_Stream3;
    hdma_spi2_rx.Init.Channel = DMA_CHANNEL_0;
    hdma_spi2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_spi2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_spi2_rx.Init.MemInc = DMA_MINC_ENABLE;
    hdma_spi2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
    hdma_spi2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
    hdma_spi2_rx.Init.Mode = DMA_CIRCULAR;
    hdma_spi2_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
    hdma_spi2_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

Hi ArturasV!

Did you ever manage to get this to work correctly?

I've also been struggling with capturing 1 microphone at an i2s clock frequency of 1024 MHz. I get an audio signal but it's very noisy, particularly in the higher frequency range. I'm not sure if the problem lies with the sampling, or the PDM Filter. I don't really have the right tools for easily debugging this at hand. Any hints would be appreciated.

Thank you, Eos

EPelz
Associate II

Hi ArturasV!

Did you ever manage to get this to work correctly?

I've also been struggling with capturing 1 microphone at an i2s clock frequency of 1024 MHz. I get an audio signal but it's very noisy, particularly in the higher frequency range. I'm not sure if the problem lies with the sampling, or the PDM Filter. I don't really have the right tools for easily debugging this at hand. Any hints would be appreciated.

Thank you, Eos

J Lee
Associate III
You can try Matlab to analyze the spectrum of a single tone
Regards,
Shuo

Hi Eos. Pelzer, no - i gave up on this, we switched to another microphone. Did not manage to get this one working properly.