Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
Clap Tracking for a Robot Drummer
Neil MacMillan
For G. Tzanetakis, CSC 475University of Victorianrqm@uvic.ca
Abstract
This document describes a project involving amodification to the existing robot drummer, allowing it torespond in real time to audio stimulus (hand clapping)without needing external equipment. The stimulusdetection, timing considerations, clap tracking andprediction, and results are all discussed.
1.
 
Introduction
To satisfy the requirements for a past course at UVic, I andtwo other engineering students, Matthew Loisel and DanielPartridge, designed and built a robot drummer that couldstrike a drum in response to Musical Instrument DigitalInterface (MIDI) input. [1] That project was mostlysuccessful, but once it was completed there were still manyways that the robot could be made more useful orinteresting. One problem with the robot is that it is limitedto MIDI input. It can accept commands from any MIDIsource, but it requires such a source
 — 
for example asynthesizer or computer
 — 
to be present. In other words,the robot is not a standalone machine.The robot can be improved by adding capability todrum in direct response to live audio input such as handclapping, instead of requiring some complex external pieceof equipment to translate analog signals to MIDIcommands. It would be even more interesting if the robotcould, when a regular rhythm is being clapped, drum alongwith the rhythm
 — 
not in response to the claps, but byanticipating each clap and striking the drum at the precisemoment of the clap instead of shortly after it.This document will describe the three core tasks that Iundertook for this project:-
 
Designed and built a sensor for detecting a handclap and outputting a digital signal. This turnedout to be the main task.-
 
Measured the delays between a stimulus to therobot drummer and the drum strike.-
 
Modified
the robot’s firmware to accept the clapsensor’s digital signal, and to predict when the
next clap in a simple beat will occur.
2.
 
Clap Detection
The robot must be able to gather input before it canrespond to claps. I looked for an off-the-shelf clap sensor,but could not find one that was cheap and producedappropriate output. I decided to build a clap sensor fromscratch. This involved designing a circuit for the sensorand laying it out as a circuit board, purchasing parts,etching and assembling the circuit board, installing thecomponents, and writing the firmware.Without the clap sensor, there would be two choices forclap detection. If the robot drummer did clap detection,then the signal processing component would add asignificant processing a
nd memory load to the drummer’s
firmware. The sensor offloads this work onto acoprocessor that transforms the analog input into a digitaloutput that is very easy for the drummer to read. Anotherway to do clap detection would be with a computer.Clearly this would undermine one of the points of thisproject, which is to make the robot drummer moreindependent. In addition to that, my experiments showthat sending MIDI commands over USB incurs atransmission delay between 10 and 30 ms. The mainproblem is the delay variance, which is impossible topredict or to correct.
2.1
 
Clap Sensor Circuit Board
10
μ
FATtiny84MicTRSJack 2.2 k 
Ω
1.5 k 
Ω
ISPLED
10 k 
Ω
5 V100
Ω
Output
+
 
Figure 1. Clap sensor circuit diagram.
Permission to make digital or hard copies of all or part of this work forpersonal or classroom use is granted without fee provided that copiesare not made or distributed for profit or commercial advantage and thatcopies bear this notice and the full citation on the first page.© 2009 University of Victoria
 
The clap sensor is a simple circuit to interface anelectret microphone with a microcontroller. [2]Figure 1shows the circuit I used. The symbol at the top representsa tip-ring-sleeve (TRS) jack, which is what the microphoneplugs into. The sleeve is ground, the ring is V+, and the tipis the signal line. The V+ line is connected to powerthrough a resistor, which is what causes the output voltageto vary when the electret is stimulated. In the middle of Figure 1,the six-pin connector is for the in-systemprogrammer (ISP) plug, which is how code is loaded ontothe microcontroller. The ISP plug includes a 10 k 
Ω pull
-
up resistor connected to the ISP’s RESET pin.
The block to the right represents the ATtiny84 microcontroller that Ichose to use (the logical connections to the ATtiny84 inthe diagram above to not match the physical layout of thechip). To the left is the DC power input, which can rangein voltage from 2.7 V to 5.5 V. The robot drummeroutputs 5 V. Beside the power source is a 10
μ
F capacitor,which protects the circuitry from transients in the powersource. Th
e LED is simply a visual output. The LED’s
current-limiting resistor value depends on the LED; theLED that I used needed
a 1.5 kΩ r 
esistor to provide its
rated current at 3.3 V. It should be 2.5 kΩ for 5 V, but
going above the rated current is safe as long as the LEDdoes not spend much time turned on. At the bottom of Figure 1is the digital output that the robot drummer reads,protected by a small current-limiting resistance.
Figure 2. Clap sensor circuit board layout.
In order to route traces properly, I had to put part of thecircuit on the bottom of the board.Figure 2shows the finalcircuit board layout for the top layer (left) and the bottomlayer (right).I used a toner transfer method to print the layout to acopper-clad PCB, and etched it with sodium persulfate(one can find many printing and etching instructions on theInternet). The top layer inFigure 2is mirroredhorizontally from the actual circuit to compensate for thetoner transfer. The wide 1 mm traces are power lines (V+and ground), and the narrow 0.5 mm traces are signal lines.
The circuit board’s through
-holes were difficult tohandle. I drilled them out with two different drill bits, a#60 (1.016 mm) bit for the large holes and a #69 (0.742mm) bit for the small holes. I carved out the TRS jack pins
 — 
which are very wide and thin
 — 
