Help me efficiently count the heartbeats of shorebirds
December 3, 2015 8:18 AM   Subscribe

I'm in search of some kind of BPM-detecting software to monitor recorded heartbeats of adorable American Oystercatchers over roughly 30-minute intervals. Medical software experts and DJs welcome!

I'm assisting some behavioral research on beach-nesting shorebirds, and basically need some software (ideally free, but willing to cough up some money) that can detect and average the animal's heartbeat across periods of time. The research compares heartbeats under induced stress and a control period, so we know that the heart rate will be pretty dynamic during these time periods. These aren't studio quality recording since they were recorded in the field; is there BPM-detecting software that is geared towards live recordings that aren't crisp and perfect tempo?

I know the easy thing to do would be to tap along to the heartbeat, or to get a visualization and count the number of beats, but we are talking about A LOT of audio data here, literally week's worth of data. If there is a way to expedite this, I'm all for it.

Thanks so much in advance!
posted by Drosera to Technology (12 answers total) 2 users marked this as a favorite
 
Can you clarify how these recordings were made? Are they audio recordings that were made with some sort of parabolic microphone or something? It sounds like the heartbeat is audible to the human ear when you listen to the recordings, is that correct? Is there also a lot of ambient sound -- wind, human speech, etc -- that is louder than the heartbeats?
posted by alms at 9:08 AM on December 3, 2015


Can you post a short sample?
posted by gregr at 10:04 AM on December 3, 2015


Are you familiar with the ECOLOG-L listserv? I bet you'd get some good expert advice there.
posted by momus_window at 11:42 AM on December 3, 2015


