I developed a very simplistic algorithm to detect bubbles via audio from an airlock during fermentation. The airlock is simply filled with water, which makes bubbles and therefore bubble sounds, when CO2 passes through.

You can see in this image, I simply used a cheap microphone attached to a laptop to record audio from the airlock.

I wrote a simple bash script, which makes use of ‘sox’ to record the audio, it splits the audio into hourly chunks, which makes processing later easier.


# log start time
date > start

# record in hourly chunks
SEC=`expr 60 \* 60`
echo $SEC

# start recording
sox -d bubbles_.wav channels 1 rate 48k trim 0 $SEC : newfile : restart


I took a very simplistic method to detect bubbles, by taking the FFT of chunks of audio and obtaining magnitudes from this.

For each FFT, if there are N peaks above a certain magnitude, the chunk is simply classed as a bubble. Since the microphone is inside a fridge, next to the airlock, this cancels external noises reasonably well I think.

You can see in this video, the FFT output in the top graph, and in the bottom graph, whether we class something as a bubble or not.

Raw data

This graph depicts the bubbles per minute against time.

Line of best fit using Savitzky-Golay filter

This graph also depicts the bubbles per minute against time after a filter has been applied to the raw data.

Why not use an optical sensor?

I was curious if I could count the bubbles via audio, but an optical sensor approach looks like it works very well:

https://www.sparkfun.com/tutorials/131 – This is an excellent example of using an optical sensor. Interestingly I seem to get the same ‘dip’ in bubble production, near the start of the graph.

It could also be interesting to use a camera, to image the bubbles and perform some kind of edge detection and blob recognition.


I would definitely like to try to make the bubble detection far more resilient against other noises. If anyone has any suggestions, I’d be keen to hear.

Also I’m wondering if I can better detect individual bubbles within a group.


I now have 57 GB of audio files of bubbles, which does somewhat limit the usefulness of my approach 😉 It would be much better to process the audio in realtime and then only record bubble information, but I developed the algorithm after recording the audio and having raw audio does enable me to tweak the algorithm later.