Hi I was trying to do Arduino FFT using an Arduino and a MAX4466 Electret Microphone Amplifier Adjustable Gain.
I'm trying the following code but I keep getting random numbers can somebody help me to fix this code and correctly do FFT. By the way i'm new to Arduino so please give me tips as well. Thanks.
#include "arduinoFFT.h"
#define SAMPLES 128 //Must be a power of 2
#define SAMPLING_FREQUENCY 1000 //Hz, must be less than 10000 due to ADC
arduinoFFT FFT = arduinoFFT();
unsigned int sampling_period_us;
unsigned long microseconds;
double vReal[SAMPLES];
double vImag[SAMPLES];
void setup() {
Serial.begin(115200);
sampling_period_us = round(1000000*(1.0/SAMPLING_FREQUENCY));
}
void loop() {
/SAMPLING/
for(int i=0; i<SAMPLES; i++)
{
microseconds = micros(); //Overflows after around 70 minutes!
vReal = analogRead(0);
_ vImag = 0;_
* while(micros() < (microseconds + sampling_period_us)){
_ }_
_ }*_
_ /FFT/
* FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
_ FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);*
* double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);*
_ /PRINT RESULTS/_
* //Serial.println(peak); //Print out what frequency is the most dominant.*
* for(int i=0; i<(SAMPLES/2); i++)*
* {*
_ /View all these three lines in serial terminal to see which frequencies has which amplitudes/_
//Serial.print((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1);
* //Serial.print(" ");*
_ Serial.println(vReal*, 1); //View only this line in serial plotter to visualize the bins*
* }*_
* //delay(1000); //Repeat the process every second OR:*
* while(1); //Run code once*
}