2
$\begingroup$

I'm trying to solve the following problem:

Let's say I have a reference sound and a recording that I know contains at least one occurrence of the reference sound. How can I determine the positions in the audio where the sound was played? It's possible that the longer recording could have noise, and I cannot assume perfect time alignment with the sound that's playing in the recording (meaning, if I knew the content of the sound played in the recording other than the reference sound, I cannot just subtract that from the recording itself).

The method I'm experimenting with is as follows:

  1. Grab windows the size of the reference sound from the recorded sound
  2. For each window, compute the N dominant frequencies (by finding peak magnitudes in the FFT results)
  3. Assign points to the dominant frequencies of the reference sound (where the most dominant gets a score of N, and the least gets a score of 1)
  4. Compare the window's dominant frequencies to these and score it

The next few parts are just experimental, and used to narrow down results.

  1. Do some filtering on the matches (for instance, a match with a score lower than half the possible score gets filtered out)
  2. Look at overlapping matches and compute the cross correlation with the reference sound (using every possible time shift, prefer the maximum result). Prefer the match which requires the smaller shift
  3. Perform that shift on the match's endpoints

The problem is that I want to also detect if part of the reference sound was played, and step 6 would not allow that if the reference sound was played two times in quick succession where one was cut off.

It seems like there has to be a solution that's not as ad-hoc as this. I'm very new to the field of DSP, so there may be something simple that I don't know about.

Any ideas?

Thanks!

$\endgroup$
  • $\begingroup$ Given this level of problem definition, you want a suggestion rather than a solution. And the most probable suggestion will be a matched filtering if you performa simple waveform based detection. If you are ok with parametric methods than more sophisticated algorithms can also be used. $\endgroup$ – Fat32 Oct 6 '17 at 23:18
  • $\begingroup$ step 6. is the key step. do you know how to compute cross-correlation? $\endgroup$ – robert bristow-johnson Oct 6 '17 at 23:18
  • $\begingroup$ @robertbristow-johnson Yes, I know how to compute cross-correlation. What do you have in mind? $\endgroup$ – user2437378 Oct 9 '17 at 23:41
  • $\begingroup$ @Fat32 would you mind giving me some resources on the more sophisticated methods that you've alluded to? The matched filter (very cool btw, thanks for that!) might work for me, but I'm just interested in exploring several options. $\endgroup$ – user2437378 Oct 9 '17 at 23:41
  • $\begingroup$ matched filter is the same as cross-correlation in this case. so @user2437378, have you tried simply cross-correlating the shorter snippet of reference audio against the recorded audio with various lags? for each lag, it's like computing a simple dot product and you get a number. try it for all possible lags and see where (at what lag) your dot-product results in a maximum value. $\endgroup$ – robert bristow-johnson Oct 10 '17 at 3:57
-1
$\begingroup$

It seems that a matched filter is good enough for my use case.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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