How can I reduce noise errors when detecting DTMF with the Goertzel algorithm? Thanks a lot to whoever downvoted my question for no good reason.

I wrote an implementation of the Goertzel algorithm in JavaScript and made a demo that detects DTMF dial-tones.

You can find the code here:
http://github.com/ravenstine/goertzeljs

The demo is below, and you can try it out if you have a web browser that supports WebRTC(newer versions of Chrome and Firefox do).

http://goertzel.herokuapp.com

I have an issue where I need help:


I need a way to effectively filter out background noise.


There wasn't much information that I could find on the subject that didn't already assume that I knew a lot about DSP.  I heard about using a window function and while I could find some algorithms, implementing them didn't seem to make any significant difference(Goertzel.js uses Exact Blackman).

As a result, I came up with my own filter where if an energy peak is not distinct enough from the energies of other frequencies, the information from that sample isn't used.  This was actually tremendously effective when using a buffer size of 2048.

However, I want my DTMF detector to be as close to meeting ITU specifications as possible; the minimum duration of a DTMF tone to be detected is specified by ITU as 40ms, but my detector doesn't consistently detect tones unless they are around 110ms.  

To deal with this, I want to make the buffer size even smaller, but if I do this then my method of removing noise becomes unmanageable(meaning it seems to either discriminate too-little or too-much).  

At the moment, my detector works pretty well but background noise occasionally creates erroneous detections.

What are some other methods that I can implement to filter out noise with my DTMF detector?  Also, am I correctly employing the window function?
One technique to reject noise is to use the ratio of the Goertzel filter output power to the total signal power over the same 40 mS sliding time windows, as well as ratio of the absolute Goertzel power to some threshold, as part of your decision criteria.  

You can adjust your buffer size to match this minimum DTMF signal time (2048 may be too long if the sample rate is well below 44.1kHz).  Using a non-rectangular window may require using a longer Goertzel filter than 40 mS.  Adjusting the Goertzel filter length to be close to an integer number of periods of the filter's center frequency will also help reject DC.  

Added:
Using a sliding Goertzel (and sliding RMS power) will reduce the effects of framing.