DSPRelated.com
Forums

Detecting DTMF Pulses

Started by Stacy March 6, 2014
On Tuesday, March 11, 2014 11:21:26 PM UTC-4, Stacy wrote:
> >I don't know what's "elegant" to you vs. "counting on your fingers and > > >toes", but I'd be mightily tempted to use the sliding DFT. > > > > > > > 1) How long should the DFT be? > > > > 2) When using the sliding DFT how many samples do you increment each > > window? > > > > > > _____________________________ > > Posted through www.DSPRelated.com
Stacy, Often the length of the DFT for DTMF detection is chosen to place the bin center frequencies as close as possible to the ideal tone frequencies with a tradoff vs time duration of the block. IIRC, for systems sampling at 8kHz, a common length was 205 samples. The normal difficulty with a blocked data arises when your tone starts or stops midway through a block of data. The sliding approach mitigates that. I think the nominal tone durations during dialing (automatic and not manual) were 45mSec on and 55 mSec off. You can certainly slide multiple samples per tone energy calculation. Probably every several mSec will yield good enough results. The sliding approach may be done with a simple dft or a goertzel. With the dft you have to have all of the coefficients (205 in the above example case) stored in memory. The goertzel only needs one per tone detector (assuming you are only finding the magnitude and not the actual fourier coefficient). Not well known is the goertzel approach to calculating the DFT as a recursion is not limited to just using a biquad filter structure as given in Goertzel's famous 1 page paper. Standard goertzel has numerical issues when working with low frequencies relative to the sampling rate. Other resonator structures used in a goertzel application can yield better numerical results. The last ten pages here: http://www.claysturner.com/dsp/digital_resonators.pdf Give the recipe for a generalized goertzel algorithm. I have derived the full generalized goerzel algo. If needed I can post it somewhere. Clay
On Wed, 12 Mar 2014 19:03:21 -0400, robert bristow-johnson wrote:

