Hi, I am trying to create an algorithm that takes in data in from real life and tells me the frequency. I am using an Arduino UNO, an Electret Microphone Amplifier - MAX4466 with Adjustable Gain. [. right now I am just getting tons of zeros. could you please help me. I am using the FFT Library. ArduinoFFT - Open Music Labs Wiki. here is my current Code.
/*
fft_adc_serial.pde
guest openmusiclabs.com 7.7.14
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.
*/
#define LIN_OUT8 1 // use the lin8 output function
#define FFT_N 256 // set to 256 point fft
#include <FFT.h> // include the library
int total;
int artificial_delay;
void setup() {
Serial.begin(115200); // use the serial port
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop() {
while (1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
while (!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = ((j << 8) | m) - 512; // form into an int and subtract DC Offset
k <<= 6; // form into a 16b signed int
fft_input[i] = k; // put real data into even bins
fft_input[i + 1] = 0; // set odd bins to 0
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_lin8(); // take the output of the fft
sei();
Serial.println();
for (byte x = 0 ; x < (FFT_N / 2) ; x++) {
Serial.println(fft_lin_out8[x]); // send out the data
}
for (int i = 0; i < 128; i++) {
total = total + fft_lin_out8[i]; // adding all items in the fft output list for use in the following "if" filter
}
}
/*if (total>0){ //IGNORE EVERYTHING IN THIS COMMENTED OUT SECTION.
if (fft_lin_out8[127] == 0){
digitalWrite(bassLED, HIGH);
Serial.println(total);
}
}*/
}
Tomigee2.ino (1.89 KB)](Electret Microphone Amplifier - MAX4466 with Adjustable Gain : ID 1063 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits)