Go Down

Topic: Cannot detect lower frequency (Read 529 times) previous topic - next topic

karansahni

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.

Code: [Select]


#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?

DVDdoug

NOTE - I've never used the FFT library.

Are you saying the frequency is low or the amplitude is low?

In the audio/sound world 3kHz isn't low...   It's mid-frequency and sounds  rather high-pitch.    3kHz is low in the RF world.   A piezo won't reproduce low (bass) audio frequencies.
 
Does it sound "loud"?   Is the microphone close to the piezo?

How does the 3kHz FFT data compare to other frequencies?   Are you saying higher frequencies show more amplitude?    

Code: [Select]
#define SAMPLING_FREQUENCY 40000
A 40kHz sample rate is high for the Arduino.   The ATmega datasheet says you loose resolution above 15kHz (which means the signal is limited to 7.5kHz).

Code: [Select]
  analogWriteFrequency(buzzerPin,25000);That's not 3000Hz.  (You can't hear 25kHz, although you might hear some resonance/noise in the audio range.)


karansahni

Yes, it is our class project and the professor is using a piezo buzzer. The lower the frequency the lower the amplitude as well. But our TA said he could get values with a teensy. So, I shifted to that but am encountering the same problem.

All he said was to make the sampling frequency and number of bins dynamic because right now, the sampling frequency is very high for 3KHz.

I reduced the sampling frequency to 6000 still, unable to detect.

Grumpy_Mike

Quote
I reduced the sampling frequency to 6000 still, unable to detect.
No you need a faster sample rate not a slower one.

Go Up