This is a side-trip from my snoring app.
I had a crack at producing an autocorrelation of the audio signal, to see if that "correlates" with snoring/breathing very well. I have a simple algorithm going (produces 1.0 as the zeroth element, which is a good sign), but I'm wondering how to evaluate the result to determine if the autocorrelation is strong, and, perhaps further, how to use it to separate various possible sound sources.
Question #1: Is the RMS of the autocorrelation (skipping element zero) as good a "quality" metric as any, or is there something better?
To elaborate: I simply want a numerical way (vs "looking" at a chart) to distinguish a highly autocorrelated signal from a less well autocorrelated one.
(I don't really know enough to know what other questions to ask.)
Some early results: In some cases autocorrelation (either RMS or peak) shows a dramatic jump on a snore -- precisely the response I'd like to see. In other cases there is no apparent movement at all in these measures (and this can be two successive snores with the two responses), and in high-noise situations the measurements actually dip (slightly) during a snore.
Update -- 22 May: I finally got some time to work on this some more. (I was pulled off on another app that is literally a pain.) I fed the output of the autocorrelation into an FFT and the output is somewhat interesting -- it shows a fairly dramatic peak near the origin when a snore starts.
So now I'm faced with the problem of quantizing this peak somehow. Oddly, the highest peaks, in terms of absolute magnitude, occur at other times, but I tried the ratio of peak to arithmetic mean and that tracks pretty well. So what are some good ways to measure the "peakedness" of the FFT. (And please don't say that I need to take an FFT of it -- this thing is already close to swallowing its own tail. :) )
Also, it occurred to me that the quality of the FFT might be improved somewhat if I mirror-reflected the autocorrelation results being fed in, with zero (which is by definition 1.0 magnitude) in the middle. This would put the "tails" on both ends. Is this (possibly) a good idea? Should the mirror image be upright or inverted? (Of course, I'll try it regardless of what you say, but I thought maybe I might get some hints on the details.)
My test cases can be divided roughly into the "well-behaved" category and the "problem children" category.
For the "well-behaved" test cases the flatness of the FFT of the autocorrelation dips dramatically and the ratio of peak to average autocorrelation climbs during a snore. The ratio of those two number (peak ratio divided by flatness) is particularly sensitive, exhibiting a 5-10x climb during a breath/snore.
For the "problem children", however, the numbers head in exactly the opposite direction. The peak/average ratio dips slightly while the flatness actually increases by 50-100%
The difference between these two categories are (mostly) threefold:
- Noise levels are (usually) higher in the "problem children"
- Audio levels are (pretty much always) lower in the "problem children"
- The "problem children" tend to consist of more breathing and less actual snoring (and I need to detect both)
Update -- 5/25/2012: It's a little premature to have a victory dance, but when I reflected the autocorrelation about a point, took the FFT of that, and then did spectral flatness, my combined ratio scheme showed a good jump in several different environments. Reflecting the autocorrelation seems to improve the quality of the FFT.
One minor point, though, is that, since the "DC component" of the reflected "signal" is zero, the zeroth FFT result is always zero, and this kinda breaks a geometric mean that includes zero. But skipping the zeroth element seems to work.
The result I'm getting is far from sufficient to identify snores/breaths by itself, but it seems to be a fairly sensitive "confirmation" -- if I don't get the "jump" then it's probably not a snore/breath.
I haven't analyzed it closely, but I suspect that what's happening is that a whistling sound occurs somewhere during the breath/snore, and that whistle is what's being detected.