DTMF ThumbnailThis was a simple Matlab project, but it can be very handy for generating touch tones for telephony hacks. In fact, try it out, you can dial your phone just by holding it up to the speaker!

Introduction

The purpose of signals is to communicate information. Some of this information is designed for humans to receive. Pictures and music are some examples. Most others are intended for computers or machines to receive. In this exercise the ability to create and decode touch tones, a task that happens millions of times a day, was replicated using principles of filtering.

First touch tones had to be understood and synthesized, and then using filtering each had to be decoded to produce the original key sequence that generated it. The end result was a dialing and decoding system like that of a phone.

Generating Touch Tones

A touch tone is made up of two frequencies corresponding to the keys’ position on the grid of the phone. For instance, 5 is produce by playing a pure 1336 Hz sine wave and a pure 770 Hz sine wave simultaneously. The result is the warbly sound you hear.

Table Showing Needed Touch Tones

It was relatively simple to code a function that would cycle through a list of characters (like a phone number) and produce the corresponding waveform to simulate touch tones. The final code was as follows:

dtmfdial.m

Making Filters

The first step to decoding the touch tones was to design a set of filters whose purpose it would be to eliminate all frequencies but one. To accomplish this, a bandpass filter was used. Eight filters were constructed to correspond to the eight possible frequencies that the touch tones are made up of. Each filter had to be scaled so that the magnitude of its frequency response was equal to exactly one. The final code was as follows:

dtmfdesign.m

The frequency response of each filter is important because it shows what every possible frequency component will be scaled by. For instance, a signal with a frequency that occurs where a filter is peaking will go through virtually unmolested because it will be scaled by a factor of one. On the other hand, signals with frequencies that occur where the frequency response is very low will be almost eliminated by the filter because they will be scaled by a small number. The images below show the passbands of all 8 filters that are used.

Passbands of Filters

These filters had to be narrow enough that they would not overlap. It was imperative that each filter would only select one of the 8 frequencies that make up DTMF. Below is an image of the filters that finally accomplished that task.

Zoomed In Passbands of Filters

Making Sense of The Signal

The second phase of the decoding algorithm involved a scoring function. This function took in one impulse response of a bandpass filter and one short segment of a touch tone and determined if there was a frequency in the pass band after the two were convolved.In order to determine if a frequency was in the pass band the magnitude of the convolution was measured. If it was above 0.71 then the frequency was considered to be passed otherwise it wasn’t. The final code was as follows:

dtmfscore.m

Putting it Together

Finally, a main function was written to call the other functions. It parsed the input signal of touch tones using a program called dtmfcut, and then used loops to iterate each tone through each filter. The resulting scores from those iterations were used to decode the row and column of each key, and thus make a vector containing the original keys that were dialed. The completed program was tested by running it on a signal of synthesized touch tones. The touch tones were created with the string ‘891#40789132*DABC’ which produced a vector whose spectrogram is shown below.

Spectrogram of Output

When the program was run, it correctly reproduced the same vector. The code for the main function and dtmfcut were as follows:

dtmfrun.m
dtmfcut.m

Final Thought

Millions of people use phones many times a day and yet, very few understand what complex processes go on inside the touch tone creation and decoding process. In this exercise, that understanding at least has been obtained. However, the ideas presented have a far broader application. The ability to use FIR filters to encode and decode signals in order to accomplish goals is pretty darn important, and it was fun to do too!

For some other great projects in Matlab, check these out:

3D Vision with Stereo Cameras
Simple Robot Simulator
Neural-Net Powered Aibo Robot Project

7 thoughts on “DTMF Generator

  1. I’m glad I stumbled upon this, I’ve been looking for source code that can do something like this for a while.

    You’ve done a good job with detailing every thing as well which made it very easy to understand. One thing though, the link to dtmfdesign.m doesn’t seem to be valid any more.

Leave a Reply

Your email address will not be published.