Go Down

Topic: MEMS Microphone (SPH0645LM4H) Library Problem (Read 587 times) previous topic - next topic

ycngz

Hello everyone,



I need to convert the output of the microphone into dB and apply a spectrum analysis. I'm using Adafruit MEMS microphone SPH0645LM4H with Arduino Mkr1000.


I am currently working with the ArduinoSound library, however there are couple things that I do not understand.


SPH0645LM4H microphone's output is 24 bits with 18 precision.


Arduino Sound library outputs 32 bits, so I can not get a true output since MEMs microphone and the library does not match in this sense.


Do you know how  can I change this bit value in the library to match it with to microphone?



It would be great If you could help me with this problem, thanks.



Grumpy_Mike

#1
Oct 25, 2018, 10:30 am Last Edit: Oct 25, 2018, 10:31 am by Grumpy_Mike
Quote
Do you know how  can I change this bit value in the library to match it with to microphone?
Take the microphone output and shift it to the left four times.
Code: [Select]
inputToFFT = microphone << 4;

ycngz

Take the microphone output and shift it to the left four times.
Code: [Select]
inputToFFT = microphone << 4;

This is the code I used, which line should be changed?

 Circuit:
 * Arduino/Genuino Zero, MKRZero or MKR1000 board
 * ICS43432:
   * GND connected GND
   * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKRZero)
   * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKRZero)
   * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKRZero)
   * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKRZero)

#include <ArduinoSound.h>

// sample rate for the input
const int sampleRate = 12800;

// size of the FFT to compute
const int fftSize = 128;

// size of the spectrum output, half of FFT size
const int spectrumSize = fftSize / 2;

// array to store spectrum output
int spectrum[spectrumSize];

// create an FFT analyzer to be used with the I2S input
FFTAnalyzer fftAnalyzer(fftSize);

void setup() {
// Open serial communications and wait for port to open:
  // A baud rate of 115200 is used instead of 9600 for a faster data rate
  // on non-native USB ports
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // setup the I2S audio input for the sample rate with 32-bits per sample
  if (!AudioInI2S.begin(sampleRate, 32)) {
    Serial.println("Failed to initialize I2S input!");
    while (1); // do nothing
  }

  // configure the I2S input as the input for the FFT analyzer
  if (!fftAnalyzer.input(AudioInI2S)) {
    Serial.println("Failed to set FFT analyzer input!");
    while (1); // do nothing
  }
}

void loop() {
  // check if a new analysis is available
  if (fftAnalyzer.available()) {
    // read the new spectrum
    fftAnalyzer.read(spectrum, spectrumSize);

    // print out the spectrum
    for (int i = 0; i < spectrumSize; i++) {
      Serial.print((i * sampleRate) / fftSize); // the starting frequency
      Serial.print("\t"); //
      Serial.println(spectrum); // the spectrum value
    }
  }
}

MarkT

This looks suspicious to me:
Code: [Select]

  // setup the I2S audio input for the sample rate with 32-bits per sample
  if (!AudioInI2S.begin(sampleRate, 32)) {

If you admit the samples are 24 bit, it might do a better job...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

ycngz

#4
Oct 25, 2018, 03:07 pm Last Edit: Oct 25, 2018, 03:10 pm by ycngz
This looks suspicious to me:
Code: [Select]

  // setup the I2S audio input for the sample rate with 32-bits per sample
  if (!AudioInI2S.begin(sampleRate, 32)) {

If you admit the samples are 24 bit, it might do a better job...
No, this line just justifies if its in correct bitrate or not, gives warning and stops the code if its not 32 bps

there are several libraries connected to main code which arranges the sample and its bitrate

audioin or audioini2s could be correct file to fix this issue, but I m unable to analyze

Grumpy_Mike

Quote
This is the code I used, which line should be changed?
Well it is not really a program as such, it is just a piece of code that calls two functions. These functions are implemented in libraries so you would would have to alter the code in those libraries.

Go Up