0

I'm using a simple electrode microphone with an Arduino UNO board with the aim of detecting peak frequencies in the output signal overtime. I set the sampling rate to 1 MHz, but i can't pick up a peak that is above 4000 Hz(I've verified the values with regression but it's only true for the range [200 Hz, 3900 Hz]). So my questions are:

  • Is this due to the microphone's sensibility or to the Arduino UNO?
  • Someone suggested me an ESP32, but i don't understand what difference it'll make.

CODE:

#include "arduinoFFT.h"
float peak = 0;
float val = 0;
#define SAMPLES 128 //SAMPLES-pt FFT. Must be a base 2 number. Max 128 for Arduino Uno.
#define SAMPLING_FREQUENCY 1000000 //Ts = Based on Nyquist, must be 2 times the highest expected frequency.
 
arduinoFFT FFT = arduinoFFT();
 
unsigned int samplingPeriod;
unsigned long microSeconds;
 
double vReal[SAMPLES]; //create vector of size SAMPLES to hold real values
double vImag[SAMPLES]; //create vector of size SAMPLES to hold imaginary values
 
void setup() 
{
 Serial.begin(115200); 
 samplingPeriod = round(1000000*(1.0/SAMPLING_FREQUENCY)); //Period in microseconds
 
}
 
void loop() 
{ 
 
 for(int i=0; i<SAMPLES; i++)
 {
 microSeconds = micros(); 
 val = analogRead(0);
 vReal[i] = val; 
 vImag[i] = 0; 
 
 while(micros() < (microSeconds + samplingPeriod))
 {
 
 }
 }
 
 
 FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
 FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
 FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
 
 peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
 Serial.println((peak-5063)/122.5); 
 Serial.print(";");
 
sempaiscuba
1,0429 gold badges21 silver badges32 bronze badges
asked Apr 27, 2022 at 12:22
12
  • i've used the included FFT library, and generated sounds with an app then verified the measured frequencies with the Spectroid app, albeit i had to put the source right at the microphone. Commented Apr 27, 2022 at 12:23
  • Related: arduino.stackexchange.com/questions/44868/… Commented Apr 27, 2022 at 12:38
  • I doubt, that you really have an ADC sampling frequency of 1MHz on an Arduino Uno. 4kHz seems to be about aligned with 2x the max sample rate in the first comment of that question (niquist frequency). The ESP32 was surely suggested, because it runs on a way faster clock. Mine is set to 240MHz by default (in contrast to the Unos 16MHz). Please show us your code Commented Apr 27, 2022 at 12:42
  • here is my code : Commented Apr 27, 2022 at 12:46
  • please check the question Commented Apr 27, 2022 at 12:48

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.