Frequency returned different
With the old library the following code returned a frequency of 944 Hz with an input of 941 Hz tuning fork.
With the new library the frequency was 936 Hz.
With the old library the following code returned a frequency of 944 Hz with an input of 941 Hz tuning fork.
With the new library the frequency was 936 Hz.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
int maxbin, k;
const int myInput = AUDIO_INPUT_MIC;
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioInputI2S audioInput; // audio shield: mic or line-in
AudioAnalyzeFFT1024 myFFT;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out
// Create Audio connections between the components
AudioConnection c1(audioInput, 0, audioOutput, 0);
AudioConnection c2(audioInput, 0, myFFT, 0);
AudioConnection c3(audioInput, 1, audioOutput, 1);
// Create an object to control the audio shield.
AudioControlSGTL5000 audioShield;
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12);
myFFT.windowFunction(AudioWindowBlackmanHarris1024);
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(0.6);
}
void loop() {
if (myFFT.available()) {
// each time new FFT data is available
// print it all to the Arduino Serial Monitor
k=0;
maxbin=0;
for (int i=0; i<512; i++) {
if (myFFT.output[i]>maxbin) {
maxbin=myFFT.output[i];
k=i;
}
}
Serial.println();
Serial.print("Max Bin ");
Serial.print(k);
Serial.println();
double y1=double(myFFT.output[k-1]);
double y2=double(myFFT.output[k]);
double y3=double(myFFT.output[k+1]);
double d=(y3-y1)/((2.0*(2.0*y2-y1-y3)));
Serial.print("Diff ");
Serial.print(d);
Serial.println();
double Freq=(AUDIO_SAMPLE_RATE_EXACT/1024.0)*(double(k)+d);
Serial.print("Freq ");
Serial.print(Freq);
Serial.println();
}
}