2
$\begingroup$

I was searching on the Internet hopelessly about some materials regarding detecting a sound in another sound. Say, I've got a recorded short sound (which may be anything, fragment of speech, fragment of music, noise, their combination or something else) and a longer sample, which contains this sound somewhere. The problem is, that the sound may be partially mixed with some ambient sounds. I know though, that despite mixing with other sounds, this will be exactly the sample I have recorded earlier.

Which algorithm may I use to perform such search?

$\endgroup$
  • 1
    $\begingroup$ I think that Matched Filtering will do better than any cross-correlation. Although keep in mind that it depends what kind of sound you are trying to detect. For some classes there might be more optimal approaches. $\endgroup$ – jojek Jul 1 '14 at 10:02
  • $\begingroup$ Are the 2 sounds absolutely identical, e.g. one recording played twice at the identical sample rate and volume? Or just very similar (saying a word or playing a note twice)? $\endgroup$ – hotpaw2 Jul 1 '14 at 19:36
  • $\begingroup$ I guess, that being a little bit more specific will help :) I'm talking about radio jingle - sound, which starts or ends a broadcast. I can extract one jingle, such that I'll have a clear sample, but ones I'll be comparing it to may be noisy or mixed with other sounds. $\endgroup$ – Spook Jul 1 '14 at 20:47
  • 2
    $\begingroup$ @jojek, matched filtering is the same as cross-correlation since the impulse response of the matched filter will be the time-reversed copy of the sound the OP is trying to detect. it's really the same thing. $\endgroup$ – robert bristow-johnson Jul 31 '14 at 11:51
  • $\begingroup$ An Industrial-Strength Audio Search Algorithm $\endgroup$ – Emre Jul 31 '14 at 18:12
3
$\begingroup$

I don't know if you are familiar with statistical signal processing and therefore will write my answer assuming that you are not. Everything I explain here is much better presented in any book about statistics. I would recommend Kay's book about detection theory. I first summarize your question by reformulating the 2 points you made, first in comprehensive English and then from a signal processing point of view.

You have access to two signals:

  1. The signal you are looking for. Be it music, speech, or whatever. The only important assumption about this signal is that you perfectly know it. We will name it the signal of interest and denote it $s$. Let's say that it consists in $N$ samples denoted $s[n]$, with $0 \le n < N$.
  2. A recording that contains the signal of interest as well as many other sources. The recording will thereafter be named the observation signal and denoted $x$. The other sources are all considered as noise in that they consist in anything but the signal of interest, and we will denote the noise $w$. The observation is longer than the signal of interest. Let's say it consists in $K$ samples denoted $x[k]$, with $K \ge N$ and $0 \le k < K$. Same goes for $w$.

You said you know what you are looking for ($s$), but you don't know how badly it is "drown" ($w$) in what you are observing ($x$). From this point, the first thing I would try is a matched filter (MF) approach. I can't say for sure it will work for your problem because you gave us nothing about $w$. What I can say for sure is that this is the easiest approach that is very likely to work, both from a theoretical and a programming point of view. If this does not work, then you can come back here again. The fun part will start from there :)

But for now, let's focus on the matched filter. $s$ is shorter that $x$, so you should be able to take $M$ successive snapshots of $x$ of the same length as $s$, each denoted $x_m$. From $s$ and those $M$ snapshots, you can construct a third signal $y$ of length $M$, with each sample defined as follows : $$y[m] = \sum_{n=0}^{N-1}{x_m[n]s[n]}$$

If $s$ is really in $x$, then you may see a clear maximum in $y$, at the index $m$ of the snapshot that contains $s$. If not, two possible conclusions:

  1. $s$ is not in $x$. But that should not be the case, according to the presentation you gave of your problem.
  2. Either the "level" of $s$ is way too low as compared to $w$ (we talk about a bad signal-to-noise ratio), or the statistical properties of $w$ are making this more complicated. The fun starts in the latter case.
| improve this answer | |
$\endgroup$
0
$\begingroup$

If your exact sample is present, you want to use circular cross-correlation between your signal and your recorded short sound:

https://en.wikipedia.org/wiki/Cross-correlation

Because it is a measure of correlation, consider that if an absolute value of normalized cross-correlation is over 0.7 in the results, it is very likely that your signal is located at that index.

Cross-correlation can be computed using the sum formulas if the data set is relatively small, and can be computed using Fourier transforms and the fft for improved speed with larger data sets:

https://en.wikipedia.org/wiki/Discrete_Fourier_transform#Circular_convolution_theorem_and_cross-correlation_theorem

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ i don't know why circularity in the cross-correlation is necessary. it's simply what you get when you use the DFT to do the cross-correlation. $\endgroup$ – robert bristow-johnson Jul 31 '14 at 11:53

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.