with the small drillbit.It was impossible to solder the top-layer traces for holeslocated underneath the TRS jack and the ISP header. Isolved this problem by drilling extra via holes next to thethrough holes, connecting the top copper to metal posts inthe vias, and then connecting the component leads to theposts on the bottom of the board, after the componentswere installed. This problem could be solved bypurchasing the boards from a professional manufacturer.The manufacturer would be able to tin inside the throughholes, which would make it very easy to solder all of thecomponents from the bottom of the board.The small holes inFigure 2,on the right side of the toplayer, correspond from top to bottom to the capacitor, the
LED, and the three resistors (1.5 kΩ, 100 Ω, and 2.2 kΩ).
The small holes on the microcontroller interface are vias toconnect the bottom layer traces to the top layer. The threelarge holes on the outer edge of the top layer correspondfrom top to bottom to V+, ground, and the output. Thelarge holes in the middle of the top and bottom layers arefor the six ISP header pins.Figure 3shows the finished clap sensor. As of thiswriting, there is still a bug in the microphone jack thatcauses the mic signal pin to stay at around 0.3 V.One problem with the circuit board layout is the pull-upresistor that drives the ISP RESET pin high. InFigure 3one can see that I added the resistor after creating thecircuit board. I have not found a way to integrate a full-sized resistor naturally into the board. A surface-mountresistor, which is much smaller than the ½ Watt axialresistor that I used, would fit easily next to the ISP port butit would make the sensor more difficult to assemble.
Figure 3. Finished clap sensor.
2.2
 
Board Cost
If the board went into large-scale production, the followingcosts would be involved (prices are as of December 112009, per unit at the 1000-unit price break, fromhttp://www.digikey.ca):
 
Table 1. Sensor component prices.
Component Part Number Price (CAD$)
CPU ATTINY84-20SSU 2.03730TRS jack SJ1-3533N 0.34158
10kΩ Res.
CFR-50JB-10K 0.01532
2.2kΩ Res.
CFR-50JB-2K2 0.01532
1.5kΩ Res.
CFR-50JB-1K5 0.01532
100Ω Res.
CFR-50JB-100R 0.01532Capacitor ECE-A1CKS100 0.03739LED* LTW-420D7 0.237471-Row Hdr 4-102972-0 0.09853**2-Row Hdr 4-103783-0 0.14689**
 
*
This LED is different from the one I used; it will use a 100Ω
current-limiting resistor, and it will be cheaper than the low-current LED I used.** The headers are packaged in lengths of 40 rows. The price listed is theprice of the three positions used for the circuit board.
I used a free software package from ExpressPCB to designthe circuit board. The company that makes ExpressPCBwill manufacture boards designed with their software. Thesoftwar
e’
s price estimator gives an estimate of US$1638.39 to manufacture 1000 circuit boards, which asof this writing works out to CAD$1.74 per board. Thatbrings the total material cost to $4.70 for a single sensor ina batch of 1000 units, not including the cost of themicrophone. [3]
2.3
 
Clap Detection
2.3.1
 
 Microphone Ouptut 
For my experiments I used a PC electret microphone.Such microphones have amplifiers built in, so that theyproduce a usable signal without having externalamplification.
1
[2] Small, unamplified microphones willnot work with the clap sensor. Microphones other than theone I used might amplify differently, which would changethe values that I give in this document.
Figure 4. Low pitch clap waveform.
1
Mics with amplifiers typically have three conductors (power,ground, and signal). Mics without amplifiers have twoconductors (ground and signal) or four conductors whenintegrated with earphones (ground, signal, left earphone, rightearphone). Mics made for the iPod do not have amplifiers.
The microphone output signal is idle at about 95% of the input voltage. If the microphone is being powered by 5V, the output will be idle at around 4.75 V. When themicrophone reads sound, the output will oscillate aroundthe idle level, peaking at the 5 V maximum and dipping to
about 3.5 V. The sensor’s CPU can read this signal using
its analog-digital converter (ADC) module.Figure 4shows the output of the microphone when itdetects a low pitch clap (e.g. a deep, palm-to-palm clap).The horizontal scale is time, and the vertical scale is signalvoltage. By visual inspection, one can see that the signalhas a period of a little under 2 ms, which corresponds to afrequency of a little more than 500 Hz. A spectrumanalysis performed using Audacity confirms that most of the information in a low pitch clap is contained between500 and 600 Hz.The waveform for a high pitch clap (e.g. a sharp,finger-to-palm clap) is shown inFigure 5.It has a shorterspike in energy than the low pitch clap, and is at a higherfrequency, but otherwise it is similar to the low pitch clap.
A spectrum analysis shows that most of the clap’s
information is stored between 3 kHz and 6 kHz.
Figure 5. High pitch clap waveform
2.3.2
 
Signal Analysis
As shown by Repp [4], the frequency spectra of hand clapsare not very useful for clap detection; the spectrumfeatures are not distinct. Fortunately, asFigure 4andFigure 5show, the time-domain characteristics of clapsounds are quite distinct. Furthermore, it is much easierfor a general microcontroller like the ATtiny84 to analyzethe time domain characteristics than for it to analyze thefrequency domain characteristics. The frequency domainwould have to be calculated with a Fourier transform,which is impractical to do in firmware because it takes aconsiderable amount of calculation time and memory.The clap waveforms suggest a heuristic for detecting aclap: look for a
―strong enough‖
spike in signal energy thatlasts for between 1 and 4 ms. If the signal is too weak,then it is not a clap. Likewise, if the spike in the signal
takes too long to settle or settles too quickly, it’s not a clap.
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more