Hello,
I have looked around a lot for something to detect frequency, and i have found a library that does that.
What i want is for this code to read the peak frequency from the microphone im using. I am using the MAX9814 microphone and Arduino MKR1000.
Basically i am trying to create drum tuner using arduino. Within the code the bandwidth is set from 70 to 210 hz because a well tuned toms drum produces a frequency range from 100 to 200hz.
#include <AudioFrequencyMeter.h>
AudioFrequencyMeter meter;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("started");
meter.setBandwidth(70.00, 210); // Ignore frequency out of this range
meter.begin(A0, 45000); // Intialize A0 at sample rate of 45kHz
}
void loop() {
// put your main code here, to run repeatedly:
float frequency = meter.getFrequency();
if (frequency > 0)
{
Serial.print(frequency);
Serial.println(" Hz");
}
}
It seems straightfoward but i wasnt sure how to make it detect peak frequency.
Does the frequency readings look correct?
Look into the Arduino reference. There is a function: max( a, b). Try My_Max = max(My_max, frequency).
What can you tell us about AudioFrequencyMeter.h? Does that give you "the frequency"? Does that not work?
I'm not sure what you mean by "peak" frequency... The highest frequency component will NOT help you with tuning.
I assume you want the most-dominant frequency? Or maybe the lowest frequency with "significant" frequency. Typically, the fundamental frequency (the lowest frequency) is perceived as pitch, but drums contain lots of nonharmonic harmonics and they aren't usually considered "pitched" so I don't know. i.e., With normal drums you don't play notes or chords and you don't change the drum tuning when you play a song in different key.
You probably need [u]FFT[/u] (there is an FFT library for the Arduino). FFT will give you the frequency spectrum of the signal/sound and you (your software) should be able to pick-out the dominant frequency.
An FFT is no good for tuning. It won't tell you if you are off by a little bit. It just puts all the nearby frequencies into a relatively wide "bin".