> On 3/12/14 6:21 PM, Eric Jacobsen wrote: >> On Wed, 12 Mar 2014 16:35:38 -0500, Tim Wescott >> <tim@seemywebsite.really> wrote: >> > ... >>> >>> Note that the sliding DFT is a kind of bandpass filter. There's a lot >>> of different bandpass filters that could be used -- the sliding DFT is >>> just the one that many non signal-processing types find to be the most >>> intuitive, or at least the easiest to accept. >> >> Well, I've found that there are many signal-processing types that seem >> to have a hard time with the sliding DFT for whatever reason, too. >> ;) >> >> > i don't have a problem with sliding DFT. and a sliding DFT for a small > subset of DFT bins is best done using Goertzel. > > but i think that neither DFT nor Goertzel are the only nor the optimal > nor the simplest way to approach this DTMF thing. > > if you want to be optimal, think of each of 16 pairs of filters as > matched filters tuned to each DTMF tone pair. back in the olden daze, > the way we were taught to approach a problem of signal detection by > matching a filter to that signal we are trying to detect. this is sorta > like M-ary communication except it's a constellation of frequency pairs > instead of something on the I and Q axes.
It's hard to realize the "sliding" part with the Goertzel, at least to my knowledge. OTOH, if you accept the fact that a Goertzel is just a band-pass filter with an infinite Q, then you can turn it into a band-pass filter with a finite Q that never needs to be reset, and you never have to mess with that "reset and test" crap. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
On 3/13/14 11:54 AM, Tim Wescott wrote:
> On Wed, 12 Mar 2014 19:03:21 -0400, robert bristow-johnson wrote: > >> On 3/12/14 6:21 PM, Eric Jacobsen wrote: >>> On Wed, 12 Mar 2014 16:35:38 -0500, Tim Wescott >>> <tim@seemywebsite.really> wrote: >>> >> ... >>>> >>>> Note that the sliding DFT is a kind of bandpass filter. There's a lot >>>> of different bandpass filters that could be used -- the sliding DFT is >>>> just the one that many non signal-processing types find to be the most >>>> intuitive, or at least the easiest to accept. >>> >>> Well, I've found that there are many signal-processing types that seem >>> to have a hard time with the sliding DFT for whatever reason, too. >>> ;) >>> >>> >> i don't have a problem with sliding DFT. and a sliding DFT for a small >> subset of DFT bins is best done using Goertzel. >> >> but i think that neither DFT nor Goertzel are the only nor the optimal >> nor the simplest way to approach this DTMF thing. >> >> if you want to be optimal, think of each of 16 pairs of filters as >> matched filters tuned to each DTMF tone pair. back in the olden daze, >> the way we were taught to approach a problem of signal detection by >> matching a filter to that signal we are trying to detect. this is sorta >> like M-ary communication except it's a constellation of frequency pairs >> instead of something on the I and Q axes. > > It's hard to realize the "sliding" part with the Goertzel, at least to my > knowledge.
oh, c'mon, it's just a filter (albeit one with a pair of poles on the unit circle). and for Goertzel, you sample the output after N samples are input. to make it sliding, you have to do it like a TIIR (them Truncated IIR filters championed by Julius Smith and Avery Wang).
> > OTOH, if you accept the fact that a Goertzel is just a band-pass filter > with an infinite Q, then you can turn it into a band-pass filter with a > finite Q that never needs to be reset, and you never have to mess with > that "reset and test" crap.
well, CIC or efficiently-implemented moving sum or moving average filters have sorta the same issue. with fixed-point arithmetic, you can always subtract exactly what was added N samples ago. with floating-point (and finite precision), it's more problematic. and with feedback that has something other than +1 or -1 or similar as coefficients, it's problematic to have a critically-stable filter. so you can back off on the Q, the poles move slightly inside the unit circle. hey Tim, if i can find it, i have a pdf of a quick math document i made for designing 1st and 2nd-order TIIRs. do you want it? (since they're just bits, i'll send it anyway and you can toss it into the trash if you want.) -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On Thursday, March 13, 2014 1:05:08 PM UTC-4, robert bristow-johnson wrote:
> On 3/13/14 11:54 AM, Tim Wescott wrote: > > > On Wed, 12 Mar 2014 19:03:21 -0400, robert bristow-johnson wrote: > > > > > >> On 3/12/14 6:21 PM, Eric Jacobsen wrote: > > >>> On Wed, 12 Mar 2014 16:35:38 -0500, Tim Wescott > > >>> <tim@seemywebsite.really> wrote: > > >>> > > >> ... > > >>>> > > >>>> Note that the sliding DFT is a kind of bandpass filter. There's a lot > > >>>> of different bandpass filters that could be used -- the sliding DFT is > > >>>> just the one that many non signal-processing types find to be the most > > >>>> intuitive, or at least the easiest to accept. > > >>> > > >>> Well, I've found that there are many signal-processing types that seem > > >>> to have a hard time with the sliding DFT for whatever reason, too. > > >>> ;) > > >>> > > >>> > > >> i don't have a problem with sliding DFT. and a sliding DFT for a small > > >> subset of DFT bins is best done using Goertzel. > > >> > > >> but i think that neither DFT nor Goertzel are the only nor the optimal > > >> nor the simplest way to approach this DTMF thing. > > >> > > >> if you want to be optimal, think of each of 16 pairs of filters as > > >> matched filters tuned to each DTMF tone pair. back in the olden daze, > > >> the way we were taught to approach a problem of signal detection by > > >> matching a filter to that signal we are trying to detect. this is sorta > > >> like M-ary communication except it's a constellation of frequency pairs > > >> instead of something on the I and Q axes. > > > > > > It's hard to realize the "sliding" part with the Goertzel, at least to my > > > knowledge. > > > > oh, c'mon, it's just a filter (albeit one with a pair of poles on the > > unit circle). and for Goertzel, you sample the output after N samples > > are input. to make it sliding, you have to do it like a TIIR (them > > Truncated IIR filters championed by Julius Smith and Avery Wang). > > > > > > > > OTOH, if you accept the fact that a Goertzel is just a band-pass filter > > > with an infinite Q, then you can turn it into a band-pass filter with a > > > finite Q that never needs to be reset, and you never have to mess with > > > that "reset and test" crap. > > > > well, CIC or efficiently-implemented moving sum or moving average > > filters have sorta the same issue. with fixed-point arithmetic, you can > > always subtract exactly what was added N samples ago. with > > floating-point (and finite precision), it's more problematic. > > > > and with feedback that has something other than +1 or -1 or similar as > > coefficients, it's problematic to have a critically-stable filter. so > > you can back off on the Q, the poles move slightly inside the unit circle. > > > > hey Tim, if i can find it, i have a pdf of a quick math document i made > > for designing 1st and 2nd-order TIIRs. do you want it? (since they're > > just bits, i'll send it anyway and you can toss it into the trash if you > > want.) > > > > -- > > > > r b-j rbj@audioimagination.com > > > > "Imagination is more important than knowledge."
It turns out to be quite easy to implement a sliding goertzel - especially if all you want is the magnitude function. Drive the recursive section of a goertzel with your data. Subtract from that your delayed data times the goertzel matrix raised to the block length power. From here you find the magnitude as normal. Clay
>The last ten pages here:
http://www.claysturner.com/dsp/digital_resonators.=
>pdf > >Give the recipe for a generalized goertzel algorithm. > >I have derived the full generalized goerzel algo. If needed I can post it
s=
>omewhere. > >Clay
Thanks Clay for posting that link. That is from the paper you presented at the comp dsp 2010 conference. Ouch, almost 4 years have gone by that fast! _____________________________ Posted through www.DSPRelated.com
clay@claysturner.com writes:
> [...] times the goertzel matrix raised to the block length power.
Numerical issues? -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
On Thu, 13 Mar 2014 21:17:24 -0400, Randy Yates wrote:

