%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%本程序用于仿真QPSK,16QAM,通过AWGN信道的BER随SNR的变化规律。%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clearall;clcM_4psk=4;%4psk的进制数k_4psk=log2(M_4psk);%4psk的一个符号包含的比特数M_16qam=16;%16qam的进制数k_16qam=log2(M_16qam);%16qam一个符号包含的比特数NumSymbols=10^6;%定义要发送的比特数rngdefault%使用默认的随机数生成器dataIn=randi([01],NumSymbols,1);%生成二进制发送数据dataInMatrix_4psk=reshape(dataIn,length(dataIn)/2,2);%将发送二进制数据整理成两个一行,准备进行进制转换dataSymbolsIn_4psk=bi2de(dataInMatrix_4psk);%转换成十进制dataInMatrix_16qam=reshape(dataIn,length(dataIn)/4,4);%将发送二进制数据整理成四个一行,准备进行进制转换dataSymbolsIn_16qam=bi2de(dataInMatrix_16qam);%转换成十进制dataModG_4psk=pskmod(dataSymbolsIn_4psk,M_4psk,0,'gray');%4psk调制以及格雷码编码dataModG_16qam=qammod(dataSymbolsIn_16qam,M_16qam,0,'gray');%16qam调制以及格雷码编码EbNo=[-2:2:15];%设置SNR范围berG_4psk=zeros(1,length(EbNo));%定义4psk误码率数组berG_16qam=zeros(1,length(EbNo));%定义16qam误码率数组forindex=1:length(EbNo)%计算以db表示的SNRsnr_4psk=EbNo(index)+10*log10(k_4psk);snr_16qam=EbNo(index)+10*log10(k_16qam);%信号通过AWGN信道receivedSignalG_4psk=awgn(dataModG_4psk,snr_4psk,'measured');receivedSignalG_16qam=awgn(dataModG_16qam,snr_16qam,'measured');%解调以及格雷码解码dataSymbolsOutG_4psk=pskdemod(receivedSignalG_4psk,M_4psk,0,'gray');dataSymbolsOutG_16qam=qamdemod(receivedSignalG_16qam,M_16qam,0,'gray');dataOutMatrixG_4psk=de2bi(dataSymbolsOutG_4psk,k_4psk);%十进制转二进制,准备计算BERdataOutG_4psk=dataOutMatrixG_4psk(:);%将数据转化成一维向量dataOutMatrixG_16qam=de2bi(dataSymbolsOutG_16qam,k_16qam);%十进制转二进制,准备计算BERdataOutG_16qam=dataOutMatrixG_16qam(:);%将数据转化成一维向量[numErrorsG_4psk,berG_4psk(index)]=biterr(dataIn,dataOutG_4psk);%计算4psk误码率[numErrorsG_16qam,berG_16qam(index)]=biterr(dataIn,dataOutG_16qam);%计算16qam误码率end%计算信号通过AWGN信道的理论误比特率==========================================TheoryBER_4psk=berawgn(EbNo,'psk',4,'nondiff');%计算4psk通过AWGN理论误比特率TheoryBER_16qam=berawgn(EbNo,'qam',16);%计算16qam通过AWGN理论误比特率%==========================================================================%画图semilogy(EbNo,TheoryBER_4psk,'b-',EbNo,TheoryBER_16qam,'r-');%画出理论BER曲线holdon;semilogy(EbNo,berG_4psk,'b*',EbNo,berG_16qam,'r*');%画出仿真BER曲线gridon;xlabel('Eb/N0(dB)');ylabel('BER');%横纵坐标legend('QPSK理论BER','16QAM理论BER','QPSK仿真BER','16QAM仿真BER');%图例title('QPSK/16QAM通过AWGN信道');%题目