cancel
Showing results for 
Search instead for 
Did you mean: 

Monitoring the raw data from MP45DT02

f23
Associate II
Posted on June 09, 2015 at 18:22

Hallo,

I am working on extracting the data from the

MP45DT I used PDM filter function. I gave a beep sound to the microphone in the certain frequency, but I noticed that the captured raw data is not given as a sine wave.0690X00000603KDQAY.jpg

Is this kind of data is correct ? because I am expecting some sine wave.The sound frequency that is transmitted to the MIC is 1000Hz. This is my setting for the MP45DT

#define SPI_Nr SPI2
#define DMA_SPI DMA1_Stream3
#define PDM_LENGTH 320
#define PCM_LENGTH 32
/*Private function--------------------------------------------------------------------*/
/* Temporary data sample in the DMA memory */
uint16_t AUDIO_SAMPLE_RX_MEM1 [PDM_LENGTH ]; //< 
Array
of DMA MEM0 for double buffer
uint16_t AUDIO_SAMPLE_RX_MEM0 [PDM_LENGTH] ; //< Array of DMA MEM1 for double buffer
static uint32_t 
AudioRecInited
= 
0
; //Current state of the audio recorder interface initialization
PDMFilter_InitStruct Filter;
/* Main buffer pointer for the recorded data storing */
uint16_t* pAudioRecBuf; //< Pointer for Audio record for PDM data collect
uint16_t OutputBuffer0[PCM_LENGTH]; //< Output Buffer 0 after PDM
uint16_t OutputBuffer1[PCM_LENGTH]; //< Output Buffer 1 after PDM
void SignalReceive_Init(void)
{
/* Configure the SPI with 32KHz Audio frequency */
WaveRecord_SPI_Init();
/* Configure the DMA (double buffer) and interrupts */
WaveRecord_DMA_Init();
/* Filter LP & HP Init */
Filter.LP_HZ
= 
32000
;
Filter.HP_HZ
= 
10
;
Filter.Fs
= 
32000
;
Filter.Out_MicChannels
= 
1
;
Filter.In_MicChannels
= 
1
;
PDM_Filter_Init((PDMFilter_InitStruct *)&Filter);
/* Set state of the audio recorder to initialized */
AudioRecInited
= 
1
;
}// End of SignalReceive_Init()
void WaveRecord_SPI_Init(void)
{
/**************I2S2 Initialization ***************************/
I2S_InitTypeDef I2S_InitStructure;
SPI_I2S_DeInit(SPI_Nr);
I2S_InitStructure.I2S_AudioFreq
=
64000
;//I2S_AudioFreq_48k ; //< Audio is recorded from two channels, so this value must be twice the value in the PDM filter
I2S_InitStructure.I2S_Standard
= 
I2S_Standard_LSB
;
I2S_InitStructure.I2S_DataFormat
= 
I2S_DataFormat_16b
;
I2S_InitStructure.I2S_CPOL
= 
I2S_CPOL_High
;
I2S_InitStructure.I2S_Mode
= 
I2S_Mode_MasterRx
;
I2S_InitStructure.I2S_MCLKOutput
= 
I2S_MCLKOutput_Disable
;
/* Initialize the I2S peripheral with the structure above */
I2S_Init(SPI_Nr, &I2S_InitStructure);
}// End of WaveRecord_SPI_Init()
void WaveRecord_DMA_Init(void)
{
//***** The DMA Configuration ****************//
DMA_InitTypeDef DMA_InitStructure;
//********* DMA init (DMA1, Channel0, Stream3)*********//
DMA_Cmd(DMA_SPI, DISABLE);
DMA_DeInit(DMA_SPI);
DMA_InitStructure.DMA_Channel
= 
DMA_Channel_0
;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(SPI_Nr->DR);
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)AUDIO_SAMPLE_RX_MEM0;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ;
DMA_InitStructure.DMA_BufferSize =PDM_LENGTH;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium ;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA_SPI, &DMA_InitStructure);
//*******Setup the Dual Buffer mode for the Rx DMA1 Stream 3 **********//
DMA_DoubleBufferModeConfig (DMA_SPI, (uint32_t)AUDIO_SAMPLE_RX_MEM1,DMA_Memory_1);
DMA_DoubleBufferModeCmd(DMA_SPI, ENABLE);
DMA_Init(DMA_SPI, &DMA_InitStructure);
//*********** Transfer complete interrupt enabling *************//
DMA_ITConfig(DMA_SPI, DMA_IT_TC, ENABLE);
//************** DMA enable***********************************//
DMA_Cmd(DMA_SPI, ENABLE);
}// End of WaveRecord_DMA_Init()
uint8_t SignalReceive_start(void)
{
/* Check if the interface has already been initialized */
/*Enable the I2S DMA */
SPI_I2S_DMACmd( SPI_Nr, SPI_I2S_DMAReq_Rx, ENABLE);
/* Enable the SPI peripheral */
I2S_Cmd(SPI_Nr, ENABLE);
/* Return 0 if all operations are OK */
return 0;
I2S_ISR_Indication=0;
}
void DMA1_Stream3_IRQHandler(void)
{
uint16_t volume;
volume = 64;
//**********Check the transfer complete event *********//
if (DMA_GetITStatus(DMA_SPI, DMA_IT_TCIF3)== SET)
{
DMA_ClearFlag(DMA_SPI, DMA_FLAG_TCIF3);
//GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
if(DMA_GetCurrentMemoryTarget(DMA_SPI)==1) //
{
pAudioRecBuf=OutputBuffer0;
PDM_Filter_64_LSB((uint8_t *)AUDIO_SAMPLE_RX_MEM0,(uint16_t *)pAudioRecBuf, volume , (PDMFilter_InitStruct *)&Filter);
}
else
{ 
pAudioRecBuf=OutputBuffer1;
PDM_Filter_64_LSB((uint8_t *)AUDIO_SAMPLE_RX_MEM1,(uint16_t *)pAudioRecBuf, volume , (PDMFilter_InitStruct *)&Filter);
}
}
DMA_ClearITPendingBit(DMA_SPI, DMA_IT_HTIF3); ///< clear pending interrupt
} //< End of DMA1_Stream3_IRQHandler

