Ultrasonically detect bats with Raspberry Pi

Welcome to October, the month in which spiderwebs become decor and anything vaguely gruesome is considered ‘seasonal’. Such as bats. Bats are in fact cute, furry creatures, but as they are part of the ‘Halloweeny animal’ canon, I have a perfect excuse to sing their praises.

baby bats in a row wrapped up like human babies
SEE? Baby bats wrapped up cute like baby humans

Tegwyn Twmffat was tasked with doing a bat survey on a derelict building, and they took to DesignSpark to share their Raspberry Pi–powered solution.

UK law protects nesting birds and roosting bats, so before you go knocking buildings down, you need a professional to check that no critters will be harmed in the process.

The acoustic signature of an echo-locating brown long-eared bat

The problem with bats, compared to birds, is they are much harder to spot and have a tendency to hang out in tiny wall cavities. Enter this big ultrasonic microphone.

Raspberry Pi 4 Model B provided the RAM needed for this build

After the building was declared safely empty of bats, Tegwyn decided to keep hold of the expensive microphone (the metal tube in the image above) and have a crack at developing their own auto-classification system to detect which type of bats are about.

How does it work?

The ultrasonic mic picks up the audio data using an STM M0 processor and streams it to Raspberry Pi via USB. Raspberry Pi runs Alsa driver software and uses the bash language to receive the data.

Tegwyn turned to the open-source GTK software to process the audio data

It turns out there are no publicly available audio records of bats, so Tegwyn took to their own back garden and found 6 species to record. And with the help of a few other bat enthusiasts, they cobbled together an audio dataset of 9 of the 17 bat species found in the UK!

Tegwyn’s original post about their project features a 12-step walkthrough, as well as all the code and commands you’ll need to build your own system. And here’s the GitHub repository, where you can check for updates.

18 comments
Jump to the comment form

Avatar

I like the picture of the felt bat from Etsy.

Reply to willmore

Avatar

Wow those mics are expensive. I would consider buying an ultrasonic mic capsule and building a pre-amp and heterodyning circuit so you can have human level audio.

Reply to Anders

Avatar

When I first started experimenting with Bat Detectors nearly 40 years ago, they all worked on the heterodyne principle and effectively used the back end of a simple transistor radio with the mixer fed with a local oscillator that produced the 470 kHz needed for the IF Strip. The resulting output was in the audio range. At the time I had a Sinclair ZX81 and I wanted to use a digital method to down convert the ultrasonic signals from the bats so that I could both hear them and (eventually) display them on the screen.
Sadly, obtaining a working ultrasonic microphone defeated me. They cost about the same as they do now, (but wages were lower then) and all my efforts to construct one failed because of the high voltage needed for the condenser mic.
On the plus side, my description of my design at a job interview got me a career at a company that i remained with until I retired :-)

Reply to Terry Coles

Avatar

Ordinary, electrets and MEMs mics, although their specification is human ear audio requencies, do have a response up to and beyond 100kHz. They may miss some of the top end noises but do work well if you pre-amp them and filter out the lower frequencies. MEMS have lower noise. For some bats species, even a piezo can be used, though not great.

Reply to Anders

Avatar

Have you tried electronic goldmine online. they have many products and ultrasonic mic’s, might be what you are looking for make your own setup. OR you can get a microphone kit and convert it to work . I use a mic amp kit in stereo like just for a hearing aid works great and much stronger than a regular one, could be modified for your needs. (MK136) Ultrasonic mic thru Electronic Goldmine.

Reply to Richard M Buck

Avatar

I also buit this unit but did not buy one of the these expensive USB microphones. It seems to be quite hard to find and USB microphone/codec that is this quick. Maube you could use an analog input to sample the sounds. I used an spu0410lr5h element and an ALC4040 which is capable of 192khz sample rate that worked quite nice. You need to add some amplification, I used the same circuit as in my Teensy Bat detector and was quite pleased with the results.

Reply to Edwin

Avatar

Is there a datasheet for the ALC4040 online? What I read says it has a 192kHz DAC but only 96kHz ADC, if so you could not record frequencies higher than 48 kHz without aliasing.

Reply to JBeale

Avatar

I am using some from a Manao USB microphone and some small 3.5mm (4pin) to USB C adapters these Both use ALC4040 and allow 192khz sampling rate. They work fine on the ultrasonic classifier (change settings to 192khz rate) . In Windows you also need to set the sound properties for the microphone. Ubuntu or raspbian seems to be starter when using Audacity.

