cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect audio acquisition with PDM microphone

RPuch.2
Associate III

Hi, I have a problem with audio acquisition using PDM microphones. After using PDM_Filter, single peaks of high amplitude appear in the data in addition to the correct readings.

I am using 4 microphones MP34DT01-M, STM32H743 and SAI interface.

I take 4096 samples from each microphone, convert PDM to PCM and save to SD card using FATFS.

My code (excerpt) is very simple:

void HAL_SAI_RxCpltCallback (SAI_HandleTypeDef *hsai) //PDM buffer full
{
	rxstate = 2; 	//buffer full flag
	real_round++;	//next real round of acquisition
}
 
int main(void)
{
HAL_SAI_Receive_DMA(&hsai_BlockA1, (uint8_t*)PDM_buffer, PDM_buffer_size); //start acquisition
 
while (1)
{
  	if (rxstate == 2)//if PDM buffer is full
  	{
  		rxstate = 0; //clear the flag
  		current_round++; //next processed round of acquisition
 
  		if (current_round <= last_round) //processes and saves a predetermined number of cycles (rounds)
  		{
  			PDM_Filter(&(((uint8_t*)PDM_buffer)[0]), &(((uint16_t*)PCM_buffer)[0]), &PDM1_filter_handler); //MIC_A
  			PDM_Filter(&(((uint8_t*)PDM_buffer)[1]), &(((uint16_t*)PCM_buffer)[1]), &PDM2_filter_handler); //MIC_B
  			PDM_Filter(&(((uint8_t*)PDM_buffer)[2]), &(((uint16_t*)PCM_buffer)[2]), &PDM3_filter_handler); //MIC_C
  			PDM_Filter(&(((uint8_t*)PDM_buffer)[3]), &(((uint16_t*)PCM_buffer)[3]), &PDM4_filter_handler); //MIC_D
 
  			if (current_round >= first_round) 
  			{
  				if(f_write(&fil, PCM_buffer, sizeof(PCM_buffer), &numread) != HAL_OK) //write data to SD card
  				{
  					printf("f_write ERROR\n");
  				}
  			}
 
  		}else //if (current_round > last_round)
  		{
  			HAL_SAI_DMAStop(&hsai_BlockA1); //stop acquisition
  			close_file();
  			unmount_sd();
  			break; //exit while loop, end of program
  		}
  	}
}
}

In each round (cycle) of 4096 measurements, there are single abnormal values with an amplitude larger than the rest of the signal. In addition, the first cycle has invalid values, but this is OK for me. In contrast, the rest of the data should be correct.

I know that the first 2 TDMA frames are invalid, but there are more such invalid values. Do you have any idea where they can come from?

I attach 2 files with fragments of graphs. On the first one, I consider the values with indexes 4097-4103 (according to RM0433) as normal, but I have no idea where the values with indexes 4567-4576 come from. The situation repeats in every cycle. As an example, I attach the appearance of the beginning of the third cycle.

Maybe this is an important piece of information - it takes longer to write to the SD card than it takes to fill the PDM buffer, so there is no continuity of the written signal, but this is OK for me.

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
2 REPLIES 2
RPuch.2
Associate III

Interestingly, the A microphone has values in line with those expected. In each cycle, exactly the first 2 int16 values are incorrect, the rest are fine. But in microphones B, C and D, a sort of phase shift arises. I attach a graph of the entire PCM buffer, in which the next 4 values correspond to A, B, C, D respectively (A1,B1,C1,D1,A2,B2,C2,D2,A3,B3,C3,D3...). The same sound was fed to all 4 microphones, so a single (bold) sine wave should result. Unfortunately, there are offsets at the beginning of each cycle. Every cycle has 16384 values (4*4096).


_legacyfs_online_stmicro_images_0693W00000bkt69QAA.png

RPuch.2
Associate III

It seems to me that the problem is the size of the PDM buffer. If the PCM buffer is 4*4096, what should be the PDM buffer size?

I am using DEC_FACTOR_64, Fs=48kHz.