Hey I am using MAX4466 mic to detect frequency of a pieo PS1240. But the value for 3000 Hz is super low and hence, cannot detect it. I am using arduinoFFT.h library.
#include "arduinoFFT.h"
#define SAMPLES 128
#define SAMPLING_FREQUENCY 40000
arduinoFFT FFT = arduinoFFT();
int mic = 14;
int buzzerPin = 4;
int led = 13;
double vReal[SAMPLES];
double vImag[SAMPLES];
double avg[SAMPLES/2]={0};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
analogReadResolution(10);
pinMode(mic,INPUT);
pinMode(led,OUTPUT);
pinMode(buzzerPin,OUTPUT);
analogWriteFrequency(buzzerPin,25000);
}
void loop() {
// put your main code here, to run repeatedly:
int time1,time2;
int i,frame;
//Analog read takes 14us plus delay of 11us = 25us ( 40khz )
for(frame=0;frame<MAXFRAME;frame++){
for(i=0;i<SAMPLES;i++){
time1 = micros();
vReal[i] = ((analogRead(mic) * 3.3)/1024) - 1.65;
vImag[i] = 0;
while((time2 = micros() - time1 ) < 25);
//Serial.println(time2);
}
/*FFT*/
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
vReal[0] = vReal[1] = 0;
for(int j=0;j<SAMPLES/2;j++){
if(vReal[j]>0.1){ //0.1 is threshold
avg[j] += vReal[j];
}
}
}
for(i=0;i<SAMPLES/2;i++){
vReal[i] = avg[i]/MAXFRAME;
avg[i] = 0;
}
///DO NO CHANGE ABOVE
for(i=0;i<20;i++){
Serial.print("[ ");
Serial.print(i);
Serial.print(" - ");
Serial.print(vReal[i]);
Serial.print("] ");
}
Serial.println("");
delay(100);
// FFT
}
Is there any tweaks I can do in the library to improve the detection of 3K and under frequency?