DTMF encoder/decoder
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Why is that this DTMF decoder doesn't give me any outputs but the encoder works well? Here is my code below. It is suppose to give me the key inputted in my encoder in the command window but it does not work somehow. e.g. If I type myDTMF_encoder ([2 3 1 2], 5, 200) in my command window, it should display it back, I dunno why won't it work while my encoder works fine, if I type that in the command window it will return a beeping sound which clearly indicates the encoder works, please help!
for decoder:
function [A] = myDTMF_decoder(key,mark,space)
%
Fs = 8000;
mark=mark/1000;
space=space/1000;
t = 0:1/Fs:mark;
a = 0:1/Fs:space;
len=length(key)/(length(t)+length(a));
key=key(key~=0);
j=1;
for k=1:len
for i=1:(length(key)/len)+1
if (i==1)
b(k,i)= 0;
else
b(k,i)= key(j);
j=j+1;
end
end
end
n=len;
key='\0';
for k=1:n;
temp=abs(fft(b(k,:)));
x=1:(Fs/2)*mark;
[~,i]=max(temp(x));
f1=(i/mark)-1;
i=i-10:i+10;
temp(i)=0;
[~,i]=max(temp(x));
f2=(i/mark)-1;
if f1>1000
var=f1;
f1=f2;
f2=var;
elseif f1<1000
end
if ((f1>692) && (f1<720))
f1=697;
elseif ((f1>765) && (f1<800))
f1=770;
elseif ((f1>847) && (f1<880))
f1=852;
elseif ((f1>936) && (f1<960))
f1=941;
end
if ((f2>1204) && (f2<1240))
f2=1209;
elseif ((f2>1331) && (f2<1360))
f2=1336;
elseif ((f2>1472) && (f2<1500))
f2=1477;
elseif ((f2>1628) && (f2<1660))
f2=1633;
end
switch(f1);
case{697};
switch(f2);
case{1209};
key='1';
case{1336};
key='2';
case{1477};
key='3';
case{1633};
key='A';
end
case{770};
switch(f2);
case{1209};
key='4';
case{1336};
key='5';
case{1477};
key='6';
case{1633};
key='B';
end
case{852};
switch(f2);
case{1209};
key='7';
case{1336};
key='8';
case{1477};
key='9';
case{1633};
key='C';
end
case{941};
switch(f2);
case{1209};
key='*';
case{1336};
key='0';
case{1477};
key='#';
case{1633};
key='D';
end
end
A(k)=key;
k=k+1;
end
for encoder:
function [xt]=MyDTMF_encoder(key,mark,space)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
Fs = 8000;
s=0:1/Fs:mark/1000;
p=0:1/Fs:space/1000;
xt=0;
z=0*p;
for i=1:length(key)
switch(key(i))
case(1)
X=sin(2*pi*(1209)*s)+sin(2*pi*(697)*s);
case(2)
X=sin(2*pi*(1336)*s)+sin(2*pi*(697)*s);
case(3)
X=sin(2*pi*(1477)*s)+sin(2*pi*(697)*s);
case(4)
X=sin(2*pi*(1209)*s)+sin(2*pi*(770)*s);
case(5)
X=sin(2*pi*(1336)*s)+sin(2*pi*(770)*s);
case(6)
X=sin(2*pi*(1477)*s)+sin(2*pi*(770)*s);
case(7)
X=sin(2*pi*(1209)*s)+sin(2*pi*(852)*s);
case(8)
X=sin(2*pi*(1336)*s)+sin(2*pi*(852)*s);
case(9)
X=sin(2*pi*(1447)*s)+sin(2*pi*(852)*s);
case(0)
X=sin(2*pi*(1336)*s)+sin(2*pi*(941)*s);
case('*')
X=sin(2*pi*(941)*s)+sin(2*pi*(1209)*s);
case('#')
X=sin(2*pi*(852)*s)+sin(2*pi*(1477)*s);
case('A')
X=sin(2*pi*(697)*s)+sin(2*pi*(1633)*s);
case('B')
X=sin(2*pi*(770)*s)+sin(2*pi*(1633)*s);
case('C')
X=sin(2*pi*(852)*s)+sin(2*pi*(1633)*s);
case('D')
X=sin(2*pi*(941)*s)+sin(2*pi*(1633)*s);
otherwise
end
xt=horzcat(xt,X);
xt=horzcat(xt,z);
end
sound(xt,Fs)
myDTMF_decoder(key,mark,space)
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu DTMF finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!