⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 huwei.m

📁 dtmf的计算机仿真程序用于大学的课程设计
💻 M
字号:
function HUWei(p,noisesigma)
k=p;
show=0;
freqmap=[697 697 697 697 770 770 770 770 852 852 852 852 941 941 941 941 ,
    1209 1336 1477 1633 1209 1336 1477 1633 1209 1336 1477 1633 1209 1336 1477 1633 ];
string=sym('[1,2,3,A,4,5,6,B,7,8,9,C,*,0,#,D]');
freq1=freqmap(1,k);
freq2=freqmap(2,k);
fs=8*10^3;
sigtime=45;
wholetime=100;
y1=[];
[y1,number]=DTMFproduce(freq1,fs,sigtime,wholetime);
[y2,number]=DTMFproduce(freq2,fs,sigtime,wholetime);
if show==1
figure
plot(y1+y2);
title('DTMF信号');
end
%=====================================
%加入高斯白噪声
m=0;
sigma=noisesigma;
noise=Gngauss(m,sigma,number);
%================================
if show==1
figure
plot(noise);
title('高斯白噪声');
end
%============================
%信道信号
signal=y1+y2+noise;
if show==1
figure
plot(signal);
title('DTMF信号与噪声叠加结果');
end
%==================================
%也可以将接受信号反转,代表随机延迟
delay=round(50*rand+1)+350;
receive(1,1:delay)=signal(1,800-delay+1:800);
receive(1,delay+1:800)=signal(1,1:800-delay);
%receive=zeros(1,800);
%receive=signal(end:-1:1);
%
%对于800个点接受信号区开始判决
%thresh=2*sigma;
thresh=2.5;
Length=300;
a=zeros(1,20);
sample=zeros(1,Length);
finished=0;
for i=1:1:800-5
     if (finished==0)
     a(1,1:5)=receive(1,i:i+4);
     if(sum(a)>thresh&i<(800-Length))
sample(1,1:Length)=receive(1,i:i+Length-1);finished=1;
end
if i>=(800-Length-10) waitfor(errorDlg('信号到达检测出现错误!'));return;end;
end 
end
%===============================
if show==1
figure
plot(sample);
title('接收端采样结果显示');
end
%======================
Topmax=(freqmap*Length/8000);
Y=abs(fft(sample));
if show==1
figure
plot(Y);
title('采样数据频谱显示');
end
%==================================
DATA=zeros(1,2);
YY=Y(1,1:Length/2);
MAX=max(YY);
m=0;
for i=3:1:(Length/2-1);
if(YY(1,i)>=YY(1,i+1))&(YY(1,i)>=YY(1,i-1))&(YY(1,i)>(MAX/3))
m=m+1
DATA(1,m)=i;
end 
end
BB(1,:)=DATA(1,1)*ones(1,16);
BB(2,:)=DATA(1,2)*ones(1,16);
Adjust=Topmax-BB;
PAN=Adjust.*Adjust;
Hu=sum(PAN,1);
Data=find(Hu==min(min(Hu)));
string(1,Data)
%================================
figure(2)
subplot(3,1,1)
plot(y1+y2);
title('DTMF信号');
subplot(3,1,2)
plot(noise);
title('高斯白噪声');
subplot(3,1,3)
plot(signal);
title('DTMF信号与噪声叠加结果');
figure(3);
subplot(211);plot(receive);title('随机延迟的DTMF接收信号');
figure(4)
subplot(211)
plot(sample);
title('接收端采样结果显示');
subplot(212)
plot(Y);
title('采样数据频谱显示');
figure(5)
axis('off');
text(0.2,0.8,'         DTMF接收窗口','sc');
text(0.2,0.6,'此次接收到的数字或符号为:','sc');
text(0.2,0.4,'            当前噪声大小为:','sc');
text(0.7,0.4,num2str(sigma),'sc');
switch Data
case 1
if k==Data text(0.7,0.6,'1','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 2
if k==Data text(0.7,0.6,'2','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 3
if k==Data text(0.7,0.6,'3','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 4
if k==Data text(0.7,0.6,'A','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 5
if k==Data text(0.7,0.6,'4','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 6
if k==Data text(0.7,0.6,'5','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 7
if k==Data text(0.7,0.6,'6','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 8
if k==Data text(0.7,0.6,'B','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 9
if k==Data text(0.7,0.6,'7','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 10
if k==Data text(0.7,0.6,'8','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 11
if k==Data text(0.7,0.6,'9','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 12
if k==Data text(0.7,0.6,'C','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 13
if k==Data text(0.7,0.6,'*','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 14
if k==Data text(0.7,0.6,'0','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 15
if k==Data text(0.7,0.6,'#','sc');else text(0.7,0.6,'通信不成功!','sc');end
case 16
if k==Data text(0.7,0.6,'D','sc');else text(0.7,0.6,'通信不成功!','sc');end
otherwise
text(0.7,0.6,'通信不成功!','sc');
end
%end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -