I had some fun doing an experiment on myself today. Way back when I was in grad school I had the pleasure of taking part in the Lionel Hampton Jazz Festival. One of the guests worked with our band and had us keep time in our heads for something like 16 measures. No high hat, no snare, no foot tapping. We were all supposed to clap on the downbeat of the 17th measure. She set the tempo for a couple measures and then we were silent. I was really impressed with how synchronized we were at the end. Today I thought I’d play around with that a little.

Here’s what I did: I recorded myself clapping at a given tempo. I wanted to know just how accurate my claps were. What I mean is, how similar were the gaps between claps?

I used Audacity to record the sounds and then I used *Mathematica* to do the analysis. I know I could have just zoomed in on the Audacity time sequence to get the data but I was wondering how hard it would be to get *Mathematica* to do all the analysis by itself.

Here’s the full time sequence and a zoom in on one of the peaks:

Time sequence of clapping

Then I had to figure out a way for *Mathematica* to determine the time of the claps. This actually took me a while because I wanted to see how little information I could give it (since my eyes were pretty good at seeing where the peaks were – this is something I deal with every year with my students in Modern Lab).

I settled on trying to find those points in the time series where the standard deviation of the neighboring 500 points was the highest. So I calculated a rolling standard deviation:

Rolling standard deviation time series

These peaks proved easier to get *Mathematica* to find. I did that by having it walk through the time series and find the time when the curve went up through 0.1 amplitude. I actually did this using the super awesome EventLocator method in NDSolve that I’ve been playing around with.

Once I got the time of the peaks, I did a linear curve fit to find the average frequency and then I took the average of the fit residuals. What’s amazing is that even though I was only clapping at 30 beats per minute (2 seconds between claps) I was only off on average from the perfect downbeat by 5 milliseconds!

This was a lot of fun and I learned a lot about how to find peaks and about my awesome metronome-like ability. In the future I’d like to figure out the best way to concentrate and minimize the errors. For this test run I sang a little song in my head while clapping and that seems to have worked quite well.

### Like this:

Like Loading...

*Related*

## About Andy "SuperFly" Rundquist

Associate professor of physics at Hamline.

Andy,

Your god-like powers with mathematica never cease to amaze me. But it seems to me like you could use this to do some neat pulse counting stuff. Hook a photocell up to ardruino, then aim a remote at it, and read the IR pulses its sending out. I vaguely remember reading something about studying remote control signals in TPT a while ago…

That does sound like a cool expt, John, thanks. Every year in my Modern Physics course I give students fake data and they’re supposed to be able to analyze it like crazy. With nearly every student I have a conversation that goes like this:

S: I can see what the value of XXX is from the plot.

Me: Ok, so get MMA to determine it

S: But it’s right there (pointing to screen)

Me: Ok, so have MMA find it

S: But it’s so obvious

Me: To you and your awesome eye/brain pattern recognition system, sure. Now teach MMA

What I did in this post is along those lines and, when done well, is highly extendable just like with your suggestion. My biggest problem is that I don’t save things often enough. Quite often I “rediscover” the best way to do things like peak finding etc.

One thing I’ve worked on with my students is to get them to break down what their eye/brain system is doing when they see the “obvious” signal. I ask them to break it down into as many steps as possible and then give me a list with the ones they don’t know how to do in MMA starred. Of course, sometimes they ask if they could just star the ones they do know how to do :)