Response by poster: Thanks all - the recording were made with a microphone inside of a decoy egg that the bird sat on while incubating its nest. So yes, wind is definitely a factor. The heartbeats are audible to human ears but can be drowned out if the wind is high enough. I'm sorry to say that I don't have a sample (the files are 72 hours long, and I couldn't render a sample before I got off work today).
posted by Drosera at 12:25 PM on December 3, 2015


Presumably there are there other noises on the tapes (besides wind and heartbeats) as well-- feet kicking up straw or pebbles, clucking and so forth. How much variation is there from tape to tape? What I mean is: if you designed a good collection of filters to work on one tape would it also clean up another tape?

I too would like to hear some examples. If you post them would you let me know?
posted by cleroy at 1:06 PM on December 3, 2015


Heh, the first hit in my search for "acoustic heartbeat" on BioOne turned up a 2014 article in the Condor about what I presume is your project. Let me know if it's not and I'll mail you a copy. There are actually a TON of papers that discuss measuring the cardiac activity of avian embryos.. maybe search around those paper's method sections, or write directly to their authors for advice. You might even consider looking at research that evaluates bird and bat wing beats, etc.

Also, a quick google search for "beats per minute software" brought up multiple options. It would be time-intensive, but perhaps you could break your recordings down into 10 or 20-second "songs" and average them as needed.
posted by scrubjay at 2:37 PM on December 3, 2015 [1 favorite]


Best answer: If you or a collaborator know Python, looks like this GitHub repository has some code for detecting beats per minute in audio files.

You could also try processing the files in Audacity. It looks like there's a crude beat finder tool built in which attempts to label beats based on loudness. You can probably improve your ability to discriminate heartbeats from background noise by first low-pass filtering your files (Audacity has a tool for this) to reduce noise from sources like wind outside the frequency band containing heart beats. If your birds have heart rates in the 200-400 bpm range (just guessing based on what a mammal of similar size would be), then you could try a low pass filter with a cutoff frequency of 500 bpm or about 8.3 Hz (note that the resulting audio will probably be inaudible, but the heart rate data ought to still be in there). If this turns out to be too aggressive you could try raising the cutoff frequency. If there's a lot of very low frequency noise then you could also try a high pass filter with a cutoff at about 1 Hz (in addition to the low pass, for a 1-8 Hz band pass filter).

If this works, it looks like the beat finder generates time labels for each heartbeat which you can export to a text file. You can then load them into R or a similar statistical package for heart rate analysis. Be prepared to censor epochs with missing or garbage data -- if there's enough background noise then no algorithm is going to rescue your data. The tools Audacity offers do look to be pretty crude, and I haven't tried them myself so I can't speak to their effectiveness, but at least it should be relatively easy. If it were my study, I'd probably validate the method by selecting a few random audio subsamples, measuring heart rate by tapping along with the audio, and then comparing my tapping data against the result from processing in Audacity.

Good luck! I'd really like to know whether this ends up working, sounds like a very cool project!
posted by biogeo at 9:37 PM on December 3, 2015


This Stackoverflow question on the subject has a variety of resources and ideas that might be helpful. You'll probably have to do some experimentation with your files to see whether either "beat detection" or "onset detection" will work for your purposes.

It looks to me like you might be able to use one of the Vamp Plugins to find the beats and "tempo" of the beats (ie, the heartrate)--perhaps Aubio or BeatRoot or a few others. You'll likely have to experiment some to find what works best. You could use Sonic Annotator to batch-load audio files, process them with the Vamp Plugin(s) of your choice, and write the results to text or XML files.

If this works, you could probably use a process like this: Break your audio files up into some convenient small units, say 30 seconds. (I believe this can be done automatically by some freely available programs.) Then you use Sonic Annotator to batch process each of these files and the end result is something like a text file listing the beats per minute calculated in each of your 30 second files, or a textfile giving the timestamps of each beat found in the various files.

FYI the Vamp Plugins also work in Audacity, so could combine some of the good ideas mentioned above by biogeo for filtering the sound files in Audacity with the (potentially) much better beat-finding capabilities of the Vamp Plugins.
posted by flug at 10:29 PM on December 3, 2015 [1 favorite]


SoundRuler may help with some of that stuff. Maybe*? At the very least it will help you hand-characterize and extract numbers from sample chunks as a sanity check / validating before you dump characterized and uncharacterized chunks into your automated black box that spits out numbers, as per I'd probably validate the method by selecting a few random audio subsamples, measuring heart rate by tapping along with the audio, and then comparing my tapping data against the result from processing in Audacity.

Apparently it plays nice with others: ... Compilation for various platforms and extension of the .m scripts to free mathematical packages (Octave, Scilab, FreeMat, etc).

Along with audacity for general filtering and massaging.

* I only know it exists because it was on gizmodo yesterday.
posted by sebastienbailard at 3:05 AM on December 4, 2015 [1 favorite]


From a bit of searching, the unix terminal program sox from your OS's package manager does quite a bit of audio swiss army knife stuff, and presumably plays nice with python or bash scripts invoking it. Like imagemagick for images or pdftk for pdfs, I suppose.

The following is an example of multiple effects chains. It will split the input file into multiple files of 30 seconds in length. Each output filename will have unique number in its name as documented in the Output Files section.

sox infile.wav output.wav trim 0 30 : newfile : restart


You can then use sox or other tools to do FFT on the 30 second snippit for the frequency components that would mean wind noise, and then do a low pass filtering, before dumping it into something else doing beat detection?

You can also use python/gnu-octave/sci-lab for much of this stuff, as per scads of online tutorials and dead tree textbooks in your institution's library about signal processing and audio processing, which you can mine for cookbook stuff and example code like "how do I do a low pass filter / FFT / beat detection". They may be helpful depending on how you end up automating stuff or sorting out your toolchain.
posted by sebastienbailard at 1:42 AM on December 5, 2015 [1 favorite]


Response by poster: Thank you for all the great leads, MeFites!

I also finally have a 5-minute audio sample of the heart beats (replete with soothing coastal noise pollution!)
posted by Drosera at 8:19 AM on December 7, 2015


Thanks for the follow-up, that was really cool to listen to! If that's a representative sample, your data are much cleaner than I'd imagined. It should be very tractable to extract heart beat timestamps with automated tools, even relatively simple ones offered by Audacity or Vamp (as flug suggested). You could probably clean it up a bit more and/or automate the analysis process further using more advanced tools (I would do it in Python+SciPy or Matlab/Octave), but that's probably only worth it if you already know how to use them and/or want an excuse to learn them.

My guess is that in most cases, the wind noise is so broadband that when it's loud enough that you can't hear the heartbeats, no amount of filtering will recover the heartbeat data, and the period near the end that sounds like the bird is moving is probably also going to be challenging or impossible to recover heartbeats from. So step 1 is probably coming up with a filter that helps you identify those epochs, or doing it manually (not fun if you've got multiple 72-hour files!), so you can exclude them from analysis. Of course, depending on the nature of the stressors and the birds' behavioral responses to them, your censored epochs could also end up being correlated with your independent variable(s), so you might want to run some stats to make sure you're not biasing your result because of that.

Anyway, very cool, good luck!
posted by biogeo at 10:09 AM on December 8, 2015 [1 favorite]


« Older Leftovers That Don't Feel Like Leftovers   |   Well, I used to be a 0 and now I'm a 6 Newer »
This thread is closed to new comments.