I need something for measuring frequency of audio.

Would I be able to measure the frequency of audio with this? https://www.amzn.com/B0173OAWE4

Also if it does, how accurate can I expect it to be?

What kind of sound?

I assume you know that real-world sounds contain many simultaneous frequencies? i.e. When you play a note on an instrument you perceive the pitch of the fundamental (which is usually the lowest-strongest frequency component). Harmonics & overtones are what makes a guitar sound different from a trumpet, or what makes two singers sound different (when they are singing the same notes). If there are chords or multiple instruments, things get even more complicated.

Would I be able to measure the frequency of audio with this? https://www.amzn.com/B0173OAWE4

No. From the description, it converts the sound to a varying DC signal that follows the loudness, or a binary (on/off) output depending on loudness. It "throws-away" the frequency information.

[u]Here is a microphone board with a normal preamp[/u]. With the right microphone/preamp you can get an electrical representation of the sound (including the frequency information). Or, if you have a headphone or line-output, or an electric guitar, etc., you already have an electrical signal and you don't need a microphone. (But you will need to bias the signal because the Arduino can't read negative voltages... Many microphone boards have the bias built-in.).

You can get a fairly accurate measure of the frequency of a pure sine wave by timing the zero-crossings. (But, the Arduino's ADC isn't fast-enough for the highest audio frequencies.)

People have made spectrum analyzers and if you Google "Aduino Spectrum Analyzers" or search YouTube you can see what's been done. These are done with [u]FFT[/u] or FHT. There are libraries for these so you don't have to write the code yourself, but you should understand how it works. (All of the spectrum analyzers I've seen that are made from the Arduino, are "effects" or "displays". A true spectrum analyzer is a measurement instrument which would be calibrated and more accurate.)

From what I read here on the forum, people have a hard time making a guitar tuner. But, the best method seems to be an [u]autocorrelation[/u] algorithm.

DVDdoug:
What kind of sound?

I assume you know that real-world sounds contain many simultaneous frequencies? i.e. When you play a note on an instrument you perceive the pitch of the fundamental (which is usually the lowest-strongest frequency component). Harmonics & overtones are what makes a guitar sound different from a trumpet, or what makes two singers sound different (when they are singing the same notes). If there are chords or multiple instruments, things get even more complicated.
No. From the description, it converts the sound to a varying DC signal that follows the loudness, or a binary (on/off) output depending on loudness. It "throws-away" the frequency information.

[u]Here is a microphone board with a normal preamp[/u]. With the right microphone/preamp you can get an electrical representation of the sound (including the frequency information). Or, if you have a headphone or line-output, or an electric guitar, etc., you already have an electrical signal and you don't need a microphone. (But you will need to bias the signal because the Arduino can't read negative voltages... Many microphone boards have the bias built-in.).

You can get a fairly accurate measure of the frequency of a pure sine wave by timing the zero-crossings. (But, the Arduino's ADC isn't fast-enough for the highest audio frequencies.)

People have made spectrum analyzers and if you Google "Aduino Spectrum Analyzers" or search YouTube you can see what's been done. These are done with [u]FFT[/u] or FHT. There are libraries for these so you don't have to write the code yourself, but you should understand how it works. (All of the spectrum analyzers I've seen that are made from the Arduino, are "effects" or "displays". A true spectrum analyzer is a measurement instrument which would be calibrated and more accurate.)

From what I read here on the forum, people have a hard time making a guitar tuner. But, the best method seems to be an [u]autocorrelation[/u] algorithm.

Thanks for all the great information! This definitely helps with my project. I will look into autocorrelation. You mentioned the Arduino isn't fast enough for high audio frequencies. At what point does this happen?

You mentioned the Arduino isn't fast enough for high audio frequencies. At what point does this happen?

The ATmega datasheet says you can get the full 10-bit resolution up to a 15KHz sample rate. You can go above that but you loose resolution/accuracy.

That's the sample rate, so the Nyquist audio limit* is 7500Hz. ..."Musically", that's higher than the highest note on a piano (and beyond most other instruments) so it's usually only harmonics & overtones.

There may be other speed/frequency limitations depending on what your software is doing. Depending on the code you're running, you may not be able to read the analog input 15,000 times per second. (I assume the Arduino spectrum analyzers read & save the audio data for a short period of time and then stop reading to analyze for a short period of time and update the display before reading audio again... But I have NOT studied the code and that's just an assumption.)

*The simplest way to understand Nyquist is that you have to sample the top-half of the waveform at least once per cycle and bottom-half at least once.

For frequency determination you don't need much resolution, so push the sampling rate up to avoid
having to worry about an aliasing filter?

With 15kSPS sampling and no aliasing filter 10kHz looks exactly like 5kHz, you may get spurious
results. A sharp analog aliasing filter with a 7kHz cutoff or so is hard to make (several opamps).
Just up the sampling rate... Its easy to low-pass filter / decimate in the digital domain once you've there.

Depending on how complex the waveform is...if it is a single frequency why couldn't you just use a digital pin to measure the amount of time the pin is high and the amount of time the pin is low, add them together to get the time it takes to complete one cycle, then 1/cycle = frequency. If you're worried about the negative part of the wave on a digital pin use a rectifier to convert the negative part of the wave to positive value, then just measure how long it takes for two high readings to pass the digital pin.

For very simple waveforms, you can use a voltage comparator circuit with hystersis feedback to turn the signal into a digital square wave. Or very simple signals can simply be amplified and driven right to a digital pin. Then you can use the FreqMeasure library, or similar techniques. Any Arduino board can do this.

For moderately complex waveforms, you can use the AudioFrequencyMeter library. Arduino Zero or other SAMD boards are needed.

For very complex waveforms, the YIN algorithm gives good results. A very fast chip is needed. Teensy 3.2 is the minimum. There's an implementation in the Teensy Audio Library.

Something many people have tried, but does not work well, is FFT or FHT. At first FFT intuitively seems like the answer, since it converts a signal to frequencies. But this has 2 huge problems.

1: The frequency data is produced in coarse "bins", which are usually far too low resolution for useful results. You can increase the FFT size, at the cost of more memory and CPU power. But even with infinite memory and CPU power, larger FFT size means measuring over a longer time, which can only be done if the waveform remains stable. That may be useful for certain applications like tuning a musical instrument like a trombone where the note can be sustained as long as the musician can physically keep playing, but for shorter events like ordinary musical notes, or plucked or percussive instruments where the note changes character over time, you simply don't get enough consistently similar data no matter how much memory and CPU time you have.

2: FFT fundamentally analyzes a periodic signal. For arbitrary real signals which do not infinitely repeat at intervals perfectly aligned to the FFT data size, a "window" must be applied to scale the data before the FFT is computed. This avoids a problem known as "spectral leakage", which would utterly corrupt all your data, but the downside is a slight smearing of the results between bins. This undesirable but necessary step further reduces the already low frequency resolution.

This question comes up over and over again. Many people have wasted a lot of their time with FFT, only to learn these lessons over and over again.

Typically for determining the fundamental of a periodic waveform auto-correlation techniques are
a good fit. Maximal auto-correlation tends to fall at the fundamental's period, or exact fractions of it.
Windowing can be used for auto-correlations just as for fourier transforms, for the same reason.

For low frequencies where the FFT bins are very coarse, the auto-correlation resolution is highest...
(but the peaks are broad, kind of cancels out).
For both techniques windowing and good peak estimation techniques can enhance the resolution
beyond the width of a bin, given a clean enough signal.

But yes its an area with plenty of pitfalls if you don't fully understand whats going on!