# Frequency Analysis

Hey folks!
Maybe you can help me... I'm new in the analog-sector and audio. But I need an option to analyses an audio stream incoming from a microphone that triggers a function on a special frequency.

Hope you understand what I mean? Maybe a great tutorial or something? I just found the word "FFT" but have no idea how to deal with...

Thank you!

I've never used this stuff, but there are FFT and FHT libraries for the Arduino so you don't have to do the math yourself. But, you do need to understand what FFT does.

Do you have a microphone shield (or something similar) and are you getting audio readings? What frequency are you looking for?

"Normal" audio is represented in the time domain where there is an amplitude for every moment* in time. For example this amplitude determines the position at any moment in time as it vibrates in & out. A regular VU/loudness meter works in the time domain.

FFT converts the data to the frequency domain where the audio is represented as the frequency content at any moment* in time.

Have you ever seen a [u]spectrum analyzer[/u]? With a spectrum analyzer, the low frequencies are on the left and the high frequencies are on the right

If you are interested in a single frequency you don't need FFT. You simply need a bandpass filter (which can be implemented digitally). A bandpass filter reduces frequencies above and below the bandpass frequency.

• With digitized audio these moments are quantized/sampled. CD audio is sampled 44,100 times per second. With FFT you might have about 1000 samples per FFT conversion so you might have 4000 FFT conversions per second.

A consine resonator or complex resonator is another way to pick out and detect a specific frequency

DVDdoug:

• With digitized audio these moments are quantized/sampled. CD audio is sampled 44,100 times per second. With FFT you might have about 1000 samples per FFT conversion so you might have 4000 FFT conversions per second.

This doesn’t quite add up. 1000 samples per FFT times 4000 FFTs per second is 4 MHz sample rate.

FFT lengths are powers of 2, so 1024 samples is the closest realistic FFT time. If you compute one FFT for every 1024 samples at 44.1 kHz sample rate, that’s approximately 43 FFTs per second.

For analysis of ordinary signals, the 1024 input samples are usually multiplied by a window function before the FFT. This is necessary to prevent the problem of spectral leakage. The window function attenuates the signal near both ends of the 1024 points. Because the FFT is then sensitive mostly to the middle portion of those 1024, a typical approach is to overlap FFTs. Twice as many are computed, staggered every 512 samples. That results in 86 FFTs per second.

I wrote a detailed tutorial about these and other FFT issues. You can find it here:

http://www.pjrc.com/store/audio_tutorial_kit.html

The FFT info begins on page 24. There’s also a complete walkthrough video (scroll down at that page). The FFT material begins at 34:56 into the video.

However, FFT is often not the best algorithm.

If you’re looking to detect the level of a single known (fixed) frequency, the Goertzel algorithm is usually the most optimal way. Goertzel is particularly attractive for specific frequencies which don’t happy to fall neatly onto a FFT bin frequency. However, for very low frequencies (relative to the sample rate), it does require more numerical precision in its intermediate calculations.

If you’re looking to detect an unknown frequency which may have many strong harmonics present, which is typical for musical instruments, the YIN algorithm works well to discover the actual fundamental frequency of the sound.

I was curious about how the Goertchel filter would perform on an Uno. The attached traces show the outputs for 50 Hz and 51 Hz input signals with a filter tuned to 50 Hz. It makes a pretty good notch filter. The problem is that being an unstable filter, once it starts oscillating the filter needs to be cleared when the frequency is changed in order to stop the oscillation. Not a huge problem. This could be corrected by moving the poles slightly inside the unit circle.