You are on page 1of 6

DTMF Decoder using

MATLAB
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share
a project named as DTMF Decoder using MATLAB. In this project, I have designed a keypad
in MATLAB using the GUI functionality of MATLAB. After designing the keypad, I have
assigned a tune to each of these buttons. Obviously the tune attached to each button is
different and when we press any of these buttons, then the MATLAB recognizes the
respective button.
This project is designed in MATLAB and I have tested it on MATLAB 2009 and MATLAB 2014
and it works fine on both of them. Code is given below in this tutorial for download. f you got
problem in it then ask in comments and I will try to resolve them. So, let’s get started with
DTMF decoder in MATLAB.

DTMF DECODER USING MATLAB

 You can download the complete code by clicking the below button:
https://www.theengineeringprojects.com/MATLABProjects/DTMF%20Decoder%20us
ing%20MATLAB.rar
 In this download package, you will get three files and you need to run the file named as
decoder.m.
 When you run the file named as decoder.m, it will start the GUI which will look something
as shown in below figure:
 That’s the GUI used for DTMF Decoder using MATLAB.
 You can see a keypad is shown in the above GUI, now I have assigned a specific tune to
each of these buttons and the code for assigning this tune is as follows:

1 t=[0:0.000125:.05];
2 fs=8000;
3 f1=770;f2=1477;
4 y1=.25*sin(2*pi*f1*t);
5 y2=.25*sin(2*pi*f2*t);
6 y=y1+y2;sound(y,fs)

 So, you can see in the above code that I have generated a sine wave and then created a
sound using that sine wave.
 So, we have such sounds assigned to each of these buttons.
 Now once button is pressed, the respective sound will be activated and rite after that
sound, I have added a subroutine for decoding that sound.
 This subroutine is placed in a separate file named as subdecode.m.
 This subdecode.m is responsible for DTMF decoding and its code is as follows:

1 axes(handles.fig1);
2 plot(t,y);
3 set(handles.fig1,'XMinorTick','on');
4 title('DTMF Input');xlabel('Time');
5 ylabel('Amplitude');grid;
6
7 rmain=2048*2;rmag=1024*2;
8 cn=9;cr=0.5;
9 cl=.25;ch=.28;
10 [b,a]=cheby1(cn,cr,cl);
11 yfilt1=filter(b,a,y);
12 h2=fft(yfilt1,rmain);
13 hmag2=abs(h2(1:rmag));
14 [b1,a1]=cheby1(cn,cr,ch,'high');
15 yfilt2=filter(b1,a1,y);
16 h3=fft(yfilt2,rmain);
17 hmag3=abs(h3(1:rmag));
18
19 axes(handles.fig2);
20 plot(yfilt1);grid;
21 title('Filtered Low Freq. Signal');
22 xlabel('Time');ylabel('Amplitude');
23
24 axes(handles.fig3);
25 plot(yfilt2);grid;
26 title('Filtered High Freq. Signal');
27 xlabel('Time');ylabel('Amplitude');
28
29 hlow=fft(yfilt1,rmain);
30 hmaglow=abs(hlow);
31 axes(handles.fig4);
32 plot(hmaglow(1:rmag));
33 title('FFT Low Pass');grid;
34 xlabel('Time');ylabel('Amplitude');
35
36 hhigh=fft(yfilt2,rmain);
37 hmaghigh=abs(hhigh);
38 axes(handles.fig5);
39 plot(hmaghigh(1:rmag));
40 title('FFT High Pass');grid;
41 xlabel('Time');ylabel('Amplitude');
42
43 m=max(abs(hmag2));n=max(abs(hmag3));
44 o=find(m==hmag2);p=find(n==hmag3);
45 j=((o-1)*fs)/rmain;
46 k=((p-1)*fs)/rmain;
47
48 if j<=732.59 & k<=1270.91;
49 disp('---> Key Pressed is 1');
50 elseif j<=732.59 & k<=1404.73;
51 disp('---> Key Pressed is 2');
52 elseif j<=732.59 & k<=1553.04;
53 disp('---> Key Pressed is 3');
54 elseif j<=732.59 & k>1553.05;
55 disp('---> Key Pressed is A');
56 elseif j<=809.96 & k<=1270.91;
57 disp('---> Key Pressed is 4');
58 elseif j<=809.96 & k<=1404.73;
59 disp('---> Key Pressed is 5');
60 elseif j<=809.96 & k<=1553.04;
61 disp('---> Key Pressed is 6');
62 elseif j<=809.96 & k>1553.05;
63 disp('---> Key Pressed is B');
64 elseif j<=895.39 & k<=1270.91;
65 disp('---> Key Pressed is 7');
66 elseif j<=895.39 & k<=1404.73;
67 disp('---> Key Pressed is 8');
68 elseif j<=895.39 & k<=1553.04;
69 disp('---> Key Pressed is 9');
70 elseif j<=895.39 & k>1553.05;
71 disp('---> Key Pressed is C');
72 elseif j>895.40 & k<=1270.91;
73 disp('---> Key Pressed is *');
74 elseif j>895.40 & k<=1404.73;
75 disp('---> Key Pressed is 0');
76 elseif j>895.40 & k<=1553.04;
77 disp('---> Key Pressed is #');
78 elseif j>895.40 & k>1553.05;
79 disp('---> Key Pressed is D');
80 end

 Now you can see in this code we are applying FFT on each of these sound signals and
then comparing them to get our required button press.
 Now, when I press any of these buttons then the GUI will look something as shown in
below figure:
 You can see in the above figure that first graph is showing the DTMF input, which is actual
signal which I have converted to sound on button press.
 The second graph is showing the Filtered Low Frequency Signal while the third one is
showing the Filtered High Frequency Signal.
 The two graphs on the right side are showing the Amplitude of FFT Low Pass and FFT
High Pass.
 Now if you have a look at the Command window of MATLAB then it will give you the button
pressed as shown in below figure:
 These are the buttons which I have pressed while testing it and it has given me each time
which button is pressed.
 Here’s the video which will give you better idea of How this DTMF decoder using
MATLAB is working.
Download Project Files

You might also like