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
-
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.أيمن الفحصي– أيمن الفحصي04/27/2022 12:23:18Commented Apr 27, 2022 at 12:23
-
Related: arduino.stackexchange.com/questions/44868/…chrisl– chrisl04/27/2022 12:38:43Commented 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 codechrisl– chrisl04/27/2022 12:42:54Commented Apr 27, 2022 at 12:42
-
here is my code :أيمن الفحصي– أيمن الفحصي04/27/2022 12:46:34Commented Apr 27, 2022 at 12:46
-
please check the questionأيمن الفحصي– أيمن الفحصي04/27/2022 12:48:15Commented Apr 27, 2022 at 12:48
lang-cpp