So I think I can print out the magnitude in dB. Not sure if it is correct or not, but it feels really good to have some numbers coming out.
How do I go about extracting the frequency?
Just to learn FFT, I tried out kissFFT in C++ a couple days ago. I filled up an array with single sine function, and I passed the array to kissfft, then I output all the numbers from the first half of the bin. The array was set to have size the same as number of samples, so that the bin number = frequency for testing purpose. The output I had was all zero except the bin where the frequency of sine function is.
Can I do the same to fft library in arduino? I tried it. but a lot of the outputs aren't zero. Not sure if it's correct. Please point out any possible error.
Here is the code I used to test fft library:
#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft
#include <FFT.h> // include the library
void setup() {
Serial.begin(9600); // use the serial port
}
void loop() {
// put your main code here, to run repeatedly:
int k = 0;
int t = 0;
for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
k = 127*sin(2*3.14 * 100 * t );
t++;
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_log(); // take the output of the fft
for(int i = 0; i < 128; i++){
Serial.println(fft_log_out[i]);
}
delay(1000);
}