cancel
Showing results for
Did you mean:

# Is it possible to measure sound intensity level from PCM samples?

Associate II

I am using two PDM microphones(mems transducer) with STM32 to measure the intensity and if the intensity of the left microphone is higher than the right one then an LED should turn on and vice versa.

We measure the intensity of analog signals like when the signal is higher than a certain threshold then do something(if(ADC_Val >= 3000)do something...), so is it possible to do such things with digital microphones?

Is it possible to measure the intensity of sound level from PCM samples?

1 ACCEPTED SOLUTION

Accepted Solutions
Principal III

Q: Can you please share the same example in C?

A:

Sure, here is an example of how to calculate the RMS value of a set of PCM samples in C:

#include <math.h>

float rms(float* samples, int num_samples) {

float sum = 0;

for (int i = 0; i < num_samples; i++) {

sum += samples[i] * samples[i];

}

return sqrt(sum / num_samples);

}

You can then use the RMS value to convert the sound intensity level to decibels (dB) using the following formula:

float intensity_level_dB = 20.0f * log10(rms / reference_level);

where

reference_level

is a reference intensity level that you can choose based on your application. For example, you could use a reference level of 1 pascal for measuring sound pressure levels in air.

It's worth noting that the RMS value is just one way to measure the intensity of sound from PCM samples. There are other methods that may be more appropriate for specific applications, such as peak or crest factor, or the average power of the signal.

4 REPLIES 4
Principal III

Yes, it is possible to measure the sound intensity level from PCM (pulse-code modulation) samples. PCM is a digital representation of an analog signal, in which the amplitude of the analog signal is sampled at regular intervals and the resulting samples are quantized and encoded using a digital code.

To measure the sound intensity level from PCM samples, you can use the root mean square (RMS) value of the samples. The RMS value is a measure of the average power of a signal and is often used to measure the intensity of sound. It is calculated by taking the square root of the mean of the squares of the individual samples.

Here is an example of how to calculate the RMS value of a set of PCM samples in Python:

import numpy as np

def rms(samples):

return np.sqrt(np.mean(np.square(samples)))

You can then use the RMS value to convert the sound intensity level to decibels (dB) using the following formula:

intensity_level_dB = 20 * log10(rms / reference_level)

where

reference_level

is a reference intensity level that you can choose based on your application. For example, you could use a reference level of 1 pascal for measuring sound pressure levels in air.

It's worth noting that the RMS value is just one way to measure the intensity of sound from PCM samples. There are other methods that may be more appropriate for specific applications, such as peak or crest factor, or the average power of the signal.

Associate II

Thank you so much!

I am new to STM32 and mems technology. Can you please share the same example in C?

Principal III

Q: Can you please share the same example in C?

A:

Sure, here is an example of how to calculate the RMS value of a set of PCM samples in C:

#include <math.h>

float rms(float* samples, int num_samples) {

float sum = 0;

for (int i = 0; i < num_samples; i++) {

sum += samples[i] * samples[i];

}

return sqrt(sum / num_samples);

}

You can then use the RMS value to convert the sound intensity level to decibels (dB) using the following formula:

float intensity_level_dB = 20.0f * log10(rms / reference_level);

where

reference_level

is a reference intensity level that you can choose based on your application. For example, you could use a reference level of 1 pascal for measuring sound pressure levels in air.

It's worth noting that the RMS value is just one way to measure the intensity of sound from PCM samples. There are other methods that may be more appropriate for specific applications, such as peak or crest factor, or the average power of the signal.

Chief II

FYI exist too ARM math library maybe speedup rms and other calculations, for example FFT.

``````#include "arm_math.h"

q15_t inc1_ccram_buffer[2048] __attribute__((section(".ccmram")));
q15_t outc1[5] __attribute__((section(".ccmram")));

...

arm_rms_q15(inc1_ccram_buffer,512,  &outc1[0]);``````