How to catch the event when spectrum of an audio reached a specific height, like triggered event made by a loud sound?

无人久伴 提交于 2019-12-02 09:36:09

So long as you can generate a continuously updating spectrum then you just need to iterate through the spectrum after every update and check the magnitudes of the relevant bins. Typically you might overlap each sample window e.g. if your FFT size and sample window size is N = 1024, then you take you first FFT over samples 0..1023, then the next block will 512..1535. This 50% overlap helps to reduce latency in your detection (you can increase the overlap but if you go too far then it may get too compute intensive).

The most straightforward way to detect a snare drum would be to compute the cross-correlation between the input signal and a recording of a snare drum hit. When the cross-correlation is high, you likely have a match.

This will be superior to testing the FFT, since the FFT computes the cross-correlation of the input signal with a pure sine wave.

The approach is called "matched filtering", it's well known in optimal detection theory.

If you just want to see when the signal gets very powerful, you don't need an FFT. You can use Parseval's Theorem that relates the power of the time and frequency domains. This allows you to create an O(1) sliding window energy detector from a moving average of squared samples.

BTW, this is exactly the sort of question that is relevant on the DSP Stack Exchange

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!