Zoom Icon

DTMF decoding

From UIC

DTMF decoding a naive approach

Contents


Infos
Author: epokh
Email: matrix.epokh@gmail.com
Website: www.epokh.org/drupy
Date: 18/12/2007 (dd/mm/yyyy)
Level: Quite hard
Language: English Image:Flag_ English.gif
Comments:



Introduction

Dual-tone multi-frequency (DTMF) signalling is used for telephone signalling over the line in the voice-frequency band to the call switching center. The version of DTMF used for telephone tone dialing is known by the trademarked term Touch-Tone, and is standardised by ITU-T Recommendation Q.23. Other multi-frequency systems are used for signaling internal to the telephone network.

As a method of in-band signalling, DTMF tones were also used by cable television broadcasters to indicate the start and stop times of local commercial insertion points during station breaks for the benefit of cable companies. Until better out-of-band signaling equipment was developed in the 1990s, fast, unacknowledged, and loud DTMF tone sequences could be heard during the commercial breaks of cable channels in the United States and elsewhere.


Tools & Files


Essay

DTMF keypad

The DTMF keypad is laid out in a 4×4 matrix, with each row representing a low frequency, and each column representing a high frequency. Pressing a single key (such as '1' ) will send a sinusoidal tone of the two frequencies (697 and 1209 hertz (Hz)). The original keypads had levers inside, so each button activated two contacts. The multiple tones are the reason for calling the system multifrequency. These tones are then decoded by the switching center to determine which key was pressed.

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

DTMF after sampling

Since the touch tone waveform is sampled at 1 KHz, from Table 1 we can see that the signal is undersampled. When the FFT (monolateral version) is performed, the actual frequencies will not be mapped correctly onto the FFT plot. For a signal above the sampling frequency, e.g. a signal at frequency of 1.2 KHz will be undersampled and mapped to a frequency of $1.2 KHz - 1 KHz = 200 Hz$. For a signal in the region between $F_{s/2}=500Hz$ sampling frequency and the sampling frequency, e.g. a signal at frequency of 700 Hz will be undersampled and mapped to a frequency of $abs(700 Hz - 1 KHz) = 300 Hz$. The equivalent table becomes:

X 209 Hz 336 Hz 447 Hz 663 Hz
303 Hz 1 2 3 A
230 Hz 4 5 6 B
148 Hz 7 8 9 C
59 Hz * 0 # D

Cleaning the signal

The first operation is to remove the voltage offset and some noisy low frequencies from the original signal in figure:

The matlab code that do the operation is:

clf;
clc;

time=number1(:,1);
y=number1(:,2);

% Sampling frequency: signal time is reported to the original one
Fs=1000;
Fsmax=Fs/2;
Ts=1/Fs;
tmax=(time(end)-time(1))*Ts
tsec=0:Ts:tmax;

figure(1)
subplot(2,1,1)
plot(tsec,y);
title('Original signal');
xlabel('Time')
subplot(2,1,2)
y=y-mean(y);
plot(tsec,y);

% A simple way to remove the offset
title('Signal with offset removed');
xlabel('Time (s)')
%remove the baseline noise
fsh=Fs/2;
w1=10/fsh;
hpass=fir1(128,w1,'high');
ynodc=filter(hpass,1,y);
subplot(3,1,2)
title('Signal high pass filtered at 10 Hz');
plot(time,ynodc);
xlabel('Time (s)');
%remove the spkes
subplot(3,1,3)
fftPlot(tsec,ynodc);
title('FFT of the filtered signal');
xlabel('Frequency (Hz)');

An high pass filter with a cut off frequency of 10 Hz remove the small oscillation from the baseline level (remember however to stay away from the folded frequency of 59 Hz!). The cleaned signal looks like in figure:

Chunking the signal

To chunk the signal we can use the spikes produced by the button pression (a positive and negative voltage peak) to detect the begining and ending of every composed tone. Selecting the proper threshold as in the code:

% Two thersholds one for the positive and one for the negative spike
% They are useful to split the tone
figure(2)
thresholdH=510;
thresholdL=-360;
vpeakH=find(y>thresholdH);
vpeakL=find(y<thresholdL);
digits=length(vpeakH);

In this case we have 11 numbers. One we found the index to split the signal, a cycle will decode the tones:

% in this way we find the digited numbers and print one by one
hold off;
for k=1:1:digits
tempy=ynodc(vpeakH(k)+1:vpeakL(k)-1);
tempt= time(vpeakH(k)+1:vpeakL(k)-1);
subplot(2,1,1)
plot(tempt,tempy,'r');
subplot(2,1,2)
tmax=(tempt(end)-tempt(1))*Ts;
tsec=0:Ts:tmax;
[fss,Y,deltaFs]=fftPlot(tsec,tempy);
lookup(Y,Fs,deltaFs);
%%dtmf=[dtmf tempy];
%%tt=[tt tempt];
input('next digit: ');
end

Tone decoding example

Considering the first tone, the monolateral FFT is computed: as we can see the two biggest frequencies are 335 Hz and 52.6 Hz. Computing the minimum error in the sampled table we decode them to 336 Hz and 59 Hz with an error of $e_{1}=1$ and $e_{2}=6.4$ that give us the number 0.

Tones 1:biggest frequecies of 335 Hz and 52.6 Hz


Considering the second tone, the monolateral FFT is computed: as we can see the two biggest frequencies are 333 Hz and 306 Hz. Computing the minimum error in the sampled table we decode them to 336 Hz and 303 Hz with an error of $e_{1}=3$ and $e_{2}=3$ which give us number 2.

Tones 1:biggest frequecies of 306 Hz and 333 Hz


