Recording the Elusive Courtship Song of Fruit Flies

Birgit Brüggemeier, University of Oxford

"NI hardware and software is modular, scalable, and infinitely flexible, making it the ideal platform for standardising collaborative research."

- Birgit Brüggemeier, University of Oxford

The Challenge:

Building a device to control the local environment of fruit flies and reliably record their courtship songs, which can be difficult because of low volume and varied environmental factors like temperature, light, and humidity levels.

The Solution:

Using LabVIEW software and CompactDAQ hardware to develop a sensory device called the Song Box, control environmental conditions within the Song Box, and interface with a particle-velocity microphone to record the mysterious fruit fly courtship song.


Birgit Brüggemeier - University of Oxford
Keiran Foster - University of Oxford
Mark Jones - University of Oxford


Introducing the Song Box

Drosophila melanogaster, more generally known as common fruit fly or vinegar fly, are yellow-brown flies, with brick-red eyes and black rings across the abdomen. Fruit flies are significant to science, as they were among the first organisms used for genetic analysis. Fruit flies became one of the most prominent “model organisms” because they exhibit many favourable biological characteristics, such as quick breeding, high fecundity (females lay up to 100 eggs per day), and other complex behaviours (for example, flight, courtship, and aggression). Scientists continue to use fruit flies for biological research in studies of genetics, physiology, behaviour, and evolution.


Male fruit flies display a complex mating ritual to females, which includes unilateral wing extension and wing vibration, to produce a species-specific courtship song. To capture the subtle changes in this elusive song, we designed a controlled, noise-insulated environmental chamber we called the Song Box.


When singing, flies are sensitive to environmental factors such as light, temperature, and humidity. As such, aside from integrating a highly accurate particle velocity microphone and humidity sensors, the Song Box also includes resistance temperature detectors (RTDs), thermoelectric cooling modules, and a ventilator to control environmental temperature. Additionally, we can use an array of white, green, and red LEDs to vary illumination levels within the chamber.


Controlling the Song Box

For our research to be successful, the sensing and control of the Song Box required accuracy, repeatability, and reliability. Many scripting languages could provide a solution when encoded onto an FPGA. However, most academic engineering projects use custom-designed equipment, which requires tailored control software. This considerably increases time and manufacturing costs with no commercial gain. Fortunately, we took advantage of the versatility of the NI platform to save time and money in manufacturing Song Box. We used a cDAQ-9174 chassis and the appropriate I/O modules to communicate from the PC to the outside world efficiently and reliably.


The extremely low volume of the courtship song required a high-quality sound recording, as well as background and electrical noise insulation. This resulted in significant challenges during the development of the Song Box, particularly in temperature control. Our Peltier (thermoelectric cooling module) required a ventilator to prevent overheating. The ventilator generated considerable noise, making song recording impossible. We addressed this problem with a flexible software solution based on LabVIEW. Our solution alters the temperature to a desired level before automatically shutting down the Peltiers. Conversely, the LabVIEW application would pause the experiments when the environmental temperature exceeded a desired threshold, to re-energise the Peltier. By taking a software-defined approach to developing the Song Box, we could quickly revise our system when we encountered unpredicted hurdles.


Communication with Song Box runs five separate tasks in parallel. Using the cDAQ-9174 as a backplane, we identified three plug-in modules suitable to tackle each, alongside a PCIe-8253 interface for camera acquisition, so we could correlate the sound recording with a video feed of the courtship ritual. The NI Vision Acquisition Software delivered a clean image, formatted to a specified codec in AVI format, which common media players recognise.


We used the CompactDAQ platform for environmental control and sound recording. For programming and memory usage efficiency, we used an event structure to trigger each command, and each module utilised the DAQ Assistant Express VI for ease of programming, within a producer/consumer loop structure to ensure no loss of data when streamed in real time. The NI 9401 module sends binary TTL signals to the LEDs and the Peltiers to control light and temperature.


The NI 9205 analogue input module’s 16-bit resolution and 250 kS/s sampling rate were ideal for digitizing the courtship song. We also used the same module to capture the humidity signal, which was then processed with LabVIEW using a formula provided by the sensor’s manufacturer to give accurate, scaled readings. Both signals streamed to a TDMS file for off-line analysis. At the end of an experiment, the TDMS file automatically parses through a LabVIEW algorithm, which produces a WAV file, again, recognised by common media players.


The NI 9217 monitors the RTD temperature sensors. The NI 9217 simplifies the sensor integration process, automatically detecting the type of RTD (3- or 4-wire) connected to it and then providing the required excitation current. The acquired temperature data passes to the Peltier control loops in our LabVIEW application, and again is saved to a TDMS file.


These tasks all run concurrently. A multicore machine may process the parallel loops with no slowing or compromise with other Windows priorities; thus, we can rely on the coding to collect an accurate and complete data set. LabVIEW makes programming multithreaded applications incredibly quick and efficient.


In addition, it was clear that we needed a fairly intuitive UI (the front panel) to use because research students with no prior LabVIEW experience or knowledge would eventually handle the code. We achieved an intuitive UI using the highly malleable nature of the LabVIEW controls and data representation objects.



Empowering Research

In research we often design unique engineering solutions to scientific problems, sometimes at the cost of reproducibility, as small deviations can change the result. Good practice in research, however, aims for reproducibility, which we can start to facilitate with reproducible engineering solutions. NI hardware and software is modular, scalable, and infinitely flexible, making it the ideal platform for standardising collaborative research.


In addition, our LabVIEW control software shows an unexpected benefit: the front end is easy and intuitive to use for scientists with no prior LabVIEW experience. When we first introduced the Song Box to other scientists, they were sceptical. They expected a time-consuming learning and set-up experience, as is often the case in science. However, these scientists found it took them less than 10 minutes to understand the control software and start their first experiment.


The Role of the Courtship Song

If I wanted to know your favorite song, I could just ask. It’s as simple as that. But, of course, with flies, it’s a little more complex. When flies hear a song they like, they change their behavior, starting to dance and even sing along – but, only when the song meets a species-specific frequency, rhythm and amplitude structure. If a song does not adhere to this strict criteria, it is no more attractive than silence.


To further our understanding of the drosophila melanogaster, one of science’s most significant model organisms, we required a high-fidelity recording of its unique courtship song, which we could playback to the flies as part of our on-going research. This is what led us to developing a unique sensory and environmental chamber; the SongBox.


Ultimately, the LabVIEW-powered SongBox captured the elusive courtship song, which allowed us to discover how volume variations not only signal species type, but are also used by female flies to select appropriate mates. This suggests an evolutionary role of volume changes in courtship song, which may inspire future research in other animals, such as birds and mammals, which also court and vocalise with variable volume.


You can read more on the findings in fruit fly song on


Author Information:

Birgit Brüggemeier
University of Oxford
Centre for Neural Circuits and Behaviour, Tinsley Building, Mansfield Road
Oxford OX1 3SR
United Kingdom

Figure 1. Drosophila melanogaster, more commonly known as the fruit fly
Figure 3. LabVIEW front panel of Song Box showing courting flies on top of an extremely sensitive microphone that records their songs. In addition, the user can control light, humidity, and temperature with the front panel.