views:

1582

answers:

5

I’m trying to find an algorithm to detect when the user blows into the microphone (like Ninentdo DS or iPhone) on a WM6 device with C#.

I was thinking to use Waveform to read from the mic in real time into a small buffer, but I'm a bit lost on how to recognize the blowing sound, I guess it sounds like white noise. Anyone has an idea on how to do it?

Any help will be greatly appreciated.

+4  A: 

If I were to tackle the problem, I'd blow into the mic and record that. Then run an FFT on the wave data to get a dominant frequency (or a few). I'd do that for several "blows" to see if they produce similar results. If they do (and I'm fairly sure they will) then I'd use an algorithm to look for that same frequency.

It's not a trivial task, but since a lot of the recording and math work is done, you could probably get it to work without too much pain.

ctacke
I had no idea OpenNetCF had an FFT function. Pretty cool.
MusiGenesis
In fact we have 2 different implementations that I did ages ago (probably came in version 1.2 or so).
ctacke
i think "noise" (at least white noise, which is what blowing into a mic should produce) by definition is a mixture of all frequencies; a dominant frequency would imply pitch, which would make the sound "not noise"
Steven A. Lowe
Different microphones will generate a different frequency signature. I think trying to detect this in the frequency domain is just going to be too "finnicky" of an algorithm... working in some cases, failing in others.
Nik Reiman
+1  A: 

This isn't exactly the same, but here is my answer to a question about note onset detection:

http://stackoverflow.com/questions/294468/note-onset-detection#294724

The answer describes an approach that relies on the signal strength's rising above a given threshold. This approach would work to detect a blowing noise, although it would also respond to any noise at all, so talking etc. would also trigger it.

You could use FFT, but I think this would be too slow to use in realtime, especially on a Windows Mobile device (it might be fast enough, though). However, a blowing noise is unlikely to have a dominant frequency, unless the blower is whistling a particular note. If FFT is fast enough, you might actually want to look for noises that don't have a dominant frequency (you'd be assuming that anything with a dominant frequency or frequencies was speech or an instrument of some sort) and that are heavily weighted towards the upper end of the audible range (above 10,000hz or so).

MusiGenesis
I'll take your word for it on dominant frequencies. My FFT work has all been for seismic analysis. What I know there is that apparently "noisy" looking waveforms will often show a couple of dominant spikes due to natural frequencies. I assumed (probably wrongly) you see similar in white noise.
ctacke
I think white noise per se shows the same intensity at all frequencies (although that might be pink noise - it's late and I'm too tired to google). However, I don't think a blow would actually be white noise.
MusiGenesis
+3  A: 

A blow in a mic will not necessarily show dominant frequencies in the high-range (10,00hz +). Blowing in a PC microphone will most likely cause signal staturation and distortion, which has a lot of low-range frequencies as well. The resulting signal will simply be a big burst of saturation.

I had to do a similar project years ago, and what I did was simply look for volume peaks well above normal speaking levels. Worked fine.

sthg
The 10,000 hz thing was a total guess - I've never actually looked at a recording of a blow. Your mention of distortion just gave me an idea for another answer.
MusiGenesis
+3  A: 

sthg's answer mentions distortion as a likely outcome of blowing into a mic. I just did a quick test, and my recording of blowing (on a cheap microphone) displayed a large number of samples at the minimum and maximum values (e.g. 32767 and -32768 on a 16-bits-per-sample WAV file), which looks like a flat-top has been applied to each of the peaks. A very simple way to detect the blowing sound might be to just count up all the samples that are at the min/max values, and if they represent more than 5% of the total (or some other threshold) assume that blowing is occuring.

MusiGenesis
Simple, effective, fast...I think this is the way I'd go (though it's not near as fun as a rolling FFT).
ctacke
Thanks. I was hoping somebody would pick up on the humor in the phrase "assume that blowing is occuring". :)
MusiGenesis
+1  A: 

I haven't looked at the spectrum of this, but I think you should see a band-limited noise spectrum with most energy below a few hundred Hz. This means you don't need a full audio bandwidth FFT, and 16K points is overkill. Even on a 256 point FFT over a small bandwidth you should be able to tell the noise from blowing in the microphone apart from speech.

stevenvh