Mems Mic over I2S_ Calculate sound level (db) out of FFT values

Baseladams

New member
Hello,
i connecting a mems mic to teensy over I2S and getting 20 fft values after each measurement. I have a very basic question :D. How to calculate the sound level in db out of the fft values?
Thanks, Basel
 
P.s. I am using following code:

"
#include <Audio.h>
AudioInputI2S input;
AudioAnalyzeFFT1024 fft;
AudioConnection connection(input, 0, fft, 0);


void setup() {
Serial.begin(9600);
AudioMemory(50);
}

void loop() {
float n;
int i;



if(fft.available()){

// each time new FFT data is available
// print it all to the Arduino Serial Monitor
//Serial.print("FFT: ");
for (i = 0; i < 20; i++) {
n = fft.read(i);



if (n >= 0.0002) {
Serial.print(n*1000, 3);
Serial.print(" ");
} else {
Serial.print(" -- "); // don't print "0.00"
}


}
Serial.println(sum);
}

}
"
 
Code:
#include <Audio.h>
AudioInputI2S input;
AudioAnalyzeFFT1024 fft;
AudioConnection connection(input, 0, fft, 0);


void setup() {
	Serial.begin(9600);
	AudioMemory(50);
}

void loop() {
	float n;
	int i;



	if (fft.available()) {

		// each time new FFT data is available
		// print it all to the Arduino Serial Monitor
		//Serial.print("FFT: ");
		for (i = 0; i < 20; i++) {
			n = fft.read(i);



			if (n >= 0.0002) {
				Serial.print(n * 1000, 3);
				Serial.print(" ");
			}
			else {
				Serial.print(" -- "); // don't print "0.00"
			}


		}
		Serial.println(sum);
	}

}
In future could you enclose your posted code between code tags using the # button, I think you will agree that it makes your code much easier to understand. This will make it more likely that someone will be able to help you.
Unfortunately I have no experience using the Audio card so I do not fall into that group.
 
This is what I am using to get to dB after the FFT has been calculated (note I am using a floating point FFT here)

Code:
 for(j=0;j<samples/2;j++){
      vReal[j] /= (double)samples/2.0; // bring back to original units
      vReal[j] = 20.0*log10f(vReal[j]);             // convert to dB
  }
 
Back
Top