Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Aim:
To turn-on and off an LED based on singular (on) or consecutive (off) claps, with a high degree of
reliability, robustness and tolerance to noise.
Introduction
- Detailed Requirements:
This particular design task requires the implementation of an analogue circuit or digital code in
order to correctly process and interpret the signal to fulfil the following:
True requirements:
1. One clap should turn the light on and two claps in quick succession should turn it off
2. The systems operation should be robust and reliable (especially to ambient noise)
3. If using the computer, the sampling rate should be minimised at the input
Desirable Requirements:
1. Larger the distance between the user and microphone that the system can work at
2. Higher robustness to noise
Windowing
This technique allows segmented parts of the entire value array to be analysed based on the rate
at which the system is receiving information, and how much of it. The technique is particularly
adequate for this project as samples can be taken in real time through a loop in Matlab and
compared to pre and post windows, making the analysis of the time varying signal much simpler.
The window used in this case is a simple rectangular window. The size of each window can be
determined by 2 key characteristics:
- The time between each clap; in this case a size of 0.2s was used (2000 samples), and;
- The maximum number of windows (time taken) for consecutive claps, which was max 3
windows, at approximately 0.6seconds.
The only issue with this technique is that distortion in the signal being analysed, can cause peaks
to overlap and parts of the peak to appear on the edge of one window and the next, incorrectly
identifying 2 peaks in 2 windows when only 1 was found. A Hamming window could have been
used instead to minimise distortion due to its smoother shape, but given the time constraints, was
avoided as it is harder to implement.
Sound Characteristics
The challenge with identifying a clap is that there a many other sounds such as a finger click or a
foot step on a hard surface that results in a high intensity peak in amplitude in the time domain
similar to that of a clap which will be the fundamental shape we will focus on. To be able to
differentiate between a clap, the differences within the actual sound rather than shape of the
sound can be a telling difference. The following differences in sound include:
Pitch: How high or low a sound/note is. Higher up in pitch a particular sound is, higher the
frequency and vice versa lower the pitch, lower the frequency. At a fixed distance, the
pitch of these sounds are quite distinct, however care must be taken when analysing the
frequency of the sound as closer the sound is to the mic, the larger the frequency of the
sound wave due to the Doppler effect, clouding the sound characteristic
Duration: As a clap reverberates a bit more (tens of micro seconds range) than a finger
click, and shorter than a stomp on the ground, this may affect the duration of the voltage
spike1
The only other sound property there is but cant be used in the determination of a clap (from
other similar sounds) is amplitude due to the variability in claps from age, sex, position of clap on
hand etc.
Robust solution
The definition of robustness for this project is that with different clapping sequences and
background noises that the system works as it is supposed to. In order to distinctly identify the
signal being fed from the microphone into the DAQ, an amplifying circuit is connected between
the 2, consisting of a resistor and capacitor (takes the output). Within the code itself, a lower pass
filter aims to remove or at least dampen the high frequency components of the ambient noise,
and the side intervals of the peak. Given the resultant noise reduction, a peak can be identified
much more easily by setting a threshold values that defines a peak for all values above, with the
lower the threshold value, the further away the clap can be from the mic and still be detectable.
http://www.animations.physics.unsw.edu.au/jw/sound-pitch-loudness-timbre.htm
Task
No.
Task
Measure
consecutive
claps and
window length
Design Matlab
Low-Pass filter,
test
Implement a
find peaks
algorithm, test
Action
By looking at the response of consecutive claps in Matlab
through the DAQ, determine the time lapse between the
2 claps.
Do tests about 5 times to ensure consistency between
time delay
Find no. of samples in a window (window length) which
allocate 1 peak ONLY in 1 window
Using first principles, implement a Low-Pass filter with the
cut-off frequency (<500Hz)
Using the signal generator, input signals with frequencies
greater than the cut-off frequency and to ensure correct
low pass operation.
Observe the signal in the time domain, looking for the
absolute peaks which correspond to a clap within the
given frequency spectrum. Setting some threshold
minimum value will stop residual noise peaks from being
picked up
Comments
Do the 5 or 6 tests with different people as different people
might perform consecutive claps (naturally) at different speeds.
Looking at the maximum time lapse between gaps, will allow us
to differentiate between singular and consecutive claps.
Never want more than 1 peak in a window therefore must be
small and big enough so that this is the case
No tool box functions can be used in Matlab except for the FFT
required to convert the time domain signal into its frequency
domain.
Low-Pass filter will also make the peaks of the sounds more
accurate with less staggered intervals (high frequency
components) on the way up to the absolute peak
Dont use the windowing technique yet during this stage. Look
at a large set of values first.
This is only the first step of characterising a clap
Note that the size of the threshold value may limit the distance
between the user and the microphone for the system to still
Implement
window, test
Implement logic,
test
Implement
driver circuit,
test
function properly.
Determine
characteristics
of a sound wave
and how they
change the
shape of the
waveform
(OPTIONAL)
Determine the
sound
characteristics
of a clap
(OPTIONAL)
Implement clap
characterisation
algorithm, test
(OPTIONAL)
10
Implement
envelope, test
(OPTIONAL)
Given this, we could implement our logic that was able to distinguish between singles claps and
consecutive (>=2) claps as shown on the next page. The logic accounts for more than 2 consecutive
claps whereby it will keep the light off.
Window i'
Restart clap
status
Has a clap been found previously & 2
windows have now passed since then
Yes
Single Clap
Turn light ON
No
No
Clap found
(Window Max value > Threshold)
Yes
Is this the 1st clap found?
Yes
No
Consecutive clap
Turn light OFF
i=i +1
- Filtering
Because of the ambient noise being detected by the microphone alongside the claps, the signal
waveform is very noisy. Therefore, a filter is introduced to process the signal and filter out the
unwanted noise components. The filter implemented in this system is a second-order elliptic low
pass filter. This filter will smoothen out the noisy and unwanted high frequencies of the ambient
noise. The cut-off frequency was chosen at 200Hz as most ambient noise frequencies and its
harmonics were found to be in the kHz range. The filter design was done in MATLAB using
ellipord, ellip and filter functions. The ellipord function takes in the passband and stopband
edge frequencies together with the desired passband ripple and stopband attenuation and returns
a suitable order and elliptic natural frequency for the filter design. The ellip function then takes
these values and returns the filter coefficients. Lastly, the filter function is used to filter the signal
with the designed filter. Below is the comparison between the filtered and unfiltered clap signals:
0.15
0.1
0.05
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
0.18
0.2
0.1
0.05
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
0.18
0.2
As seen, the filtered signal is much smoother compared to the unfiltered one. As such, the clap
peak is more distinct and easily detected. Because of this, the system is able to detect claps at a
much further distance than normal. Also, because the high frequencies have been filtered out, this
allows us to lower our sampling frequency from 15kHz to 10kHz with no effect on the system.
The circuit design is fairly straightforward for this system as most of the process is done via
software. The electret microphone is first connected in a microphone biasing circuit, which
consists of a resistor (2.2k) and a capacitor (1F). The output of the capacitor is then connected
to the DAQ input for sampling and signal processing. The DAQ interfaces with MATLAB where
most of the filtering and logic is carried out. The DAQ then outputs a logic signal via the output
ports, into the base of the transistor.
When the user claps once, the DAQ output a HI (5V) to the base of the transistor, in this situation
the transistor is now ON, causing current to flow from Vcc to ground. When the user claps twice,
the DAQ outputs zero, this is not enough voltage to forward-bias the transistor and the transistor
is off causing the LED to be at the same potential as Vcc as there is no ground connection,
therefore no current flows through the circuit.
setup to try further distances), and it is highly robust to noise. Unfortunately, due to time
constraints, we were unable to execute better ideas that would further improve the
responsiveness and the robustness of this system, e.g. envelope detection, clap characterization
through the analysis of sound properties, and the use of a Hamming window instead of a
rectangular window.
This lab had many challenges, which we managed to overcome, and also learned much in the
process. The design task really assessed us on our proficiency in designing, interfacing and
troubleshooting hardware and software and manipulating signals to perform respective actions.
Due to the time constraint and limited resources, we learnt to be more organized and systematic
in laying out a task plan, and executing specific tasks to better achieve our goal. We also learned to
think more critically and analyze a problem more thoroughly, to find a solution and workaround.
Moreover, this lab also taught us to be more particular about everything to the finest detail, as a
small miscalculation could have big impacts on the system (e.g. tuning the low pass filter). Lastly,
we would also like to thank our lecturer Dr. Aboutanios for teaching us to think more critically and
exposing us to real-life working scenarios. Thoroughly enjoyable project.
samples = seconds*Fs;
totalIterations = samples/samplesPerIteration; %seconds*Fs = total number of smaples
while(i ~= totalIterations)
acquiredData = getdata(ai, samplesPerIteration); %4000 = no. of samples
data1 = acquiredData(:,1); % every sample from channel 1. data1 is of length 4*Fs
y=abs(data1(1)-data1);
%rectified. data1(1) may or may not start at 0, so
find each value relative to the first value
y_lpf = filter(B1,A1,y);
%data after lowpassfilter
t=0:1/Fs:(length(y)-1)/Fs; %time
if (max(y_lpf) > 0.011)
if ((found == 0));
%1st peak in sequence
found = i;
%first peak in 3 box sequence found
if(i == (totalIterations-1)) % account for clap in last window
putsample(ao,5) %output HI
end
else
%next peak found, for consecutive claps
putsample(ao,0)
%turn off LED
off = 1;
found = i;
end
end
if (((i-found)== 2)&&(found~=0)) %Singular clap
if (off == 0)
%reset found after off state change
putsample(ao,5)
end
found = 0;
off = 0;
end