DTMF coder / decoder
By S.Sircar
21/02/98
Source Code DTMF
Encoder/Decoder
Introduction
Analog DTMF telephone
signaling is based on encoding standard telephone
Keypad digits and symbols
in two audible sinusoidal signals of frequencies FL and FH. Thus the scheme gets
its name as dual tone multi frequency (DTMF).
|
Hz |
1209 |
1336 |
1477 |
1633 |
|
697 |
1 |
2 |
3 |
A |
|
770 |
4 |
5 |
6 |
B |
|
852 |
7 |
8 |
9 |
C |
|
941 |
* |
0 |
# |
D |
Figure 1
Each digit or symbol represented
in figure 1 has 2 distinct high and low frequency components. Thus each
high-low frequency pair uniquely identifies the corresponding telephone keypad
digit or symbol. Each key pressed can be represented as a discrete time signal
of form
dt[n]
= sin[wLn]
+ sin[wLn]
, 0 £
n £
N-1 (1)
Where N is defined as
number of samples taken. Typically in the sampling frequency used is 8khz. Thus
if the two individual frequency components of the signal can be identified then
the number dialed can be decoded.
Note :-
In this report I have used (dual tone and digit/symbols)
interchangeably but both mean the same. Dual tone means the encoded samples of
the corresponding DTMF digits/symbols.
Implementation of DTMF Encoder
The DTMF encoder is
implemented in MATLAB function dtmfe.m. The implementation is based on a
digital oscillator, that will generate sinusoidal tones at frequencies Fo
in response to an input signal x[n] = d[n].
![]()
x[n] H[n] y[n] {y[n] = x[n]*H[n]
Consider a causal filter
with
y(n) - 2*cos(2*pi * f
*Ts)y(n-1) + y(n-2) =0*x(n) sin(f)x(n-1) + 0*x(n-2).
The impulse response of
this system tells us that this indeed is a digital oscillator.
The H[n] is plotted and is
sinusoidal and hence any input to this system will oscillate as governed by the
system function.
The impulse response of the
system is shown in the figure above. This is generated by using the MATLAB
dimpulse() function for 100 points.
The encoder is coded so that
it inserts silence samples in between each digits/symbols so that they are
separated from each other.
Starting position = (total number of digits be encoded-1)*(length of each dual tone + number of silence samples to be inserted) + 1.
This information is used at
the decoding step to get each dual tone sample length and how many samples to
skip for the next digit/symbol. The
resulting waveform after encoding is shown in figure 2 below. The waveform
shows an encoded sequence of my phone number 7262527. There are 7 digits in the
dialed string and hence the waveform shows 7 distinct sub samples of the
resulting DTMF encoded waveform.

The frequency spectrum is
shown in the figure below of the dialed dtmf digits. The plot shows both sided frequency
spectrum and is simply a mirror of the base band.

Implementation of DTMF decoder
The input to the decoder is a vector containing DTMF tones that are
encoded by the encoder. A FIR (Finite Impulse Response) band pass filter is implemented
which is centered at the frequencies of interest for decoding each key pressed.
The decoding process takes place in iterative form. Starting from row 1 to row
4,in each iteration a FIR band pass filter centered at each FH is
implemented and the signal strength around the band is compared against a
threshold. If the mean amplitude of the filter output is more than a set
threshold, the frequency component tested is considered to be strong. To
prevent cancellation of the sinusoids while calculating the mean, the values
are squared.
Similar approach is taken
in order to find the FL present in the signal. Once a row-column
pair has been detected the digit encoded is uniquely identified. This approach
has been taken in order to suppress the effects of noise in the encoded signal.
This approach has a significant advantage that is the
band pass filter coefficients can be manipulated individually to produce a narrower
filter and detection
process can be enhanced in presence of noise.
In order to decode
a string of dialed symbols/digits the decoding step assumes that the encoder
has inserted silence between each dual tone. Each dual tone length is tracked
and silence lengths are calculated. The decoding step loops over for the number
of digits to be decoded that is easily calculated from the total length of the
signal divided by the sum of individual dual tone length and silence length.
Thus after decoding the first digit certain number of samples are skipped and
the next set of samples are decoded. This means sampling and decoding a small
part of the resulting waveform in each iteration, where one iteration relates
to one key pressed.
Conclusion
No attempt has
been made to test the system performance in a noisy environment. However, since
I have used a band pass filter in order to decode every DTMF tone the band pass
filter length can be manipulated in order to get good results in noisy
environment. A filter of length L (L=128 currently used) can be used to
increase the immunity of noise (type of noise). However a higher value of L
would detect tones even of lower amplitude better, but also increases the
chance of error in detection. This matched filter approach definitely
reduces the mean square error between two bands of detection. The system has
been tested and works according to specification in a noise free environment.
Analysis Results
Consider
Detecting digit 4 of DTMF which comprise of Fl = 770, Fh = 1209.
Filter
coefficients and frequency response of 770 hz center frequency band pass FIR
filter.

Frequency response of the
770 hz band pass filter is shown in the plot below.

Filter
coefficients and frequency response of 1209 hz center frequency band pass FIR
filter.

Frequency response of the
770 hz band pass filter is shown in the plot below.

Suppose the frequency we are looking for is 770hz
and 1209 hz in order to detect dialed digit 4. The decoding takes place by implementing
a band pass filter at every iteration step looking for a particular Fl and Fh.
The decoded digit in the following diagram is 4. Take a look at how 770hz and
1209 hz are allowed to pass from the band pass filter.