jDTMF – a Java DTMF detection library

jDTMF – real-time, event based DTMF detection in pure java

jDTMF provides an event based DTMF tone detection library that is implemented in pure java.  The library can be used to detect DTMF tones from several sources including in real-time from a sound card.  It can also detect DTMF digits from a PCM audio file.

What is DTMF?

DTMF tones are also commonly known as “touch-tones”. Most people know these sounds as the tones that a phone makes when you press a button on the keypad.

DTMF tone encodings are defined by the presence of two simultaneous tones.

1209
Hz
1336
Hz
1477
Hz
1633
Hz
697
Hz
1 2 3 A
770
Hz
4 5 6 B
852
Hz
7 8 9 C
941
Hz
* 0 # D

For instance, the ‘3’ code is said to be present when 697Hz and 1477Hz are found to exist at the same time, above a given noise threshold and last for a duration of at least 45 milli-seconds. If only one of the frequencies is present, then the ‘3’ code has not been signaled.

In addition to the DTMF keypad tones, the DTMF specification also includes what are known as “event” frequencies.

440
Hz
480
Hz
620
Hz
350
Hz
Dial
tone
440
Hz
Ringback
(US only)
480
Hz
Busy
Signal

A Graphical DTMF Detector

This application detects DTMF “touch” tones and presents the relative magnitude of the component frequencies.

The screen-shots were taken while recording audio directly from the sound card on a windows PC. I have not attempted any code optimizations and the code is fairly hackish, but it provides a fair prototype that can be extended upon as desired.

The numbers along the left of the windows are the individual DTMF frequencies. Each frequency’s relative magnitude is displayed in individual meters to the right of each number. When the magnitude of any frequency climbs above a preset threshold the frequency number turns red, just like the values in the pictures.

dtmf_poc_B_key dtmf_poc_3_key
The ‘B’ digit is triggered only when 770Hz and 1633Hz are present at sufficient amplitude and duration. The ‘3’ digit is triggered only when 697Hz and 1477Hz are present at sufficient amplitude and duration.

The Goertzel algorithm

The Goertzel algorithm is particularly suited to detection of specific, pre-defined frequencies within a signal using a minimal number of memory and computation resources. In particular, the Goertzel algorithm has seen a lot of use detecting DTMF frequencies within audio signals. In addition to DTMF tones, the algorithm is also well suited to the detection of CTCSS (squelch tones) used by mobile two-way radio systems.  This algorithm is frequently implemented in microcontroller devices where both processing power and RAM limitations prevent the use of other algorithms such as the FFT.

WikiPedia provides a well done introductory article on the Goertzel algorithm and an example implementation in C.

Embedded System Design has a fantastic article about the Goertzel algorithm. This article provides a C
implementation of the algorithm , from which I ported the java version included in the source below…

jDTMF Library

2/25/2010:  The library is currently re-written and will be made available under a commercial license.

Goals of the rewrite include:

  • Increased performance
  • Modular design
  • Event/callback based interaction
  • More detection configuration to increase accuracy
  • JUnit test suite with audio test files for input

Copyright 2004-2010 Henry Ranch LLC.

Leave a Reply

Your email address will not be published. Required fields are marked *

*