clc;clear;close all;
fs=5000;
T=0.4;
t=0:1/fs:T;
fRow=[697 770 852 941];
fCol=[1209 1336 1477];
dialedNum=8023600822;
dialedNum=num2str(dialedNum);
toneSig=[];
for i=1:length(dialedNum)
switch dialedNum(i)
case '1'
f1=fRow(1);
f2=fCol(1);
case '2'
f1=fRow(1);
f2=fCol(2);
case '3'
f1=fRow(1);
f2=fCol(3);
case '4'
f1=fRow(2);
f2=fCol(1);
case'5'
f1=fRow(2);
f2=fCol(2);
case'6'
f1=fRow(2);
f2=fCol(3);
case'7'
f1=fRow(3);
f2=fCol(1);
case'8'
f1=fRow(3);
f2=fCol(2);
case'9'
f1=fRow(3);
f2=fCol(3);
case'0'
f1=fRow(4);
f2=fCol(2);
end
tone=(sin(2*pi*f1*t)+sin(2*pi*f2*t))';
toneSig=[toneSig;tone;zeros(size(tone))];
end
sound(toneSig,fs)
subplot(2,1,1); plot(toneSig)
title('DTMF Signal');
xlim([0,40000]);
audiowrite('DTMSignal.wav',toneSig,fs);
N=length(toneSig);
X=abs(fft(toneSig))/N;
X=2*X(1:N/2+1);
f=(0:N/2)*fs/N;
subplot(2,1,2); plot(f,X)
title('Frequency spectrum of DTMF signal');