Stupendous Sound


The sound sensor is another sensor which has a lot of different information in it and which requires careful handling to interpret the data from the sensor.

Here are a couple of useful recipes for doing things with sound processing. If you have something you really need, do ask me.

Detect noise level over the last minute

To detect ‘how busy’ a room is, we could consider using an overall measure of noise in the room. Here we do this with a simple low-pass filter with a high time constant.

Detect spikes (without firing on constant loud noises)

To detect spikes here, we assume a spike is a quick up followed by a quick down. To detect these, we:

  1. Highpass filter to isolate changes in level
  2. Threshold and fire an event if we see both positive and negative spikes in the highpass filter close together with silence either side.

If you look at the code below, there are a bunch of constants. Changing these alters how sensitive it is to spikes, and how ‘spiky’ a spike has to be.

Constant  Default  Description
TIME_THRESHOLD 0.2s We only count spikes that are separated from the previous one by at least this much. This avoids finding spikes when e.g. people are talking loud
SILENCE_BEFORE 0.2s We require this much silence before a spike - to make sure it is really a spike.
SILENCE_AFTER 0.1s And this much silence after. Making this value can make the spike detection less likely to false positive, but because we have to wait this long before reporting a spike, it will add delay.
UP_THRESHOLD .02 How much of an up spike is required on the high-passed value. Increasing this value will mean spikes have to be louder so increase the level of false negatives whilst decreasing false positives.
DOWN_THRESHOLD -.02 How much of a down spike is required on the high-passed value. This has a similar effect to the UP_THRESHOLD