【matlab】仿真4PSK调制信号在高斯信道下的性能,并与理论分析结果比较——仿真篇

来源:互联网 发布:图像处理分水岭算法 编辑:程序博客网 时间:2024/04/29 22:01

三、4PSK调制信号在高斯信道下的性能仿真[--详细解析--]

1. MATLAB进行仿真程序如下:



%{----------------------------------------------------------------------------- File:   说明文件                                                   Time:   Created on 2016-11-23                                                Author: Y. S. Cui <崔延硕>-----------------------------------------------------------------------------     声明:所有程序均已在以下环境调试通过,现声明环境:----------------------------------------------------------------------------- -|- 1、处理器:        Pentium(R) Dual-Core CPU E5800 @ 3.20GHz  3.20GHz    2、安装内存(RAM):8.00GB    3、系统类型:      Matlab R2014a    4、系统位数:      64位操作系统,基于x64的处理器----------------------------------------------------------------------------- ----------------------------------------------------------------------------- 题目:试编写程序,仿真4PSK调制信号在高斯信道下的性能,并与理论分析结果比较。分析:----------------------------------------------------------------------------- %}% //程序源代码:%------------------------------------------%clear all;clear;closeSNR=0:1:14;  %误码率范围%---------------------------------------------------%%---------------------------------------------------%%--------------到此 for K=1:15循环开始----------------%for k=1:15      M=250;    %---------------------------------------------------%%--------------到此 for l=1:M循环开始----------------%for l=1:M    N=80;     F=10;     n=0;     cntError=0;     m=1:1:10;    s0=sin(2*pi*m/F);  %000o    s0=s0'; %s0转置     s1=sin(2*pi*m/F+pi/2);%1090o    s1=s1'; %s1转置     s2=sin(2*pi*m/F+pi);%11180o    s2=s2'; %s2转置     s3=sin(2*pi*m/F+3*pi/2);%01270o    s3=s3'; %s3转置     source=randsrc(1,N,[0,1,2,3;.25,.25,.25,.25]);    %{    randsrc(m,n);    输出m*n阶或m*m阶矩阵,元素为随机出现的-1或1,概率为1/2;     %随机信源元素为随机出现的0/1/2/3,概率为0.25;    randsrc(1,N,[0,1,2,3;.25,.25,.25,.25])    ans =      Columns 1 through 14    0     2     2     2     2     0     1     0     0     0     0     1     2     3      Columns 15 through 28    0     2     1     0     3     0     1     2     0     2     3     3     1     1      Columns 29 through 42    2     2     3     0     2     2     3     3     3     2     3     1     0     2      Columns 43 through 56    0     2     1     1     1     1     3     1     0     2     3     1     2     3      Columns 57 through 70    3     0     3     2     0     0     2     0     3     1     3     0     0     2      Columns 71 through 80    2     2     3     3     1     3     1     1     3     2    %}    %---------两个循环------------------%    for i=1:N  %1-80        for j=1:F  %1-10        modsrc(j+(i-1)*F)=sin(pi/2*source(i)+2*pi*j/F);        end    end%---------awgn - Add white Gaussian noise to signal------------------%modsrcnoise=awgn(modsrc,SNR,4);  % 10*80——>1*800矩阵  y = awgn(x,snr,sigpower)%{help awgnawgn - Add white Gaussian noise to signal    This MATLAB function adds white Gaussian noise to the vector signal x.    y = awgn(x,snr)    y = awgn(x,snr,sigpower)    y = awgn(x,snr,'measured')    y = awgn(x,snr,sigpower,s)    y = awgn(x,snr,'measured',state)    y = awgn(...,powertype)ans =  Columns 1 through 80.6321    0.6895    0.8444    0.4612    0.2301   -0.3356   -1.7327   -0.6224    ......  Columns 793 through 8000.4677    0.5009   -0.0102   -0.4438   -0.6277   -0.9017   -0.3601   -0.2201%}    for i=1:N   %1-80    x = modsrcnoise((i-1)*F+(1:F));        %解调经过均衡器处理的数据        if x*(s0-s1)>=0 && x*(s0-s2)>=0 && x*(s0-s3)>=0;                  receive(i)=0;% 对应0        elseif x*(s1-s0)>0 && x*(s1-s2)>=0 && x*(s1-s3)>=0;                 receive(i)=1;% 对应1        elseif x*(s2-s0)>0 && x*(s2-s1)>0 && x*(s2-s3)>=0;                receive(i)=2;% 对应2        else                receive(i)=3;% 对应3        end    end    for i=1:N        if source(i)==receive(i);        else        cntError=cntError+1;        end    end    n=n+N;    ErrorRate(l)=cntError/n;end  %for 1=1:M  for l=1:M%--------------到此 for l=1:M循环终结----------------%%---------------------------------------------------%    ErrorRatesum(k)=0;    for i=1:M        ErrorRatesum(k)=ErrorRatesum(k)+ErrorRate(i);    end    ErrorRateave(k)=1/M*ErrorRatesum(k);end%--------------到此 for K=1:15循环终结----------------%%---------------------------------------------------%%---------------------------------------------------%semilogy(SNR,ErrorRateave,'-o');%{区别就是对谁取对数然后取代原来的x,y你可以绘图看看是不是这么回事。譬如x = 0:.1:10;semilogx(x,10.^x)图像是曲线 x = 0:.1:10;semilogy(x,10.^x)图像是直线semilogx和semilogy的区别: semilogx是将X轴的值用对数来表示;                          semilogy是将Y轴得到的值用对数来表示!%}%semilogy(SNR,ber1,'+-',SNR,ber2,'-');grid onhold onENR=10.^(SNR/10);for i=1:15    syms t  %This MATLAB function creates symbolic variables t    f=1/sqrt(2*pi)*exp(-t.^2/2);%标准正态分布    p(1,i)=int(f,t,-sqrt(ENR(i)),inf);    %{    这个Matlab函数返回矩阵形式的CIC滤波器的状态,而不是本地filtstates对象。    integerstates = int(hm.states)    %}endp=double(p);%double - Convert to double precisionp=1-p.^2;semilogy(SNR,p,'r');title('4PSK平均误码率');xlabel('SNR信噪比(db)');ylabel('BER误码率');legend('实际结果','理论结果');



0 0
原创粉丝点击