Duration of activity: 3 hours
Group members participating: Lukas, Daniela, Helene
Goals:
- Perform exercises from Lab Session 3
Plan:
- Mount the microphone on the car.
- Do exercises 1-6.
Exercise 1
We downloaded the source code for the SonicSensorTest from the last lab session and made a small change to transforme it to a sound sensor test and called the new class SoundSensorTest.
We changed the following line in the SonicSensorTest.java:
UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
And replaced it with the following line:
SoundSensor us = new SoundSensor(SensorPort.S1);
Link to the complete SoundSensor.java file: SoundSensorTest.java
After we run the program on the NXT we tried to measure sound values from different distances and different volumes. The results of the measuraments can be seen in the following tables:
It was very difficulty to get accurate measurements for several reasons. We didn't have any measuring tape, so we had to estimate the distances between the sensor and the sound source. There was a lot of noise in the room which made it difficult in some cases to determine whether the measurements were detecting our sound or some noise in the background.
In our first attempt of measuring sound from different distances, we tried to clap our hands with equal volume, but we found this very difficult. It is hard to clap with the same amount of volume. We decided to use a mobile phone to make sounds of a constant volume instead, to achieve more precise results in the next experiment.
When we didn't make any sound the NXT showed sound values in the range from 2 to about 6, which must be due to the background noise. Therefore our measurements with a value around this range are very inaccurate and we cannot be sure that the value is caused by the sound we made or the background noise. For measurements above a value of 10 it is very clear that the microphone picks up the sound we made.
Despite the inaccuracies due to the experiment's set up, we argued that there is some proportionality between the registered sensor values, the loudness of the sound and the distance from the sound source and the sensor.
Sound from farther away and the same volume, are measured as more silent, while loud sounds from the same distance are also measured as such.
Therefore, the sensor seems to work correctly.
-----------------------------------------------------------------------------------------------------------
Exercise 2
In this exercise our goal is to gather a lot of data and plot it in a graph to see how the sound level varies over time. To do this we used the given DataLogger.java and SoundSampling.java.
We started the SoundSampling program on the NXT and used our mobile phone to make the same beeptones as in exercise 1.
We got the following result for 3 beeps (link to the raw data: Beeptone Sample.txt):
The beeptone that was made consisted of two beeps quickly following each other. These two beeps are clearly seen on the graph represented by the two small tops for each pulse.
This shows that the sensor is able to measure short sounds at average loudness, even though there is background noise.
We notice that that the readings start between 90 dB and 100 dB and in the next 300 ms drop to below 10 dB. We saw the same behavior in all of the samplings we took. We believe that these readings must be due to how the system initializes the sound sensor or to a noise inside the system that the sound sensor reacts to. This means that when starting the system we cannot get a reliable sound value within the first 300 ms.
-----------------------------------------------------------------------------------------------------------------
Exercise 3
We started by downloading the SoundCtrCar.java and the Car.java files and running the SoundCtrCar on the NXT. We noticed the following behavior:
- When the program started the car stood still.
- When we made a loud sound ( e.g. a clap or a shout) the car began to move forward.
- When we made another loud sound the car started to turn right in a circle.
- After another loud sound the car started to turn left in a circle.
- And after another loud sound the car stopped.
- When keep making loud sounds the car switched from stop to moving forward to turning right to turning left to stop etc.
After this experiment we took a closer look at the source code of the SoundCtrCar. Here we noticed that when the sound value reached a value of above 90 the car switched action between moving forward, turning right, turning left and stop. Which clearly maches our observations of the cars behavior.
Another thing we noticed during our experiment was that we could not exit the program unless we had the escape button pressed when switching from turing left to stop. When looking in the source code we found the reason for this, which is that when the car waits for a loud sound (e.g. is in the inner loop) it does not check whether the escape button is pressed. In fact the check is only performed between the car has switched to stop and starts waiting for a loud sound to begin moving forward.
--------------------------------------------------------------------------------------------------
Exercise 4
In this exercise we are asked to implement a button listener in order to make possible to exit the program at any point during execution. We did this by adding the following code to the SoundCtrCar.jave:
Explanation of the code:
We added a buttonListener that terminates the program when the assigned button is pressed. We assigned the buttonlistener to the ESCAPE button. Now we can stop the NXT by pressing the escape button, no matter in which loop (outer or inner) the program is.
(Link to the complete SoundCtrCar with button listener implemented: SoundCtrCar.java)
--------------------------------------------------------------------------------------------------------------------
Exercise 5
In this exercise we should implement a method to detect claps. To do this we created a class called DetectClap.java and used code from the modified SoundCtrCar (with the button listener) where we modified the inner loop to only react when it detected a clap.
Before this we used the SoundSampling program to sample data for claps and got the following result (link to the raw data: Clap Sample.txt):
Observing the graph we noticed that a clap has a pattern that goes from a sound value below 50 to a sound value above 85 within 25 ms and then returns back below 50 withing 250 ms (just as described in the exercise).
After this measurement we wrote the inner loop of our DetectClap program which can be seen in the following code:
We use the tresholds of sound value 50 and 85, and time 30 ms and 85 ms to determine whether it is a clap we are measuring.
This is done in the following way:
- If the sound level is below 50 and we are not clapping we do nothing
- If we reach a sound value above 85 and it is more than 30 ms since we were below 50 it could be the start of a clap, so we claim that we have started a clap (isClapping = true) and set time since clap = 0
- If we are clapping (isClapping = true) we add our sleeptreshold of 5 ms to time since clap. Besides we check if the sound value is below 50 and it is more than 250 ms since we started clapping, if so this must be a clap and we break out of the while loop. If Not and it is more than 250 ms since we started clapping this must be something else, and we reset all of the parameters.
When testing our program we got the wanted result: When we clap, the car reacts.
We noticed that when we made other short "pulse" sounds like short whistle, shout etc. the car also reacts. This must be due to the fact that these sounds have a pattern matching the one for claps.
(If we had been thinking about it at the time we could had gather data for these other sounds to see how much they look like clapping and maybe be able to modify our program to filter out some of these sounds. If we had access to FourierTransformation, we could also analyse the frequency spectrum of a clap and try to use it to differentiate between sounds with other spectra).
-------------------------------------------------------------------------------------------------------------------
Exercise 6
In this exercise we should let the car move in the direction of the louder sound based on readings from two sensors.
We started by making a little program which sample sound values from the two sensors to check if some calibration is needed. We found that the right sensor measures a little more than the left sensor, so we added a value of 5 to the measurements from the left sensor.
We created a class PartyFinder.java which basicly gather the readings from the left and right sensor and calculate a ratio which determines how much power the left and right wheel gets (link to the file: PartyFinder.java).
The ratio is calculated as how much the left sensor measure relative to the total measurement:
leftSoundValue / (leftSoundValue + rightSoundValue)
After that we calculate the power of each wheel. We are doing this via a power function because a very loud sound to the left should make the car more eager to turn to the left and vice versa. We added a constant to this power funktion to increase the minimum power to get the car to move:
leftPower = 25 + 10^(2.2 - ratio)
rightPower = 25 + 10^(1.2 + ratio)
We got the values in the function from trying different possibilities.
First we tried placing the sensors close to the car but the measurements on the two sensor were very close to each other when we made a noise from one of the sides, so we moved the sensor away from the car (this can be seen in the video below). This also helped the fact that the sensors were reacting to the noise from the wheels.
The final result from this exercise can be seen in the following video:
Conclusion:
The sensor readings of the sound sensor are affected by the background noise in the environment. Detecting a sound in the value range from 2 to 6 can be difficult, since in a noisy environment such as the lab, the sensor readings are never under this range.
By logging sensor data we noticed that the sensor always starts reading values between 90 and 100 in the first 300 ms. These readings are probably due to the system itself, and we can therefore not consider the readings in the first 300 ms as fully reliable.
Different kind of sounds can be recognized algoritmically by analyzing sound's volume patterns, but sounds with similar volume patterns (e.g. a clap and a short shout) are difficult to distinguish.
Some mroe calibration of the sensors could be needed when using more than one sensor.
References:



