cancel
Showing results for 
Search instead for 
Did you mean: 

PCM sound to PC -> Stm32f4 microphone

Klemen Bati?
Associate
Posted on April 11, 2017 at 10:55

Hello!

I am using 'STM32Cube_FW_F4_V1.14.0\Projects\STM32F4-Discovery\Examples\BSP' modified example for recording audio. 

As far as I understand the audio is recorded, converted from PDM to PCM and saved into WrBuffer. Data is uint16_t. I am sending it with function HAL_UART_Transmit, which sends 8 bit data.

'HAL_UART_Transmit(&huart6, (uint8_t *)  WrBuffer, WR_BUFFER_SIZE*2, 5000);'

I send it after the function  AudioRecord_Test(); function call.

On my PC I use matlab to receive data and to cast it to 16 bit. Code for casting:

a =uint8(fread(s)); %reads the data from the serial port and stores it to the matrix a

res = (typecast(uint8(a), 'uint16'));

When recording sound: sine vawe , snap of fingers, etc... The plotted data does not have a recognisable pattern, it looks like noise, althoug I can hear the sound clearly on playback via STM board.

I am quite sure the conversion in Matlab works, because I tryed sending uint16_t sine vawe (lookup table) via uart and the matlab reconstructed it perfectly

So what am I doing wrong? I added some photos of MIC sound. I hope I provided enough info, if not I´ll be glad to.

Thanks for help!

1 ACCEPTED SOLUTION

Accepted Solutions
Nesrine M_O
Lead II
Posted on April 11, 2017 at 11:05

Hi

batic.klemen@gmail.com

,

-Nesrine-

View solution in original post

2 REPLIES 2
Nesrine M_O
Lead II
Posted on April 11, 2017 at 11:05

Hi

batic.klemen@gmail.com

,

-Nesrine-

Posted on April 11, 2017 at 20:40

Thank you for your fast resposne!

I actually was using example to help find information, but the second look at application note caught my eye that the PCM signal is in signed 16 bit integer. So it was a problem with casting in matlab

res = (typecast(uint8(a), 'int16'));. One letter removed and everything works. I was so sure that this is not a problem that I just overlooked it

🙂