Control your home devices by whistling
This post will show you a simple application of the USB enabled remote control.
The major problem of all kinds of physical remote controls is that they are usually not ready to hand when you need them. If you have to move to get to the remote control, you could as well directly switch on the device. Thus the whole concept of ‘remote control’ is becoming a bit useless. Therefore this post will show you how to create a non physical remote control.
The idea of the non physical remote control is very similar to the clapper switches. But instead of clapping you simply whistle. Whistling has some advantages over clapping. The first and most obvious is that you do not need your hands for whistling. You can continue doing what you are doing and control devices in parallel. The second more important advantage is the expressivity of whistling. You can vary your whistles in the rhythm, the length and the tone whereas you can vary claps only in the rhythm. This expressivity allows you to encode specific commands like “turn desk lamp on” or “turn ceiling light off” and so on.
To whet your appetite, here is a video showing the non physical remote control in action:
So how does this work? Actually it is very simple. A microphone captures audio inside my room. This audio is transformed by a FFT into its spectral components. The FFT gives you the information of the magnitude of the captured frequencies. Inside this frequency representation of the microphone signal we have to look for whistle signals. And in fact, whistle tones have two properties making them very easy to detect. First, they are loud. Thus the magnitude of whistle frequencies will be quite high. Second, whistle signals are very close to single frequency signals (like a perfect sine signal). The following three images will give you an impression on the spectrums captured from the microphone. The x axis describes the frequency, the y axis describes the magnitude of the frequency component.
The spectrum of a whistle sound with no background noise looks like this:
As you can see the whistle sound should be easy to detect. The sharp spike indicates that the whistle is very close to a single-frequency sine.
If we add a little music as background noise, the plot looks like this:
Still, the whistle is clearly visible.
Having a high detection rate is nice. But also the false positive rate should be as low as possible. Lets take a look at a graph of someone talking near to the microphone:
Here we see several spikes. To avoid the highest spike from being detected as a whistle, we introduce a uniqueness ratio. This ratio is defined by the maximum value divided by the second maximum value. In case of the voice graph the uniqueness ratio would be very low, approximately 1.5. In contrast to that in the case of whistling with background music, we have a uniqueness ratio of >8. This filter is very simple but yet effective. The independence of amplitude values let the filter work on loud whistling and soft (far away) whistling without adapting the filter parameters.
You find the implementation of the whistle detector in my mercurial repository in the folder linux/whistle_control . To check out the repo, execute
For running the code you need to have installed the fftw3 development headers (libfftw3-dev for Ubuntu) and the ALSA development headers (libasound2-dev for Ubuntu).
Please note that this code is not really polished. It is a 1h quick hack but it should give you the basis for more advanced implementations. Currently the program only distinguishes between two commands. The relative frequency of two whistle sounds determines which command is executed. low to high => command 1, high to low => command 2. However, this should be easy to adapt to your needs.