Ok, so what I want to do is record samples with a microphone, perform a Fourier-Hartley Transform with the ArduinoFHT Library, then use the different values in the bins, which correspond to certain frequencies (right?) to perform further actions.
My problem is that I need to know which bin corresponds to which frequency.
There are 128 Bins when the FHT is performed.
I've read somewhere that the first bin corresponds to the frequency (sampling rate/2), the second to (sampling rate/4). However, I don't even know the sampling rate, plus this doesn't make sense in my opinion.
This is the example code when the FHT is downloaded. I added the for loop to print out each bin with its value.
/*
fht_adc.pde
guest openmusiclabs.com 9.5.12
example sketch for testing the fht library.
it takes in data on ADC0 (Analog0) and processes them
with the fht. the data is sent out over the serial
port at 115.2kb. there is a pure data patch for
visualizing the data.
*/
#define LOG_OUT 1 // use the log output function
#define FHT_N 256 // set to 256 point fht
#include <FHT.h> // include the library
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 < FHT_N ; i++) { // 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; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fht_input[i] = k; // put real data into bins
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_log(); // take the output of the fht
sei();
Serial.println(">>>Start");
for (int i = 2; i < FHT_N/2; i++) { //Print out every bin with its value. The first 2 bins seem to be pink noise, which is the reason why they arent printed out.
Serial.print(fht_log_out[i]);
Serial.print(", ");
}
Serial.println();
}
}
Example Serial Bin Output:
60, 44, 30, 53, 32, 16, 24, 38, 43, 8, 16, 24, 27, 19, 19, 0, 42, 25, 38, 25, 19, 24, 19, 33, 16, 41, 0, 30, 16, 38, 24, 19, 30, 0, 25, 16, 24, 19, 0, 27, 8, 8, 33, 0, 0, 8, 8, 30, 8, 25, 19, 16, 16, 25, 0, 16, 8, 33, 19, 19, 8, 27, 0, 8, 27, 0, 0, 33, 8, 0, 0, 19, 16, 0, 0, 0, 8, 19, 8, 27, 0, 0, 25, 8, 8, 8, 0, 25, 0, 16, 0, 19, 19, 19, 16, 8, 16, 19, 0, 8, 35, 19, 19, 16, 0, 30, 8, 0, 19, 19, 0, 19, 8, 16, 0, 8, 19, 8, 0, 0, 16, 0, 19, 0, 0, 0,
Thanks for your help