MATLAB: Stuck with DTMF code

dtmf

I want to write a DTMF function which takes 5 inputs and give sound for it with gap of 1 seconds. I know how to concatinetane at the end and other stuff but i am stuck how to take data from fucntion input and tell it to assign a desired frequency. Plz Help me
function dtmf=dtmfdial([a b c d e],fs);
%This function produces DTMF Tone corresponding to given
%key number
%abcdefg=input key numbers
%fs= The sampling frequency
fs=8000
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
table=f';
dur=.5;
tt=0:(1/fs):dur;
%******************************************************************

%%Here i want to tell MAtlab that if key number 1 is pressed then the
%frequencies will be table (1,1) and table (1,2) and so on
% how to tell matlab about this
%******************************************************************
tone1=sin(2*pi*table(1,1)*tt);
tone2=sin(2*pi*table(1,2)*tt);
tone_a=tone1+tone2
sil_dur=1;
sil_freq=0;
sil_tt=0:(1/fs):dur;
sil_tone=sin(2*pi*sil_freq*sil_tt)
tone1=sin(2*pi*table(3,1)*tt);
tone2=sin(2*pi*table(3,2)*tt);
tone_b=tone1+tone2
soundsc(tone_a,fs);
soundsc(sil_tone,fs);
soundsc(tone_b,fs);

Best Answer

You can pass in an array like
function dtmfdial(x,fs)
and then inside your function, use a for loop to work on each key pressed. e.g.,
for m = 1:length(x)
key_pressed = x(m);
% continue to whatever you need to do
end
HTH
Related Question