Skip to main content
Visitor II
March 1, 2023
Question

How can I calculate the exact Audio frequency of a MEMS microphone?

  • March 1, 2023
  • 4 replies
  • 6702 views

Hi,

I developed an application that uses an STM32L452 and MP34DT06J, with SPI and DMA. I don't have an external clock on the MCU so I'm using the internal one. Regarding the storage, I'm using an external Micro SD driven with SDMMC.

Since I've more sensors acquiring at the same time, for me it's extremely important to know the exact frequency of the signals since it can lead to a misalignment of the signals. When I was recording sound with my application and comparing it with my smartphone, I found that the sampling frequency isn't exactly 16kHz. So the questions are:

  1. How can I find the exact frequency?
  2. Does the internal clock allow me to have a constant sampling frequency, with drift over time?

Best Regards

    This topic has been closed for replies.

    4 replies

    Technical Moderator
    March 1, 2023

    Welcome, @Community member​, to the community!

    The internal clock used for the PDM data stream is derived from the external clock at CLK (AN5027):

    PDM modulator converts the buffered analog signal into a serial pulse density modulated signal. The clock input (CLK) is used to control the PDM modulator. The clock frequency range for ST digital microphones is from 1 MHz to 3.25 MHz. This frequency defines the sampling rate at which the amplifier’s analog output signal is sampled to produce a discrete-time representation (PDM bitstream).

    So if your application with the STM32L452 uses internal, free-running clock sources, the sampling frequency cannot be more accurate than those clock sources.

    Does this answer your question?

    Regards

    /Peter

    MAndr.7Author
    Visitor II
    March 1, 2023

    Hi @Peter BENSCH​ 

    Thank you for your prompt response.

    So if the internal clock source is inaccurate, the audio sampling frequency will always be inaccurate too. That's the reason why I can't find the exact clock frequency. Is that right?

    Technical Moderator
    March 1, 2023

    Correct.

    However, all connected microphones follow the same frequency (if they are using the same clock) and behave identical to each other, which might help you in your application?

    Regards

    /Peter

    MAndr.7Author
    Visitor II
    March 1, 2023

    In my specific case, the sensorial specs are:

    • A microphone connected with SPI, with DMA.
    • ADC to acquire data from an analog sensor.
    • I2C for an ST's Accelerometer.

    These three sources of data are being stored in the SDCard and I need all these three completely aligned. For that, I need to know the exact audio frequency. So, it's not important if I have an audio frequency of 16kHz or 16.55KHz. However, it must be constant over time.

    I'm thinking about adding an HSE and changing the mic's peripheral to I2S with SAI. In this application note it's stated that with I2S, with mono channel, I can reach accuracies of 0ppm. Do you think it can solve my problem?

    I really appreciate you feedback

    Graduate
    March 2, 2023

    Not sure if this helps. But I need accurate timing from the PDM microphone for tuning purposes. The DFSDM is driven by a non-crystal clock. So I DMA the output of the DFSDM to a single location, then I use the accurate 32,768Hz LSE to drive a timer to sample that data from that memory location and transfer it to a buffer - works for me, my tuner is spot on accurate.

    Graduate II
    March 2, 2023

    @Community member​ 

    That's interesting, is there any HSI / clock calibration with the LSE involved?

    Because I cannot see how sampling data with accurate timing from memory location after DMA might help with exact sampling rates?

    Graduate
    March 2, 2023

    I don't bother trying to calibrate the HSI/MSI - I just use the LSE clock as the drumbeat for everything (input/output audio). DMAing the data from the DFSDM to a single location (let's call it location X) ensures that the data is up to date at location X (and independent of the LSE clock), and I then use the LSE driven timer to sample location X as if it was any other analogue source. Basically I'm using the DMA channels to re-sample the data at an accurate rate.

    Super User
    March 2, 2023

    > for me it's extremely important to know the exact frequency of the signals since it can lead to a misalignment of the signals

    If all sampling instants are derived from the same clock, there should be no drift between the signals.

    If you have a different master clock, feed the audio clock to a 32-bit timer/counter and record the counter value together with the other data for later correlation.

    If you know the total recording time of your data (from a wall clock, GPS,...) you may adjust the audio speed afterwards by a tool like audacity to match the correct play time.

    hth

    KnarfB