Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Study of Directivity and Sensitivity Of A Clap Only

On-Off Switch

Ajaykumar Maurya Sarath M


Dept. Of Electrical Engineering Dept. Of Electrical Engineering
IIT Bombay IIT Bombay

Abstract—Clap clap switches find applications in domains B. Basic Design Elements


such as automation and security. A clap sound can be used
as a triggering signal either to switch the relays on/off, or as The clap activated switching device can basically be de-
alert signal for some Security System. However the sound is very scribed as a low frequency sound pulse activated switch that is
directive and sensitive to noise floor. Also,being an impulse,it is free from false triggering. The input component is a transducer
difficult to distinguish between a clap and a similar impulsive that receives clap sound as input and converts it to electrical
sounds like bang,dog-barking, coughing,etc. Our report presents pulse.The transducer (microphone) is connected to an amplifier
an efficient way to design omni-directional device for detecting sub-circuit which is then fed to Tiva TM4C module.
clap from a distance and be able to distinguish it will other
impulsive sounds using time and frequency domain analysis. 1) The Sensor(Microphone): Microphones converts acous-
tic energy i.e. sound signal into an electrical signals. Basically,
Keywords—Impulse,Correlation,Sampling,Threshold,Directivity, a microphone is made up of a diaphragm, which is a thin piece
Sensitivity
of material that vibrates when it is struck by sound wave. This
causes other components in the microphone to vibrate leading
I. I NTRODUCTION to variations in some electrical quantities thereby causing
electrical current to be generated. The current generated in
The basic motivation of the project was to develop a the microphone is the electrical pulse.
product which will make a person’s life simpler, say to turn ON
a particular device or an appliance, rather than the customary There are two major types of microphones based on
practice of switching ON the device explicitly, a simple ’clap’ the technical methods of converting sound into electricity
would suffice, thereby reducing the human effort. In case of namely the dynamic and condenser microphone. Condenser
emergency, a clap switch can be used an emergency alert microphones generally have flatter frequency responses than
device. dynamic, and therefore mean that a condenser microphone is
more desirable if accurate sound is a prime consideration as
A. Block Diagram required in this design. And hence, we have also preferred the
same in the form of electret microphone.
Clapping generates sound waves. A sensors which converts
these sound waves into electrical signal is desired to detect Figure 2. shows the basic circuit diagram for an electret
the occurrence of sound event. Hence a microphone is used microphone. An electret is a thin, Teflon-like material with
to sense audio signal whose output voltage level typically is a fixed charge bonded to its surface. The electret is housed
of the order of few millivolts depending upon the loudness of between two electrodes, and the structure forms a capacitor
sound and distance of source from the microphone. The block which contains a fixed charge. Air pressure variations (sound
diagram of the circuit designed for the project is shown in waves) move one of the electrodes of the capacitor back and
Figure 1. forth, changing the distance between the two electrodes, and
modulating the capacitance of the structure. Because the charge
on the microphone is fixed, varying the capacitance causes the
voltage on the capacitor to also change, satisfying the equation:
Q = CV (1)

where Q is charge, C is capacitance, and V is voltage.


Therefore the microphone capacitor acts as an accoupled
voltage source. Because the charge on the microphone capac-
Fig. 1: Simplified Block Diagram itor must be fixed, the amplifier circuitry directly in contact
with it must have extremely high input impedance. Most
electret microphones have an internal JFET which buffers the
It consists of an op-amp based amplifier circuit, sufficient microphone capacitor. The voltage signal produced by sound
enough to amplify the electrical signals generated by micro- modulates the gate voltage of the JFET, labeled VG in Figure
phone. This amplified signal is then fed to the Tiva TM4C129 2 causing a change in the current flowing between the drain
module, wherein we perform some signal processing to distin- and source of the JFET (IMIC). An extremely high resistance,
guish clap signals from other randomly occurring signals. RG, may be included to bias the gate of the JFET.
Fig. 4: Basic Amplifier Circuit

Fig. 2: Electret Microphone Circuit