Reply to Edwin

Avatar

I don’t have first hand experience of these but I have heard they will do the job reasonably enough once fed through a pre amp. The price tag is much more user friendly than any other ultrasonic range mic I’ve found.

Reply to Philip McGladdery

Avatar

your link shows a simple electromagnetic (inductive) coil pickup. It is not a microphone at all, despite the listing’s title. Well, it might be slightly microphonic in extremely intense sound fields, in the same way something not designed to be a bell may still ring a little if you hit it hard enough.

Reply to JBeale

Avatar

Just a little extra note about the microphone. It looks like you are paying a lot for an ultrasonic microphone, but you have to keep in mind that it needs to be sensitive for ultrasonic frequencies, low noise and also the sample rate needs to be high and the sensitivity needs to be about the same over a 20-100+ kHz range. The standard sample rate for audio usually is 44.1kHz which is enough to record sounds up to only 22kHz. Bats can can make sounds up to like 130kHz and you would need double the sample rate to see the whole call. Sample rates at 260kHz or higher require more than a simple soundcard input.
The microphone element is not the expensive but the fast ADC circuit and extremely low noise amplifiers add to the price. The suggested microphone has extra features that make it suitable for stand alone recording (if im not mistaken) anyway, this stuff just is expensive.
If you want to record bats you need a microphone element that has a good response over the whole frequency range. This excludes the cheap 40kHz ultrasonic transducers, these work fine for detecting bats but one can not determine the species since it works bad with frequencies that are not near 40kHz. Knowles makes a tiny electret element which is widely used. Known as the FG element, these are tiny I suggest you buy a leaded version like FG-23629-P16 otherwise use a MEMS like the SPU0410LR5H-QB or as some people suggested an ICS-40720 but the latter seems to have a “gap” in the reception around 70kHz.
Using a good microphone element does not get you anywhere unless you have a fast analog digital converter. The ALC4040 has a reasonably high sample rate but it would be better is you could sample at at least 250kHz. The ALC4040 can be found in small USB audio converters for less than 10 usd, so I guess that is i nice starting point. There are not many bats that call over 96kHz so this is why I settled for the ALC4040 and SPU microphone with a low noise amplifier.
The advantage of the FG microphone is that is can withstand some moisture, an there are leaded versions available. It is more expensive as the MEMS elements and needs more amplification. The ICS element is tiny but can be hand soldered, comes with no leads and has low sensitivity in a part of the band. The SPU element is even smaller as the ICS and you probably need to look for one on a breakout board. It is a bit more sensitive on 23khz but seems to have reasonably flat response.
I hope this helps you understand why ultrasonic microphones are expensive and why it is hard to build one that enables digital recording.

Reply to Edwin

Avatar

There are numerous off the shelf devices that convert bat noise down to human audio range, and are a fraction of the price of that mic alone. It’s a nice mic, but a bit of a luxury.
Heterodying analogue is the trick that has been used for many decades to bring high frequencies down in the the reach of cheaper components.

Reply to Anders

Avatar

Interesting I have the parts and I want to build it. How much RAM do you need for it? I have 1GB RAM model
will it work?

Reply to Arya

Avatar

I was told by the creator (Tegwyn) you need at least 4gb of ram.

Reply to Edwin

Avatar
Avatar

I have just been playing with the cheap ALC4040 usbc adapter cables, windows does recognize a maximum sample rate of 192000hz, unfortunately this does not work, maybe there is a fake chip in the these cables or there is some configuration fault. The Board that I use from a Manao microphone works perfectly well records on 192kHz sample rate. I will also try a Ugreen cable soon. It seems not every ALC4040 works as microphone codec up to 192Khz.

Reply to Edwin

Avatar

It would have been nice to be able to edit the older post unfortunately I have to write a new comment. I just tested a Ugreen USB to headset adapter. Like the Maono this Ugreen also works fine with 192khz samplerate. Apperantly only the cheap Chinese USB-C adapter cables come with funny ALC4040 chips (only tried similar units from two sellers) .
Both the Ugreen and Maono adapters together with a ultrasonic mens or electret element and amplifier work well enough for many bat species. Do not forget to change the microphone properties in the program.

Reply to Edwin Houwertjes

Leave a Comment