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

📄 huwei.m

📁 数字通信系统仿真
💻 M
字号:
function HUWei(p,noisesigma)
 k=p;                            %输入的键盘编号(16个键)
 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];%16个键的对应频率
 string=sym('[1,2,3,A,4,5,6,B,7,8,9,C,*,0,#,D]');  %16个键对应的数字或符号
 freq1=freqmap(1,k); %低频部分
 freq2=freqmap(2,k); %高频部分
 fs=8*10^3;          %采样频率
 sigtime=45;         %DTMF持续时间
 wholetime=100;      %静音加DTMF的持续时间
 %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
 %========================DTMF信号与噪声叠加结果====================
 %信道信号
 signal=y1+y2+noise;
 if show==1
 figure
 plot(signal);
 title('DTMF信号与噪声叠加结果');
 end
 %====================接收端DTMF判决程序与数据采样===============
 %也可以将接收信号反转,代表随机延迟
 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
 %将极值点位置与16个已知频点位置进行比较,最近点对应相应键的数字或符号
 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(311)
 plot(y1+y2);
 title('DTMF信号');
 subplot(312)
 plot(noise);
 title('高斯白噪声');
 subplot(313)
 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.95,'为祖国而学习,为人民而学习,为自己而学习!','sc');
 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 + -