flash memory. Since our idea was to perform certain signal
processing on the samples of the external signals and distin-
guish it from the desired clap signal, both time domain and
frequency domain analysis had to be performed. Tiva TM4C
module has 12 bit precision ADC with a maximum sampling
rate of 1 million samples per second. Also these, samples so
generated can be directly processed in frequency domain using
fast fourier transform. Thereby making the processing much
simpler.

II. D ESIGN F LOW


The electrical signals so generated from microphone are
only of the order of millivolts, and hence an amplification
stage is required. A non-inverting amplification stage using
op-amp was hence designed initially with a variable gain and
then the gain was fixed at 100 after observing the output wave
forms. This stage was followed by a comparator circuit, which
Fig. 3: Clap Waveform At figure 2 output basically compares the amplified signal level with a predefined
threshold which is depicted in figure 3.

2) Amplifier Stage: Operational amplifiers can be used in


two basic configurations to create amplifier circuits. One is
the inverting amplifier where the output is the inverse or 180
out of phase with the input, and the other is the non-inverting
amplifier where the output is in the same sense or in phase
with the input. The gain of the non-inverting amplifier circuit
can be determined by the using the fact that the voltage at both
inputs is the same. This arises from the fact that the gain of
the amplifier is exceedingly high. If the output of the circuit
remains within the supply rails of the amplifier, then the output
voltage divided by the gain means that there is virtually no
difference between the two inputs.And hence the gain is given
by
Fig. 5: Amplifier and Stage
R2
Vout = 1 + Vin (2)
R1 However, since our aim was to separate ”clap” signals from
almost all other signals, comparator stage is unnecessary and
hence we removed the comparator stage. Now, from literature
3) Tiva TM4C Module: One of the prime requirement of survey, it was found that clap signal had a frequency range
our project was the huge amount of samples that we needed ranging approximately from 2kHz to 3kHz, hence we designed
to store on the micro-controller, and hence Tiva TM4C was a high quality factor band pass filter so as to notch out other
chosen as it has 256 KB of data memory and 1 MB of undesired frequencies.
Fig. 6: A high Q band pass filter

For the figure 5. the transfer function is given by, Fig. 7: Clap Detector-Hardware

Vo sCR
= 2 2 2
(3)
Vi 1 + s C R + sCR(2 − K) A. Time Domain Analysis

where, K is given by, The continuous time analog time domain signal from the
amplifier circuit was fed to the analog read pin of Tiva TM4C
R4 module. The clap signals correspond to a frequency range of
K= (4)
R5 2kHz to 3kHz, and hence the signals were sampled at a rate
of 10k samples per second, satisfying the Nyquist criteria. Ini-
And bandwidth is given by, tially training sequences were generated by repeatedly clapping
predefined number of times. The training sequence so obtained
fH − fL = (2 − K) (5) was recorded and analyzed for its time domain specification.
These specifications along with each signals is pre-loaded as a
However, desired result was not obtained even after the training data in the Tiva module. For our application we have
amplified analog signal was filtered using high Q band pass chosen the training data to be 10. Once the training data is
filter as undesired signals like desk banging etc where not loaded, the real time testing data is fed to the analog pin of
getting properly filtered. Hence, we resorted to process the Tiva. The sample rate (approx. 10K samples) and the number
signals on Tiva TM4C board and analyze the samples. of samples (128) is kept same so as to correlate the data
without zero padding.Time domain correlation is done using
III. H ARDWARE I MPLEMENTATION Pearson’s formula.

The clap-detector circuit was implemented on on a general X X X


