📄 gendtmf.m
字号:
%function [wav]=genDTMF(telnum)
%Usage:
%[wav]=genDTMF(telnum)
%For example:
function wav=genDTMF([2 6 5 3 6 1 9 8]);
%the elaspe time of a dial
elapse_time=0.04;
%sampling frequency
Fs = 8000;
%the time sequence of a dial
t = (0:elapse_time*Fs)/Fs;
pit = 2*pi*t;
%DTMF look up table
fc = [697 770 852 941];
fr = [1209 1336 1477];
f = [];
for c=1:4,
for r=1:3,
f = [ f [fc(c);fr(r)] ];
end
end
%generate the tones for 12 dial numbers
for i=1:size(f,2),
tones(:,i) = sum(sin(f(:,i)*pit))';
end
%determine how many numbers dialed
len=length(telnum);
%generate the seed for random
rand('seed',telnum(1));
%generate the silent tone before dialing
wav=zeros(1,round(rand*100));
for i=1:len
if telnum(i)==0
telnum(i)=11; % the number '0' is in the 11th position
end
%generate tone of each dial number with a sequence of silent tone
wav=[wav tones(:,telnum(i))' zeros(1,round(rand*6000+1000))];
end
%the whole tone is disturbed with a small noise
wav=wav+rand(1,length(wav))/50;
%play this tone
wavplay(wav,Fs);
%plot it.
plot((1:length(wav))/Fs,wav)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -