1
$\begingroup$

I am going to detect alarm sounds (like from a fire detector) in a live stream. (I have asked similar questions here before, I'm now at the stage of actually doing it).

I will not really want to compare that two audio segments are similar (as in How do I implement cross-correlation to prove two audio files are similar?), but that there is an alarm sound (of which I have stored its FFT) present in the audio sample.

I now also have the FFT of the audio sample. I guess there would be at least two ways to do this:

  1. Do the cross-correlation of the two FFTs. However, this would require quite much calculation in sliding one of the series, to be able to find the highest correlation

  2. Do as is told in [1]. Zero-pad, do FFT of both, multiply, do IFFT but observe time reverse or complex conjugate to make it different from convolution

Or is there any alternative method, since I only need to look for that particular alarm sound?

Aside: Since each of my series covers 64 ms (16 kHz, 1024 samples per batch, 15.625 Hz/bin to max 4 kHz) and alarm sounds go "bah-buh_pause_bah-buh_.." I need to collect data across series as well.

$\endgroup$
4
  • $\begingroup$ but you already have a recommendation. Did you implement that and meet a problem? If so, what problem was that? If you did not implement it yet, maybe do that? $\endgroup$ Commented Jul 20, 2022 at 10:43
  • $\begingroup$ ..which recommendation? I've mostly been querying about anti-alias filtering and downsampling, which should be ok now. Not about the theme I'm asking about here. Which basically is whether it's smartest to do as 1. or 2. or any even smarter way. With the latter I basically was thinking about correlating only with the one or two peaks of the signal's spectrum. $\endgroup$ Commented Jul 20, 2022 at 11:24
  • 1
    $\begingroup$ as in your 2., that's a pretty specific optimized way of doing cross-correlation $\endgroup$ Commented Jul 20, 2022 at 12:03
  • $\begingroup$ Thanks! This is what I was after! $\endgroup$ Commented Jul 20, 2022 at 14:05

2 Answers 2

3
$\begingroup$

Or is there any alternative method, since I only need to look for that particular alarm sound?

If your alarm sound is ""bah-buh_pause_bah-buh_.." I would assume that the bah and the buh are tonal with a harmonic spectrum but different fundamental frequencies. If that's the case you can try the following:

  1. Run a comb filter or a set of cascaded notch filters to remove the fundamental and dominant harmonics from the input. One filter for bah, one for buh
  2. Run an energy detector on the input and the two filter outputs. Calcualte the ratio of the output energies to the input. Energy detector means: square the signal and run it through a lowpass filter.
  3. If the output is significantly lower than the input, that means there is a lot of energy at the bah or buh frequencies. So the energy ratio is a "detector" that tells you whether buh or bah are present. You can either make this binary (using a threshold) or a continuous metric.
  4. Downsample either after step 2 or step 3.
  5. At this point you have two signals: the bah detect and the buh detect. Simply look for a sequence where bah=on/buh=off for one second (or however long it is), followed by bah=off/buh=on followed by bah=off/buh=off. This can either be done with two cross correlations or a simple state machine.

This method will be computationally a lot more efficient than using FFTs and in general will be more robust against noise, movement of speaker and microphone and changes in the acoustic environment. For example the fine structure of the FFT can change a lot with microphone location or just someone walking though the room. The proposed method mimics roughly how a human being would detect the alarm.

$\endgroup$
1
  • $\begingroup$ I like that method! Thanks a lot! However, the bah-buh_pause_bah-buh_.. is only one example. Sorry for not telling, but I have learnt to be short here. The others could be beep-beep-beep_pause_.. or a certain tone from a mobile etc.. I have a list of some tones, and I have also thought about registering tones live in the product (but for those I'd have to rely on the same pattern I guess, for each 64 ms). But then there's nothing that hinders me to use your method orthogonally to pick out the most critical ones. I need to think about it. Thanks anyway, @Hilmar! $\endgroup$ Commented Jul 20, 2022 at 14:03
0
$\begingroup$

@Marcus-Müller's answer "as in your 2., that's a pretty specific optimized way of doing cross-correlation" is just what I was after.

I even got an alternative method from @Hilmar!

Thank you! Case closed.

$\endgroup$
1
  • $\begingroup$ I didn't do anything :) I just pointed you to what you had already found yourself! The real heroes here are you and Hilmar $\endgroup$ Commented Jul 20, 2022 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.