Hope someone can help me. Thanks
4 REPLIES 4
Posted on June 09, 2015 at 19:24

Is the data really UNSIGNED 16-bit? If not think about how two-complement data might plot on a 0-70000 scale...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
f23
Associate II
Posted on June 09, 2015 at 20:49

Thanks for the reply clive1,

Yes the output data after go through the filter is Unsigned 16. I collected each 32 samples after interrupt of the DMA double buffer and put it in one array and plotted it.

 But as you see from the graph, the wave form is quite weird. I dont know if my settings  are wrong or not . Supposedly we should expect some kind of sine wave right, if we emit sound in certain frequency to the microphone?

Posted on June 09, 2015 at 21:22

But as you see from the graph, the wave form is quite weird.

Yes, and to which I suggested that you consider if this is actually UNSIGNED data. I doubt that it is, plot it as SIGNED data in the +32767 to -32768 range.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
f23
Associate II
Posted on June 10, 2015 at 02:06

Thanks Clive1

I do the casting for converting the unsigned 16-Bit to signed 16-Bit. Is it correct?

void DMA1_Stream3_IRQHandler(void)
{
uint16_t volume;
int16_t PCM_out[PCM_LENGTH];
volume = 50;
//**********Check the transfer complete event *********//
if (DMA_GetITStatus(DMA_SPI, DMA_IT_TCIF3)== SET)
{
DMA_ClearFlag(DMA_SPI, DMA_FLAG_TCIF3);
//GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
if(DMA_GetCurrentMemoryTarget(DMA_SPI)==1) //
{
pAudioRecBuf=OutputBuffer0;
PDM_Filter_64_LSB((uint8_t *)AUDIO_SAMPLE_RX_MEM0,(uint16_t *)pAudioRecBuf, volume , (PDMFilter_InitStruct *)&Filter);
for(i=0;i < PCM_LENGTH;i++)
{
PCM_out[i]=(int16_t)OutputBuffer0[i]; //< Casting
}
}
else
{
pAudioRecBuf=OutputBuffer1;
PDM_Filter_64_LSB((uint8_t *)AUDIO_SAMPLE_RX_MEM1,(uint16_t *)pAudioRecBuf, volume , (PDMFilter_InitStruct *)&Filter);
for(i=0;i < PCM_LENGTH;i++)
{
PCM_out[i]=(int16_t)OutputBuffer1[i]; //< Casting
}
}
}
DMA_ClearITPendingBit(DMA_SPI, DMA_IT_HTIF3); ///< clear pending interrupt
} //< End of DMA1_Stream3_IRQHandler

And this the best possible plotting I got. 0690X00000603KIQAY.jpg Is there anything else I miss?