# Connexions

You are here: Home » Content » DTMF Detection

### Lenses

What is a lens?

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

#### Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
• TI DSP

This module is included inLens: Texas Instruments DSP Lens
By: Texas Instruments

Click the "TI DSP" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

#### Also in these lenses

• Lens for Engineering

This module is included inLens: Lens for Engineering
By: Sidney Burrus

Click the "Lens for Engineering" link to see all content selected in this lens.

### Recently Viewed

This feature requires Javascript to be enabled.

### Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

# DTMF Detection

Module by: Jacob Fainguelernt. E-mail the author

Summary: This module shows the implementation of a DTMF detector using the DSK6713. The detector is desgined using Simulink.

## Introduction

The Dual-tone multi-frequency (DTMF) signaling method was developed originally to replace pulse (Dial Pulse or DP in the U.S.) and loop disconnect (LD) signaling methods to dial numbers, in order to shorten the holding time of the switch during dialing , specially for long distance calls.

DTMF signaling uses two tones to represent each key on the touch pad. There are 12 distinct tones1 (Please refer to Table 1). When any key is pressed the tone of the column and the tone of the row are generated. As an example, pressing the '5' button generates the tones 770 Hz and 1336 Hz. The frequencies were chosen to avoid harmonics: no frequency is a multiple of another, the difference between any two frequencies does not equal any of the frequencies, and the sum of any two frequencies does not equal any of the frequencies.

 . 1209 Hz 1336 Hz 1477 Hz 697 Hz 1 2 3 770 Hz 4 5 6 852 Hz 7 8 9 941 Hz * 0 #

Table 1- DTMF frequencies

The low frequencies are referred as rows, The higher frequencies are referred as columns.

This example will show the implementation of a DTMF receiver using the DSK6713. The DTMF receiver will be based on the simulation model used in the Simulink demo. A graphic user interface (GUI) will also be created to activate the DSK6713. DTMF digits will be sent from the PC sound card.

## Simulation

### The Simulation Model

Figure 1 shows the model used to simulate DTMF detection and generation.

The DTMF generator is composed by 7 sine wave generators, corresponding to the 7 DTMF frequencies. The oscillators are grouped as described in Table 1. The oscillators’’ outputs are multiplexed and summed (Please refer to Figure 2). Upon selection of a digit to be transmitted, the correspondent oscillators are activated.

The DTMF detection comprises two processes, the frequency detection algorithm itself, and a leading edge detection subsystem.

The frequency detection subsystem measures the energy present at the seven frequencies, and calculates the digit by taking the component of maximum energy in the lower and upper frequency groups. The process is shown in Figure 3. This process runs continuously; however the calculated digit is reported only if its energy is above a threshold as determined by the leading edge detection subsystem. The DTMF detection process is shown in Figure 4.

### Running the Simulation

• Open the simulation model “DTMF.mdl”
• In order to select the digit double click the DTMF generator subsystem and enter the digits to be sent as follows:
• Activate the simulation, the detected digits will be displayed as shown:

## Real Time Implementation

The real-time implementation environment is shown in Figure 7. The DTMF generation will be performed in MATLAB® and sent to the DSK through the PC sound card. The detected digits will be reported through RTDX. A graphic user interface (GUI) will be built to activate the transmitter, and display the reported digits.

The DTMF receiver will be based on the DTMF receiver from the simulation model, with the following changes:

• Samples will be read from the Analog to Digital Converter, and filtered by a DC removal block2
• Digits will be reported through RTDX.
• Addition of the DSK6713 target preference

• Open the simulation model “DTMF.mdl”, remove all the blocks besides the DTMF receiver block.
• The “TO RTDX” will be used to report the detected digits to the PC. Add it to your model:
• Add the “Digital Filter” and “Gain” blocks for DC removal:
• The DTMF receiver model is shown Figure 17:
• Save the model as "DTMF_DSK6713.mdl".
• Built the model.

### Functionality