purpose PCB as shown in figure 7. We have 4 LED’s indicating numerator = X1 ∗ X2 − X1 ∗ X2 (6)
the confidence levels of clap detection. The Tiva TM4C is qX
programmed such that the when the real time samples passes X X
denominator1 = X1 ∗ X1 − X1 ∗ X1 (7)
each thresholds both frequency domain as well as time domain,
the LED’s indicating the confidence levels blinks in sequence. qX X X
Also another LED has been set up to indicate the detection of denominator2 = X2 ∗ X2 − X2 ∗ X2 (8)
signals other than clap signals. numerator
r= (9)
denominator1 ∗ denominator2
IV. S IGNAL P ROCESSING
where X1 and X2 are the sample Vector to be correlated.
The signals from different possible sources are sampled The maximum output of ADC of Tiva TM4C is 4095. Also
using ADC in Tiva TM4C with appropriate sampling rate. The the maximum number to which a float is defined in Tiva is
samples were analyzed in both time domain and frequency 4e9. By using Pearson’s formula the summation term was
domain.In time-domain the captured samples were cross- crossing the maximum limit of a float thereby giving false
correlated with a pre-loaded training sequence. Initial training reading for the same. Thus an optimal number of points was
is necessary as claps can be different for different person. In required to choose so as to get time time correlation as well
frequency domain Fast Fourier Transform(FFT) was performed as frequency resolution in frequency domain as per required.
on the samples so as the distinguish different frequencies. Hence 128 sample points were chosen where in the maximum
Appropriate results were displayed to distinguish the clap from limit the summation term can reach is 2.2e9 and the frequency
other sounds. resolution is 144Hz which is acceptable for our application.
B. Frequency Domain Analysis
The sampled real time signal is processed using 128 point
DFT in frequency domain to detect the presence of frequencies
between 2khz to 3 khz. The resolution for 128 point DFT
is about 144 Hz. Also the amplitude for the corresponding
frequencies plays a very important role as high amplitude may
lead to false triggering. Higher point DFT can also be done
as it will increase the resolution but on the cost of process
time. We went for for 128 point DFT as higher points couldn’t
be processed on Tiva TM4C because of range limitation of
floating point numbers.

V. A LGORITHM
Initially, the clap signals are amplified by a non-inverting
amplifier of sufficient gain. This amplified signal is fed to the
Tiva TM4C. Tiva is programmed to sample the analog input
at the rate of approx. 10k samples per second. These samples
so obtained are analyses in frequency-domain as well as time-
domain. Initial analysis is done in frequency domain, were
we filter out the incoming signals which do not fall in the
range of clap-signals. This is done by specifying appropriate
thresholds for the amplitudes in the frequency domain during
the training process. Once we have filtered out all the signals
which are out of band of the clap frequencies, we switch to
time-domain analysis. In time domain we correlate the real
time samples with the pre-loaded training sequence. After
computing the correlation co-efficient, appropriate threshold is
specified on the value of correlation coefficient so obtained
during the training process. If the value of correlation co-
efficient is greater than the threshold then we say that a clap
is detected. Figure 8 depicts the flow chart of the algorithm
that we have implemented.

VI. A NALYSIS AND I NTERPRETATION


Initially the system was trained with ”five” claps at both
near and far. By ”near clap”, we mean a clap at an approximate
distance of 30cm, and by ”far clap” we mean a clap at a
distance of 2-3m. These signals were sampled on Tiva TM4C
and analyzed in Matlab. After repeating the experiments a
number of times, the thresholds for both time-domain and
frequency domain were set. Also these samples were preloaded
into the Tiva TM4C for correlating it with the real time signals.
Figures 8 to 25 and 12 to 29 depicts the training signals
along with their FFT’s processed in Matlab after extracting
the samples using . As can be seen from the training data, a
majority of the freT ivaT M 4Cquencies for the clap signals,
both near and far clap falls in the frequency range of 2-
3kHz.Accordingly we chosen the lower cutoff frequency to Fig. 8: Flow-Chart
be 2.016 kHz and the upper cutoff frequency to be 3.016
kHz. The frequency domain plots were processed with a
resolution of about 144.06 Hz as there was a computational
limitation associated with the floating point numbers while
loading the program onto the Tiva TM4C. Similarly after
analyzing multiple data sets and correlating it with the pre-
loaded training sequence using equation 9, a threshold of
0.15 was set on the value for correlation coefficient for clap
detection.
Fig. 9: Far 1 Waveform Fig. 13: Far 1 Frequency Response

Fig. 10: Far 2 Waveform Fig. 14: Far 2 Frequency Response

Fig. 11: Far 3 Waveform Fig. 15: Far 3 Frequency Response

