Thursday, September 16, 2010

Lab Exercise 3

Date:
16/9 2010

Duration of activity:
3.5 hours

Group members participating:
Frederik & Christian

Goals:
To investigate the NXT sound sensor, and the characteristics of different sound phenomenae - especially the gesture of clapping.

Plan:
1. Test of the Sound Sensor
2. Data logger
3. Sound Controlled Car
4. Clap Controlled Car

Results:
1. After mounting the sound sensor, and uploading the program SoundSensorTest [1] to the car, we could see the values of the microphone readings in the display of the car. We experimented  with different sampling frequencies in the main loop of the program to see, if this had any effect on how the readings were.
It seems that if the delay is below a value of around 300 ms, the microphone readings are not so responsive.

Car with mounted sound sensor

2. After a dry run of the datalogger program, SoundSensor [2], we inspected the sample file and decided to layout the data written by DataLogger [3] in a single row instead of 20 to ease the import of data to MS Excel.
In the start of the log file, it seems as if there is some noise - our guess is that it is some sort of burst noise [4] occuring during initialization of misc. circuits inside the NXT.
We imported the data sample into Excel, and made a graph:
As the graph shows, there is some form of impulse starting at sample 0, and quickly dying out. The clap starts at around sample #200, and peaks at 93 dB. The graph shows that the clap has a very characteristic, steep climb at the beginning, and then dies out more slowly.

3. The program SoundCtrCar [5] has 4 states; stopped, go forward, turn left, turn right. Each state transition is triggered by a sound input of 90 or higher.


Video showing the SoundCtrCar program

The program runs in a do-while loop, which continuosly reads the sound sensor until a value equal or above the threshold is read. It then returns to the main control loop.
One hickup with this version of the program is that it is difficult to terminate the program - the escape button must be pressed down before the main loop is restarted.

We wanted to improve this version by making the press of the escape button detectable from all program parts. We did this by making a class that listens for button presses by implementing the ButtonListener interface and adding a field indicating a press on the escape button. See example below.


 Then other classes will then be able to read a global value of the escape button. So by checking for the escape button in the waitForLoudSound method a press on the escape button terminates the program. See example below.


4. To recognize claps, Sivan Toledo suggests that you look at how fast the sound strength goes from low to high, and then back to low again. The leading edge of the clap should be very quick, and the trailing edge should be slower [6]. This is because of the nature of a clap; it starts very abruptly, and then dies out more slowly, but still quite fast.
We had intended to experiment if it would be possible to look at samples close to each other. E.g. if a sample would rise with a value of, say, 30-50, it might be possible to recognize the clap. Of course for it to be sure, we would have to look at the trailing edge in order to exclude a continous high strength sound.
For reasons unknown we were not able to upload our program to the NXT, and therefor we were not able to test our assumptions before time ran out. The program can be seen in [7].

Conclusion
Because of problems with uploading the Clap Controlled Car program, we did not succeed in testing our assumptions for clap recognition. Likewise we didn't get to investigate the characteristics of other sound phenomenae than clapping. However, sample files suggested, that Sivan Toledo is on to something, when he proclaims, that a clap has a short, and powerful rise, and a more subtle trail.

Implementation-wise the NXT sound sensor is similar in use to the other NXT sensors - the sensor is instantiated, and the method readValue() is used to gather data.



References

[1]. SoundSensorTest.java - http://dl.dropbox.com/u/2389829/Lego/Lab3/SoundSensorTest.java
[2]. SoundSampling.java - http://dl.dropbox.com/u/2389829/Lego/Lab3/DataLogging/SoundSampling.java
[3]. DataLogger.java - http://dl.dropbox.com/u/2389829/Lego/Lab3/DataLogging/DataLogger.java
[4]. Burst Noise, Wikipedia - http://en.wikipedia.org/wiki/Burst_noise
[5]. Ref to SoundCtrCar - http://dl.dropbox.com/u/2389829/Lego/Lab3/SoundCtrl/SoundCtrCar.java
[6]. Legolab exercise 3 - http://www.legolab.daimi.au.dk/DigitalControl.dir/NXT/Lesson3.dir/Lesson.html
[7]. ClapControlledCar.java - http://dl.dropbox.com/u/2389829/Lego/Lab3/Clap/ClapControlledCar.java