(Last updated October 2019)
As the Cirrus Logic Audio Card is no longer available, options for recording ultrasound with the Raspberry Pi are unfortunately limited. There is a relatively new sound card available which is specifically designed to record ultrasound with a maximum sample rate of 192kHz: Audio Injector Ultra 2 from Flatmax Studios.
Instructions for setting up this card for use with a Raspberry Pi can be found here.
The card defaults to line input, so a simple bash script is needed to set up recording from the on-board microphones (Knowles SPU0410LR5H Ultrasonic MEMS microphones).
amixer cset name='ADC Mux' 0 amixer cset name='PGA Volume' 40 amixer cset name='ADC HPF Switch' 0 amixer cset name='ADC Soft Ramp Switch' 0 amixer cset name='Loopback Switch' 1
This can be saved as a bash script (e.g. record_from_mic.sh) and set to run at startup by adding the following line to /etc/rc.local just before exit zero (instructions on how to do this are here).
sh /home/pi/record_from_mic.sh &
Here’s the Ultra 2 Sound Card attached to a Raspberry Pi 3A+. I’m only using the base card that comes with the AudioInjector sound card package, with a separate MEMS ultrasound microphone attached:
SoX can be used for sound-activated recording:
rec -G -c1 -r 192000 -b 16 -V2 /home/pi/temp.wav sinc 10k silence 1 0.01 1% -1 1.0 1% trim 2.0 3.0
These are spectrograms of bat calls from recordings made with the Ultra 2 sound card:
Automatic Classification of Bat Calls
Bat calls that have been recorded can be automatically analysed using Chris Scott’s “BatClassify“. The version in the link has been compiled for Windows, but it is possible to re-compile the source code for running on a Raspberry Pi (more information to follow).
Bat sounds can be classified in almost real-time (on a Pi3A+, a 3 second file takes about 40 seconds to analyse), and the result displayed on a small OLED screen.