The GUI will perform the following functions:

• Initialization: Initialize the RTDX interface and loading the DTMF Receiver program we have built in the last section to the DSK.
• Generate the DTMF signal samples: The GUI will enable the user to select a sequence of 11 digits3 to be transmitted. It will create the samples of the DTMF signal based on this selection, and send them to the sound card.
• Display the detected digits reported by the DSK

### Description

The desired GUI is shown in Figure 18

It will enable the user to:

• Dial the digits: every digit dialed is added to a specific buffer, and displayed under the “Dialed Digits” label.
• Delete the last digit
• Clear all the digits
• Send: Create the DTMF signal from the digits selected4. A dual-tone signal will be created for each digit. Silence will be inserted between consecutive digits. This signal is sent to the sound blaster using the “sound” command in MATLAB.
• Display: Digits reported by the DSK will be displayed under the “Detected Digits” label.

### The Procedure

• Activate the GUIDE (Graphic User Interface Integrated Development Environment in MATLAB.
• Open a new GUI and name it DTMF
• Add 12 Push buttons for the keypad and set their String property to the proper values (0-9,*,#) using the property inspector.
• Add the Send, Clear and Delete buttons
• Add 2 Edit Texts objects for display
• You may now add the labels (static texts):
• “Dialed Digits”
• “Detected Estimation”
• “DTMF Transmitter”
• Press the “play” button to open the MATLAB script. Name the script “DTMF.m”.
• Enter the Initialization (DTMF_OpeningFcn ) as shown:

function DTMF_OpeningFcn(hObject, eventdata, handles, varargin)
modelName = gcs;
CCS_Obj = connectToCCS(modelName);
% Identify RTDX channel names/modes
chan_struct(1).name = 'OutputDigit';
chan_struct(1).mode = 'r';
handles.RTDX_chan1=chan_struct(1);
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize= 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
CodegenDir = fullfile(pwd, ['DTMF_RT' '_c6000_rtw']);
OutFile = fullfile(CodegenDir, ['DTMF_RT' '.out']);
%Load is needed for RTDX setup
% Set up RTDX
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
handles.pipe=r;
handles.CCS_Obj=CCS_Obj;
handles.output = hObject;
CCS_Obj.run;
% Enable all RTDX channels
r.enable('all');
%The buffer that stores the user input digits
A=[];
handles.A=A;
% flag that tells if the gui needs to clear the dialed string or
%the next digit joins the previous string:
handles.initFlag=0;
handles.maxSize=11;
handles.freqTable=generateTable();
% Update handles structure
guidata(hObject, handles);


This function will run after activating the GUI. It will then load the DSK, initialize the RTDX interface, and initialize a table of samples for each digit, by calling the generateTable auxiliary function:


function res=generateTable()
t=(1:256*6)/8192;
res(1,:)=sin(2*pi*697*t)+sin(2*pi*1209*t);
res(2,:)=sin(2*pi*697*t)+sin(2*pi*1336*t);
res(3,:)=sin(2*pi*697*t)+sin(2*pi*1477*t);
res(4,:)=sin(2*pi*770*t)+sin(2*pi*1209*t);
res(5,:)=sin(2*pi*770*t)+sin(2*pi*1336*t);
res(6,:)=sin(2*pi*770*t)+sin(2*pi*1477*t);
res(7,:)=sin(2*pi*852*t)+sin(2*pi*1209*t);
res(8,:)=sin(2*pi*852*t)+sin(2*pi*1336*t);
res(9,:)=sin(2*pi*852*t)+sin(2*pi*1477*t);
res(10,:)=sin(2*pi*941*t)+sin(2*pi*1209*t);
res(11,:)=sin(2*pi*941*t)+sin(2*pi*1336*t);
res(12,:)=sin(2*pi*941*t)+sin(2*pi*1477*t);

• Enter the handle Button function:

function handleButton(hObject,handles,k)
%get the digits buffer
A=handles.A;
%if we have to erase so we are doing it here:
if handles.initFlag==1
handles.initFlag=0;
A=[];
end
%check if the string is too long with the new digit:
if length(A)==handles.maxSize
fprintf('Error: too many digits\n');
return;
end
%concatenate the new digit to the existing buffer
A=[A k];
handles.A=A;
set(handles.text1, 'String', strrep(strrep(strrep(int2str(A),'10','*'),'11','0'),'12','#'));
guidata(hObject,handles);

% invoked when the user dials '1':
function pushbutton1_Callback(hObject, eventdata, handles)
handleButton(hObject,handles,1);
% invoked when the user dials '2':
function pushbutton2_Callback(hObject, eventdata, handles)
handleButton(hObject,handles,2);
. . .


This function will be activated, every time the user pushes a digit button in the keypad. The digit will be displayed under the “Dialed Digits” label.

• The following function will be activated by the “Send” button:

%input: digits and handle to the signals table
%output: buffer that contains the DTMF samples for the digits.
function res=buildXmt(handles,A)
res=[];
for k=1 : length(A)
freqTable=handles.freqTable;
%place the next digit and then zeros (space)
res=[res freqTable(A(k),:) zeros(1,256*6);];
end

%The Send Button Handler:
function pushbutton13_Callback(hObject, eventdata, handles)
r=handles.pipe;
A=handles.A;
if length(A)==0
return
end
% if dialed less than 11 digits pad to 11 digits
if length(A)<11
A=[A ones(1,11-length(A))];
end
%build the Send Buffer
xmt=0.5*buildXmt(handles,A);
%Transmit DTMF signals buffer
sound(xmt,8192)
%Wait for end of detection
pause(4)
%read the digits from the rtdx:
num_of_msgs = msgcount(r,'OutputDigit');
r.flush('OutputDigit',num_of_msgs-1);

%Update the upper label with the digits read from dsk estimation
set(handles.text4, 'String', strrep(strrep(strrep(int2str(y),'10','*'),'11','#'),'20','*'));
handles.initFlag=1;
guidata(hObject, handles);


It will generate the DTMF samples Buffer, based on the “User Dialed” information. The samples will be sent to the sound-card. The program will then monitor the RTDX channel to receive the digits reported by the DSK.

• Enter the functions activated by the “Clear” and “delete” push buttons:

% Delete one digit.
function pushbutton14_Callback(hObject, eventdata, handles)
A=handles.A;
if length(A)==0
return
end
A=A(1:end-1);
set(handles.text1, 'String', strrep(strrep(strrep(int2str(A),'10','*'),'11','0'),'12','#'));
handles.A=A;
guidata(hObject, handles);

%Clear all the dialed digits.
function pushbutton15_Callback(hObject, eventdata, handles)
A=handles.A;
A=[];
set(handles.text1, 'String',
strrep(strrep(strrep(int2str(A),'10','*'),'11','0'),'12','#'));
handles.A=A;
guidata(hObject, handles);


### Running the Example

The system used to run this example is shown in Figure 7.

Activate the GUI (DTMF.fig). Enter an array of digits and compare them to those detected by the DSK.

## Things to Try

The original algorithm (simulation) runs in a "noiseless" environment. You are invited to check the performance of the real-time model, and eventually change the algorithm to reduce its sensitivity to noise.

You may also add new buttons for DTMF parameters (level, frequency deviation, etc …), and test the DTMF receiver performance against these parameters.

## Footnotes

1. The DTMF method defines four additional digits: “A”, “B”,”C” & “D”. Most of the systems today do not use those digits.
2. This block is necessary to convert the unipolar format of the samples to a 2’s complement format for processing by the DSP.
3. If the user selects less than 11 digits, the sequence is padded with DTMF digit '1'.
4. The DSK operates with a buffer of 11 digits so if the user dialed less then 11 digits we are padding them to 11 in the MATLAB.

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks