Hi guys,
Objective:
To detect whistling.
Hardware:
-
Arduino Yun
-
Electret Microphone Amplifier - MAX4466 with Adjustable Gain
Wiring: -
Vcc -> 3.3v
-
Ground -> ground
-
Output -> A0
Library:
OpenMusicLabs FHT
Question:
I have read many, many forum threads about the FHT and the FFT, but some of them I do not understand, and many of them does not really give an answer, but just ends with OP going silent or finding a tweak that helped his individual project.
I need to be able do detect a human whistle, or at least just sounds around a high pitched frequency.
When I run the code (posted below), I get the same output every time, which of course tells me something is wrong. I have read that disabling the window function helps this problem, but I have also read that this function must be kept.
Can someone give me something to work from as I am completely lost where to begin? Right now I understand that the output is a collection of bins, each representing a frequency range, and the integer shows the amplitude of that range - is that correct?
Code:
/*
fht_adc_serial.pde
guest openmusiclabs.com 7.7.14
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.
*/
#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 = 0; i < FHT_N / 2; i++)
{
Serial.println(fht_log_out[i]);
}
Serial.flush();
}
}
Output:
start
232
216
80
60
47
42
38
32
33
19
27
27
19
19
19
19
8
19
19
27
16
19
19
19
19
19
19
16
19
19
19
19
0
8
8
16
16
0
19
19
19
19
19
19
16
19
19
16
0
16
19
8
19
8
8
19
19
0
19
19
0
19
8
0
8
0
8
0
0
0
0
0
0
0
8
8
0
8
0
0
0
0
19
0
0
0
0
0
0
0
0
19
16
0
8
8
0
0
0
0
0
16
0
0
0
0
0
0
16
8
0
0
8
0
0
0
0
8
8
0
0
0
8
0
8
0
19
0