Stuck with DTMF code

12 vues (au cours des 30 derniers jours)
moonman
moonman le 6 Oct 2011
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);

Réponse acceptée

Honglei Chen
Honglei Chen le 6 Oct 2011
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

Plus de réponses (4)

Walter Roberson
Walter Roberson le 6 Oct 2011
Your line
function dtmf=dtmfdial([a b c d e],fs);
is illegal syntax. It is not allowed to list an array or cell array as a parameter on the right-hand side of a "function" statement.

moonman
moonman le 6 Oct 2011
Actually i want to play through follwoing matlab command
sound(dtmfdial([input]),12000)
and input is row vector
what should i do
Then i want to call each element of this row vector in programm to calculate its frequency
Plz help me

moonman
moonman le 6 Oct 2011
I have made whole flow chart of code and written the code i just need help how can i give input of 5 keys in function and how can i call them in code i mean lets suppose we have row vector k=[3 4 2 4 2] we can call the first element by k(1) and so on
how abt getting elements of function input
Waiting for reply

moonman
moonman le 6 Oct 2011
Somebody plz help me
today wayne king is not here so i m alone....
  1 commentaire
Walter Roberson
Walter Roberson le 6 Oct 2011
I had a mandatory all-staff meeting at work this morning, which made my sleep and breakfast schedule rather unbalanced. And now I need to go see if some lunch will wake me up.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by