clear;
close all;
d=input('input telephone number: ','s'); %输入电话号码
num=length(d);%电话号码总位数
dtmf=[];%时域信号
for a=1:num
asc=abs(d(a));%当前符号的ASCII码
tm=[49,50,51,65;52,53,54,66;55,56,57,67;42,48,35,68];
for p=1:4;
for q=1:4;
if tm(p,q)==abs(d(a)); break,end
end
if tm(p,q)==abs(d(a)); break,end
end%确定当前位对应的两个频率值
f1=[697,770,852,941];
f2=[1209,1336,1477,1633];
n=1:400;
x=sin(2*pi*n*f1(p)/8000) + sin(2*pi*n*f2(q)/8000);
x=[x,zeros(1,400)];%生成当前位的DTMF信号
dtmf=[dtmf,x]; %将全部位按序排列,产生完整电话号码的DTMF信号
end
wavwrite(dtmf,'dtmf')
sound(dtmf);
plot(dtmf);
title('DTMF信号');