> clay@claysturner.com writes: >> [...] times the goertzel matrix raised to the block length power. > > Numerical issues?
You beat me to it. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Not much worry about numerical issues. Recall a goertzel matrix has a unity determinant and if chosen correctly it is orthogonal or nearly so at the frequency of interest. Hence its condition number is small. It has unity magnitude eigenvalues so raising them to a high power is a simple application of DeMoivre's theorem. But to overcome a potential error just move the poles just inside of the unit circle and then trash decays away. Now you know one of the reasons I've investigated many different oscillator topologies.

Clay
On 3/14/14 1:48 AM, clay@claysturner.com wrote:

> But to overcome a potential error just move the poles just inside of the unit circle and then trash decays away.
and to make it a sliding Goertzel, you have to truncate the impulse response that you get, even after moving the poles slightly into stable territory. you do that with a Truncated IIR (TIIR) topology. (remember that TIIRs are really FIRs implemented with feedback and those two barely stable poles will be canceled with zeros. again, for anyone interested, i have a 4-page doc that tells you quicky how to slap together a TIIR assuming you already know how to do the IIR that's getting T'd.) you don't have to do the TTIR thing if your Goertzel is not sliding, but then, every N samples, you have to reset the accumulator. the TIIR version is fully LTI. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
>> But to overcome a potential error just move the poles just inside of the
unit circle and then trash decays away.
> >and to make it a sliding Goertzel, you have to truncate the impulse >response that you get, even after moving the poles slightly into stable >territory. you do that with a Truncated IIR (TIIR) topology. (remember >that TIIRs are really FIRs implemented with feedback and those two >barely stable poles will be canceled with zeros. again, for anyone >interested, i have a 4-page doc that tells you quicky how to slap >together a TIIR assuming you already know how to do the IIR that's > >-- > >getting T'd.) > >you don't have to do the TTIR thing if your Goertzel is not sliding, but >then, every N samples, you have to reset the accumulator. the TIIR >version is fully LTI. >
>r b-j rbj@audioimagination.com > >"Imagination is more important than knowledge." >
I'm interested. I would like to see your 4 page document on implementing the TIIR topology. _____________________________ Posted through www.DSPRelated.com