1、%FSK_theo.mclear all;clc;SNRindB=0:1:20;Pe_CFSK=zeros(1,length(SNRindB);Pe_NCFSK=zeros(1,length(SNRindB);Pe_NCFSK_Rayleigh=zeros(1,length(SNRindB);for i=1:length(SNRindB) EsN0=exp(SNRindB(i)*log(10)/10); Es_aveN0=exp(SNRindB(i)*log(10)/10); Pe_CFSK(i)=Qfunct(sqrt(EsN0);%相干移频键控系统 Pe_NCFSK(i)=0.5*exp(
2、-EsN0/2);%非相干移频键控系统(无衰落) Pe_NCFSK_Rayleigh(i)=1/(2+Es_aveN0);%非相干移频键控系统(瑞利衰落)endsemilogy(SNRindB,Pe_CFSK,-o,SNRindB,Pe_NCFSK,-*,SNRindB,Pe_NCFSK_Rayleigh,-);xlabel(Es/No或平均Es/No(dB)ylabel(最小平均错误概率Pelegend(相干移频,非相干移频(无衰落)非相干移频(瑞利衰落)title(二元移频信号检测性能曲线axis(0 20 10-7 1);grid on;2、调用子函数%Q函数%Qfunct.mfunct
3、ion y=Qfunct(x)% y=Qfunct(x)% QFUNCT evaluates the Q-function. % y = 1/sqrt(2*pi) * integral from x to inf of exp(-t2/2) dt.% y = (1/2) * erfc(x/sqrt(2).y=(1/2)*erfc(x/sqrt(2);二、仿真结果作业2试编写程序,仿真BPSK,4PSK调制信号在高斯信道下的性能,画出误码率(误比特和误符号)的性能曲线,并与理论分析结果相比。一、BPSK脚本文件及仿真结果%BPSK调制信号在AWGN下的蒙特卡罗仿真%BPSK_MC.mSNRind
4、B1=0:10;SNRindB2=0:0.5:smld_err_prb=zeros(1,length(SNRindB1);theo_err_prb=zeros(1,length(SNRindB2);length(SNRindB1), % simulated error rate smld_err_prb(i)=sm_BPSK(SNRindB1(i);end;length(SNRindB2), EsN0=exp(SNRindB2(i)*log(10)/10); % theoretical error rate theo_err_prb(i)=Qfunct(sqrt(2*EsN0);% Plott
5、ing commands followsemilogy(SNRindB1,smld_err_prb,*,SNRindB2,theo_err_prb,Es/No(dB)误码率BPSK调制信号在AWGN下的蒙特卡罗仿真仿真误码率理论误码率%计算BPSK的仿真误码率(误符号率=误比特率)%sm_BPSK.mfunction p=sm_BPSK(snr_in_dB)% p=sm_BPSK(snr_in_dB)% sm_BPSK simulates the probability of error for the particular% value of snr_in_dB, signal to noi
6、se ratio in dB.Es=1;EsN0=exp(snr_in_dB*log(10)/10); % signal to noise ratiosgma=Es/sqrt(2*EsN0); % sigma, standard deviation of noiseN=107;%统计量%产生二进制数据源dsource=zeros(1,N);N, temp=rand; % a uniform random variable over (0,1) if (temp0.5), dsource(i)=0; % with probability 1/2, source output is 0 else
7、dsource(i)=1; % with probability 1/2, source output is 1 endnumoferr=0; %接收信号(信号映射,加性高斯白噪声) if (dsource(i)=0), r=-Es+gngauss(sgma); % if the source output is 0 r=Es+gngauss(sgma);1 end; %信号判决 if (r0), decis=0; % decision is decis=1; %计算误符号率=误比特率 if (decis=dsource(i), % if it is an error, increase th
8、e error counter numoferr=numoferr+1;p=numoferr/N; % probability of error estimate%*% 产生加性高斯白噪声% gngauss.mfunctiongsrv1,gsrv2=gngauss(m,sgma) % gsrv1,gsrv2=gngauss(m,sgma) % gsrv1,gsrv2=gngauss(sgma) % gsrv1,gsrv2=gngauss % GNGAUSS产生两个均值为m、标准差为sgma的、互相独立的 % 高斯随机变量。如果缺少其中一个输入参数,则取均值 % 为0。如果既没有给出均值也没有给
9、出方差,本函数将 % 产生两个标准高斯随机变量。if nargin=0, m=0;sgma=1;elseif nargin=1, sgma=m;m=0;u=rand; %在区间(0,1)内的均匀随机变量 z=sgma*(sqrt(2*log(1/(1-u); %瑞利分布随机变量 gsrv1=m+z*cos(2*pi*u);gsrv2=m+z*sin(2*pi*u);3、仿真结果二、QPSK脚本文件及仿真结果%QPSK调制信号在AWGN下的蒙特卡罗仿真%QPSK_MC.m14; % 设置仿真信噪比范围0.1: % 理论计算信噪比范围smld_bit_err_prb=zeros(1,length(
10、SNRindB1);smld_symbol_err_prb=zeros(1,length(SNRindB1);theo_bit_err_prb=zeros(1,length(SNRindB2);theo_symbol_err_prb=zeros(1,length(SNRindB2); pb,ps=sm_QPSK(SNRindB1(i); % 仿真比特和符号错误概率 smld_bit_err_prb(i)=pb; % pb表示误比特率 smld_symbol_err_prb(i)=ps; % ps表示误符号率 SNR=exp(SNRindB2(i)*log(10)/10); % 信噪比SNR=Es/N0 theo_bit_err_prb(i)=Qfunct(sqrt(SNR); % 计算理论误比特率 theo_symbol_err_prb(i)=2*Qfunct(sqrt(SNR); % 计算理论误符号率semilogy(SNRindB1,smld_bit_err_prb,o % 画图hold onsemilogy(SNRindB1,smld_symbol_err_prb,semilogy(SNRindB2,theo_bit_err_prb,)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1