phyphox Forums
excat timer aslong audio is above certain level - Printable Version

+- phyphox Forums (https://phyphox.org/forums)
+-- Forum: App-Feedback (https://phyphox.org/forums/forumdisplay.php?fid=6)
+--- Forum: Feature requests (https://phyphox.org/forums/forumdisplay.php?fid=8)
+--- Thread: excat timer aslong audio is above certain level (/showthread.php?tid=589)



excat timer aslong audio is above certain level - cool-man - 01-27-2020

Hi,
I`m looking for a possibility to count time by "audio" activation, means if the sound from microfone is above a certain threshold it should start count and stop counting when is below this threshold.  Resolution should be most excat.

The implemented timer is not working like this.

Regards


RE: excat timer aslong audio is above certain level - Sebastian Staacks - 01-28-2020

In principle, this seems like an interesting idea, but this is a bit more tricky than the acoustic stopwatch.

The acoustic stopwatch works like this:
The recorded audio is handed to phyphox in chunks of about 100ms (I have not checked the exact value, but this also depends on the phone anyway). In each chunk we check whether there is an audio sample that exceeds the threshold. If it does, we locate it within the chunk and use its location to determine the time at which the stopwatch was triggered. We simply have to look for the first sample above the threshold and do not care at all about any other samples after this within the chunk. (This has some disadvantages: We cannot trigger twice within 100ms.)

However, finding the time at which the signal drops below the threshold is not that simple. The reason is that it does so all the time. Any tone or noise oscillates between extreme values and it drops below the threshold in every cycle. So, instead of looking for the first sample below the threshold, we have to monitor a sequence of samples and check whether all of them were below the threshold. How many samples? This depends on the tone you expect. For some random noise, monitoring a period of 1ms might be sufficient, but a 100Hz tone has a periodicity of 10ms, so we get a maximum once every 10ms and should only trigger if there has been no such maximum in a 10ms period. This also means that the resolution could only be 10ms.

This is not really a problem, but a complication for the "ease of use" for this kind of tool. The problem is that this is hard to implement in phyphox. Every experiment in phyphox is defined in our own file format, which does not (yet?) support loops. So we always analyze these 100ms chunks instead of looking at each sample at a time.

So, I cannot really offer you this function right away. However, I intended to improve the acoustic stopwatch anyway (I think I can create a version that does not require a threshold and a minimum delay setting), so I will put you request on my todo list. Unfortunately, this is a big list, so I cannot say when I will look into this.


RE: excat timer aslong audio is above certain level - cool-man - 02-02-2020

Thanks Sebastian for this detailed information. Would it be an idea to do a FFT of each 100ms sample looking for sound above this a certain threshold?


RE: excat timer aslong audio is above certain level - Sebastian Staacks - 02-03-2020

100ms is precise enough? Then I misinterpreted your "Resolution should be most excat." and we were talking about different time scales.

Our acoustic stopwatch gives a resolution of 1ms and theoretically, it could even be more precise as the microphone samples at 48000 Hz, resulting in a period of 21µs. In practice sound does not instantly push a single sample above the threshold, so you need a good setup to even achieve 1ms. What I wrote above applies if you want to achieve a resolution better than 20ms.

If 100ms is sufficient, I can easily check for each sample packet if its maximum is above the threshold. The resolution would depend on the buffer size of your phone, but it should be at least 100ms.

I will see if I can set up something in the next few days.

BTW: I do not see how a FFT would help here..? Do you need to filter a specific frequency range?


RE: excat timer aslong audio is above certain level - cool-man - 02-03-2020

Good point, what is most excat ? The time range I want to measure is typically around 1 to 20 seconds.
So resolution on 0.1 seconds would be good if this is easy to implement.

I was on wrong track with FFT, I though this sum up amplitude.
THANKS


RE: excat timer aslong audio is above certain level - Sebastian Staacks - 02-07-2020

So, I finally got around to create this and it works better than I expected. I found a simple way to find the last sample above the threshold, so the precision is in fact only limited by the period of the sound you use. However, in practice finding the correct threshold is not so easy. In contrast to just finding the maximum of a loud sound as we do for the acoustic stopwatch, you need a sound that consistently exceeds the amplitude of the environment. The threshold you need to set for this version is usually much lower than you might expect from using the acoustic stopwatch, because even though a tone might seem loud to your ears, the amplitude of a (seemingly quieter) single event is usually much higher.

In other words: If you have found a threshold in the acoustic stopwatch that works well for a clap, then imagine how loud and annoying a sound would be that constantly has the same sound level as the clap. So, most reasonable sounds have a much lower threshold and you will probably have to find a value that is only slightly above the level that would lead to random triggers.

So, here is the new "sound duration" experiment:
https://phyphox.org/phyphox-files/sound_duration.phyphox

Let me know if it is working for your.


RE: excat timer aslong audio is above certain level - cool-man - 02-09-2020

Thanks Sebastian it is working as I was looking for - perfect. I made some tests with 0.04 threshold, and measured always same time. This comes from a timer running a motor. For example : 5.357s 5,509s 5,646s 5,672s 5,476s all close by - I´m still evaluating what it tells to me. I can not compare the measurement with the real timer time - but is is good already to see the single values and if I tune the time of timer how this increase/decrease.

So again - Dankeschön.