Software - DD4WH/Teensy-Bat-Detector GitHub Wiki
How to setup the software
- Install Arduino
- Install Teensyduino beta3 / also installs USB driver for the Teensy 3.6
- copy library uSDFS into Arduino folder
- open Arduino software
- open .ino-file containing the Bat Detector script
- Tools --> Board: Teensy 3.6 USB type: Serial CPU speed: 180MHz Programmer: AVR ISP
- upload
- Bat Detector starts scanning!
How does the software work?
The MIC delivers the audio to the MIC input of the audio shield. The codec SGTL5000 digitizes the audio with a user-settable sample rate and gives the samples through the I2S lines to the Teensy 3.6 microprocessor. The software running on the Teensy 3.6 uses several software libraries, including the audio library by Paul Stoffregen. The latter implements multiple predefined audio objects that can be used and set by the user. This is a semi-graphical representation of the audio chain flow inside the software (the names of the objects correspond to those on the software):
The audio samples enter the microprocessor via the i2s_in object. Each audio block consists of 128 16-bit samples. The audio passes mix1, which is not a mixer in the strict sense, but simply switches the audio coming from either the MIC itself or the player, which can play audio from files on the SD card.
The core elements of the heterodyne function are sine1, a local oscillator which produces the user-defined sine frequency in order to detect a bat calling at that frequency, and the multiplier mult1, which multiplies the incoming frequencies in the audio with the local oscillator. The desired result is the difference frequency between the MIC input and the local oscillator sine1. (Of course, if the local oscillator frequency is low and in the audible range, you will also hear the local oscillator frequency itself AND the sum frequency of the incoming audio and the local oscillator frequency).
The object myFFT is a Fast Fourier Transform (FFT) which transforms the audio from the time domain into the frequency domain. That enables us to display a frequency spectrum of the ultrasound audio coming from the microphone. The spectrum display and the waterfall spectrogram display are both based on this FFT object. Currently it is implemented as a 256-point FFT on 16-bit integer values.
The recorder object is responsible for delivering the audio samples for recording. The audio library takes care of queueing the audio, i.e. it delivers the samples in the right frequency and puts them into a queue. In the software, when in REC mode, a block of 128 audio samples is taken from the queue, copied into a buffer variable, the queue is emptied and the next block is taken from the queue until the buffer is filled. When that is finished, the audio samples from this large buffer are written to the SD card as a RAW audio file. At the moment, the library uSDFS is used for this purpose.