Fig. 12: Far 4 Waveform Fig. 16: Far 4 Frequency Response


Fig. 17: Far 5 Waveform Fig. 21: Far 5 Frequency Response

Fig. 18: Near 1 Waveform Fig. 22: Near 1 Frequency Response

Fig. 19: Near 2 Waveform Fig. 23: Near 2 Frequency Response

Fig. 20: Near 3 Waveform Fig. 24: Near 3 Frequency Response


Fig. 25: Near 4 Waveform Fig. 29: Near 4 Frequency Response

Fig. 26: Near 5 Waveform Fig. 30: Near 5 Frequency Response

Fig. 27: Test 1 Waveform Fig. 31: Test 1 Frequecy Response

Fig. 28: Test 2 Waveform Fig. 32: Test 2 Frequency Response


Fig. 33: Test 3 Waveform Fig. 37: Test 3 Frequency Response

Fig. 34: Test 4 Waveform Fig. 38: Test 4 Frequency Response

Fig. 35: Test 5 Waveform Fig. 39: Test 5 Frequency Response

Fig. 36: Test 6 Waveform Fig. 40: Test 6 Frequency Response


VII. R ESULTS

Correlation Table
Testing Signals Freq(KHz) Near1 Near2 Near3 Near4 Near5 Far1 Far2 Far3 Far4 Far5
Pen-drop 1.782 -0.035 0.021 -0.042 0.015 -0.154 0.039 0.024 0.013 -0.182 0.115
Click 4.610 -0.029 0.058 0.282 -0.015 0.207 -0.029 0.059 0.0282 -0.015 0.206
Bang 1.440 -0.071 -0.038 -0.022 0.161 -0.084 -0.071 -0.038 -0.020 0.61 -0.084
Whistle 5.042 -0.024 -0.003 -0.064 0.126 0.047 -0.024 -0.003 0.064 0.126 0.047
Clap1 2.881 0.019 0.006 -0.069 0.255 0.010 0.017 0.006 -0.069 0.255 0.010
Clap2 2.305 -0.043 0.221 0.248 -0.027 -0.027 -0.043 0.221 0.248 -0.027 -0.027

The Correlation table shows the correlation co-efficient for


various real time test signals with respect to stored sample.
The frequency for Pen-drop, click bang and whistle were not
in the range hence rejected. For the claps, as the frequency is
within the band, time correlation is done with the store sample.
For clap1, the correlation with near4 and far4 is greater than
the threshold thus it is detected as a clap. Similarly for clap2
near2, near3, far2 and far3 correlation exceeds and get detected
as clap.

VIII. C ONCLUSION A ND F UTURE W ORK


We have successfully designed and implemented an effi-
cient clap only detector. The system is highly sensitive and
omni-directional. Testing the system showed 80% accuracy(40
out of 50 claps were detected) for a maximum distance of
4 meters. Out of remaining 20%, 12% were false negative
and 8% were false positive. Overall this system is much more
efficient compared to other existing counterparts. Future work
includes more regressive training of the system using other
efficient algorithms.

ACKNOWLEDGMENT
We would like to thank Prof. Siddharth Tallur for constantly
helping and motivating us constantly in completion of the
project. And Prof. Joseph John for giving insights on micro-
phone operation. We also like to thank WEL Lab staffs, in
particular Maheshwar Mangat Sir for his valuable inputs.

R EFERENCES
[1] Wasim Ahmad and Ahmet M. Kondoz, Analysis And Synthesis Of Hand
Clapping Sounds Based On Adaptive Dictionary, in Proceedings of
the International Computer Music Conference University of Surrey,
Guildford, United Kingdom 2011.
[2] Seyi Stephen Olokede,Design of a Clap Activated Switch, in Leonardo
Journal of Sciences, College of engineering and technology Olabisi
onabanjo university,Ibogun,Ogun State 2008.
[3] Bruno H. Repp,Sound Of Two Hands Clapping-An Exploratory Study, in
The Journal of the Acoustical Society of America, Haskins Laboratories,
Connecticut 1986.

You might also like