DTMF Encoder Decoder Design Using FIR Banks
DTMF Encoder Decoder Design Using FIR Banks
by S.Sircar
Introduction
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
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.
1
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.
2
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.
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.
3
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
Analysis Results
4
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.
5
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.
6
Source Code for DTMF Encoder/Decoder
global dtmf_rfreq
global dtmf_cfreq
global dtmf_key
global dtmf_fs
global dtmf_silencelen
global dtmf_tonelen
% Sampling Frequency
dtmf_fs = 8000;
disp(['DTMF samplerate set to ' num2str(dtmf_fs) ' Hz']);
%Duration of the Tone to generate
dtmf_tonelen = round(dtmf_fs * 0.50); % Convert length from seconds to samples
disp(['DTMF tone length set to ' num2str(dtmf_tonelen) ' samples']);
%Insert Silence lengths between tones for detection
dtmf_silencelen = round(dtmf_fs * 0.20); % Convert length from seconds to samples
disp(['DTMF break length set to ' num2str(dtmf_silencelen) ' samples']);
function Y = gensino(f,n,Ts)
X = zeros(1,length(n));X(1) = 1; % generate the impulses
A = [1 -2*cos(2*pi * f *Ts) 1];
B = [0 sin(2*pi * f *Ts) 0 ];
Y = filter(B,A,X);
7
Code for DTMF Encoder
function encodedTones = dtmfe(num)
% This function translates key pressed in digital telephone keypad to corresponding
% dual tone frequencies
% Example encodedTones = dtmfe('5670531')
% 567031 is string of numbers pressed. The function converts them to their
% corresponding dual tones as per defined in dtmf main (FH,FL)
%
% Shiladitya Sircar 2002
% DSP Course Project
%Bring the global variables defined in dtmfmain to the scope of this function
global dtmf_rfreq
global dtmf_cfreq
global dtmf_key
global dtmf_fs
global dtmf_silencelen
global dtmf_tonelen
% Can use the setparameter function in order to just evaluate this function
% to do this just un-comment the setparameter. This script will set up the global
%variable required to execute dtmf encoding.
%setparameter;
num = sprintf('%s',num);
Ts = 1/dtmf_fs; % Sample length
n = 0:dtmf_tonelen-1; % Vector to sample from 0 < n <=N-1
%Total Number of Elements required in the ecoded vector space
numcount = length(num);
tlen = numcount*(dtmf_tonelen + dtmf_silencelen);
%Generate the vector first that contains the tones
encodedTones = zeros(1,tlen);
for i = 1:numcount
% Find out which column and row this key belongs to
if ( isempty(row) )
disp('One of the Key Pressed is not a valid DTMF Key');
en d
8
Code for DTMF Decoder
function digitstr = dtmfd(encstr)
% This function translates the encoded tones to corresponding
% keys/key that are pressed.
% Example digitstr = dtmfd(vec)
% Where vec is the vector that contains the encoded tones
%
% Shiladitya Sircar 2002
% DSP Course Project
global dtmf_rfreq
global dtmf_cfreq
global dtmf_fs
global dtmf_silencelen
global dtmf_tonelen
global dtmf_key
% Can use the setparameter function in order to just evaluate this function
% to do this just un-comment the setparameter. This script will set up the global
%variable required to execute dtmf encoding.
%setparameter;
dtmf_digilen = length(encstr)/(dtmf_tonelen+dtmf_silencelen);
% Loop through each column and check if the column-i frequency exist in the signal
for i = 1:4
% Calculate filter coefficients for the bandpass filter for column frequencies
% given the center frequency
hh = 2/L*cos(2*pi*dtmf_cfreq(i)*filt_n/dtmf_fs);
ss = mean(conv(encstr_frag,hh).^2) > mean(encstr_frag.^2)/5;
if (ss)
col = i;
9
break % we already have our column - no need to check the rest
en d
en d
numstr(1,deco_seq) = dtmf_key(row,col);
en d
digitstr = numstr;
% Sampling Frequency
dtmf_fs = 8000;
disp(['DTMF samplerate set to ' num2str(dtmf_fs) ' Hz']);
%Duration of the Tone to generate
dtmf_tonelen = round(dtmf_fs * 0.50); % Convert length from seconds to samples
disp(['DTMF tone length set to ' num2str(dtmf_tonelen) ' samples']);
%Insert Silence lengths between tones for detection
dtmf_silencelen = round(dtmf_fs * 0.01); % Convert length from seconds to samples
disp(['DTMF break length set to ' num2str(dtmf_silencelen) ' samples']);
%sound(encodedTones,dtmf_fs);
10
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('FFT Amplitude Spectrum')
%Return The Decoded Tones
Decoded_Digits = dtmfd(encodedTones);
if (strncmp(Decoded_Digits,num2encode,length(num2encode)) == 1)
disp(' ');
disp('Succesfully decoded the dialed number');
disp(' ');
disp('The dialed Telephone Number was'); num2encode
disp(' ');
disp('The Decoded Telephone Number is '); Decoded_Digits
else
disp('Error In Decoding'); Decoded_Digits
en d
11