Considering the second tone, the monolateral FFT is computed: as we can see the two biggest frequencies are 332 Hz and 53.8 Hz. Computing the minimum error in the sampled table we decode them to 336 Hz and 59 Hz with an error of $e_{1}=4$ and $e_{2}=5.2$ which give us again number 0.

Tones 1:biggest frequecies of 332 Hz and 53.8 Hz


Reply the procedure for the next tones.

How to plot the spectrum

To plot the monolateral FFT I used the following code:

function [fss,halfASpect,deltaFs]=fftPlot(tsec,ecg)
% Compute the FFT on the sampled signal
fftSpect=fft(ecg);
% number of samples are
nsamp=length(tsec);
% The fft transform coeffs are simmetric so we take only the half
hindex=ceil(nsamp/2);
halfSpect=zeros(1,hindex);
halfSpect(1:hindex)=(nsamp/2)*fftSpect(1:hindex);
% The frequency intervals are spaced by deltaF
% The fft consider the signal as periodic: in our case the signal last for
% tsec(end) approx 32 seconds
deltaFs=1/tsec(end);
fss=0:deltaFs:(hindex-1)*deltaFs;
halfASpect=abs(halfSpect);
bar(fss,halfASpect);
xlabel('Frequency   (Hz)');
ylabel('FFT magnitude');
end

How to auto detect the composing frequencies

The algorithm partially implemented to decode the frequencies is: 1) consider the biggest frequency compononent in the spectrum 2) calculate the distance between it and all the other 4x4=16 components 3) compare the minimum distance with a threshold: according to the ITU-T standards the frequency error must be under 1.5\%. If the condition is satisfied one component is found 4) remove the biggest component and go on step 1 5) stop when 2 frequencies are found

A partial code to implement the algorithm is:

function lookup(Y,Fs,deltaFs)

% low frequency table
fL=[941,852,770,697];
% high frequency table
fH=[1209, 1336,1447,1633];
% folding frequencies are:

FL=abs(fL-Fs*ones(1,length(fL)));
FH=abs(Fs*ones(1,length(fH))-fH);

% Lookup table
% M=[1,2,3,'A';4,5,6,'B';7,8,9,'C';'*',0,'#','D'];
M=[1,2,3,-1;4,5,6,-1;7,8,9,-1;-1,0,-1,-1];
% Take the biggest components one by one
biggest=0;
minsL=[];
minsH=[];
for k=1:1:length(Y)
    [biggest,index]=max(Y);

    % delete that component from Y
      Y(index)=0;
      % find the corresponding frequency
      freq=index*deltaFs;
            freqV=freq*ones(1,length(FL));

      fdiffH=abs(freqV-FL);
      %check the difference for the minimum frequencies
      fdiffL=abs(freqV-FL);

      [minL,Lindex]=min(fdiffL);
      minsL=[minsL minL];
      fdiffH=abs(freqV-FH);
      [minH,Hindex]=min(fdiffH);
      minsH=[minsH minH];
            %search only in the upper spectrum
      if(freq>300)
            Lindex=-1;
      end
      if(freq<200)
              Hindex=-1;
      end
     
    if(Lindex >0 && Hindex>0)
       break;
    end
     
end
 fprintf('Detected digit is: %s \n',num2str(M(Lindex,Hindex)));
end

An analog approach

Beside the Goertzel algorithm, another digital or analog approach is to use banck of 8 pass band filters centered on the frequencies of table 1 (if analog) or of the table 2 (if digital).


Note Finali

See also

   * Selective calling (use of DTMF in two-way radio)
   * Pulse dialing
   * Rotary dial
   * Telephone keypad
   * Goertzel algorithm (used for DTMF detection/decoding)
   * Multi-frequency



Disclaimer

I documenti qui pubblicati sono da considerarsi pubblici e liberamente distribuibili, a patto che se ne citi la fonte di provenienza. Tutti i documenti presenti su queste pagine sono stati scritti esclusivamente a scopo di ricerca, nessuna di queste analisi è stata fatta per fini commerciali, o dietro alcun tipo di compenso. I documenti pubblicati presentano delle analisi puramente teoriche della struttura di un programma, in nessun caso il software è stato realmente disassemblato o modificato; ogni corrispondenza presente tra i documenti pubblicati e le istruzioni del software oggetto dell'analisi, è da ritenersi puramente casuale. Tutti i documenti vengono inviati in forma anonima ed automaticamente pubblicati, i diritti di tali opere appartengono esclusivamente al firmatario del documento (se presente), in nessun caso il gestore di questo sito, o del server su cui risiede, può essere ritenuto responsabile dei contenuti qui presenti, oltretutto il gestore del sito non è in grado di risalire all'identità del mittente dei documenti. Tutti i documenti ed i file di questo sito non presentano alcun tipo di garanzia, pertanto ne è sconsigliata a tutti la lettura o l'esecuzione, lo staff non si assume alcuna responsabilità per quanto riguarda l'uso improprio di tali documenti e/o file, è doveroso aggiungere che ogni riferimento a fatti cose o persone è da considerarsi PURAMENTE casuale. Tutti coloro che potrebbero ritenersi moralmente offesi dai contenuti di queste pagine, sono tenuti ad uscire immediatamente da questo sito.

Vogliamo inoltre ricordare che il Reverse Engineering è uno strumento tecnologico di grande potenza ed importanza, senza di esso non sarebbe possibile creare antivirus, scoprire funzioni malevoli e non dichiarate all'interno di un programma di pubblico utilizzo. Non sarebbe possibile scoprire, in assenza di un sistema sicuro per il controllo dell'integrità, se il "tal" programma è realmente quello che l'utente ha scelto di installare ed eseguire, né sarebbe possibile continuare lo sviluppo di quei programmi (o l'utilizzo di quelle periferiche) ritenuti obsoleti e non più supportati dalle fonti ufficiali.