December 8, 2022

Whistle Detector

I recently remembered my project a while back of making a whitlse detector with arduino. So I re-started that.

I am simply using arduino pro micro and variable (varistor) gain mic by Adafruit.

See the Github Repo here :


  1. mic_check
    Running mic on ADC to check values speed etc. Start here for testing
  2. mic_peakdet
    A peak detection on mic data to detect a blow or word into mic that is very close. We used this for a game controller. Takes running average of mic data for baseline and compares newest ADC val relative to that to identify relevant peaks
  3. mic_fft
    Calculates FFT with the <fix_fft.h> library. Print out the amplitude spectrum or group into bands. 128 Samples for N=7 order spectrum of 64 bands. Combine Real and Imaginary parts for amplitude spectrum.
  4. mic_whistle
    Finds peak in FFT, interpolates with neighbours to find a peak inbetween two bands. prints peak magnitude and band value above certain threshold. To convert into frequency you would need to measure and apply sampling rate
  5. mic_whistle2
    Finds peak and second peak in FFT and uses the ratio to judge noise / distinction. Uses ratio threshold then calculates frequency the same way
  6. mic_whistle3
    Attempt at tracking individual and consecutive whistles from beginning to end. Whistles are very discontinuous so still balancing out for gaps inside a whistle with the gap necessary in between two whistles. Then can do consecutive whistle detection for different commands.
  7. Next i still have some Relays so maybe can use this for some lights

Still false positives that pop up as frequencies that are detected right after a real detected whistle ends. Generally pretty good performance for little Arduino and mic. Big problem / question is distance from the mic though. Noise subsceptibility /filtering is pretty good with peak-2nd-ratio though.

This is a complete do-it-yourself, there are much simpler / smarter solutions out there that use an i2c microphone that probably deals way better with on-board noise , a mic with voltage-comparator module that makes the the frequency computation easy as bits.

Leave a Reply