The Doppler effect is found almost everywhere someone is blasting a noise and traveling. The scenario you will probably hear it the most is with police cars blasting a noise as they are rushing past. It would be much more effective to have the police car just announce to move out of the way instead of a loud annoying siren. I sought to create that solution using the Sony Spresense, the built in GPS that is included in the board, a button and a portable speaker.Doppler Effect
We are going to start with what the Doppler effect actually is. Please see image below for an example.
That car is driving at speed v. The people in front of him are getting compressed waves and the people behind him are getting depressed waves. The Doppler effect is found by the following equation.
f' is the frequency that the stationary person will hear, f_0 is the frequency that you are playing and v is your speed in mph (everything is converted to be miles per hour to make it easy for Americans. If you're not, I guess this math would need to be changed for you). So to make the project much easier for myself, I'm going to concern myself with just four speeds - that way I can just play one of those speeds for each speed. I chose 15mph, 30mph, 45mph and 60mph. I figure in a 20mph zone, a police officer will probably be driving 30mph so I'm probably fine. Please see images below for the math.
Generally police sirens emit frequencies between 600Hz and 900Hz which means that the resulting frequencies are:
- 60mph > 647 Hz - 970 Hz
- 45mph > 635 Hz - 953 Hz
- 30mph > 623 Hz - 935 Hz
- 15mph > 612 Hz - 918 Hz
One of the many great features of the Sony Spresense is it's built in GPS. The device uses GNSS which stands for Global Navigation Satellite System. It normally has an accuracy of 2 to 3 meters (around 10 feet). I don't expect to get those same kinds of accuracy but within 100 feet will work fine.
I'm going to start with how latitude and longitude relate to what I'm trying to accomplish. Latitude is North > South and longitude is East > West. One degree of latitude is equal to about 111km which is about 69 miles. One degree of longitude is equal to 111km * cos(degrees in latitude), for my location, it's about 84km which is 52 miles.
To figure out how I want to determine the distance between one location and another, I will use the Pythagorean theorem (a^2 + b^2 = c^2) to figure out how to determine the distances.
Please see below for the math for the distances.
To get the speed, you just take the distance calculated above and divide it by the time it took to get that information. If I sample every minute, I multiply the distance by 60 (minutes to hours) and I get our speed.Setting up the Sony Spresense
Incorporating both the adjusted frequency for the four speeds as well as determining the speed using GPS will allow us to determine the speed and also play the audio file related to that speed. The sampling time for GPS is every second (or at least that is what I have it set at), this means that I will multiply the distance by 3600 (60 seconds per minute times 60 minutes per hour) in order to get my velocity. I will get very aggressive velocities because my sampling is every second but my system will also react a lot faster than if I sampled every 60 seconds.
Please see attached code. I calculated the distance that the gps was reading in miles (1) and then multiplied it by 3600 (2) in order to determine the miles per hour.
Using this information, I can take it, and using a simple pushbutton, I can play the same audio file at different speeds and the audio will compensate with the speed.Roadblocks
Unfortunately, I can't seem to figure out a way to upload my different audio files. I will work on it - I think I might have to move my project on GitHub and post it there. The other issue I had was actually determining if my system was working in the field. I live in kind of a busy neighborhood and I haven't gone to the middle of the woods yet in order to blast these recordings. I would like to modify this in the future to take a user's voice and modulate it in semi-real time.
Overall, the concept is pretty straightforward and I think we would all appreciate a little clearer noise in our lives without having to hear the noise of sirens go by.