1、%QPSK 格雷码clc;clear all;close all;nsymbol = 50000;%每种信噪比下符号数的发送符号数data = randi(0,1,1,nsymbol*2); %产生 1 行,nsymbol 列均匀分布的随机数 0,1qpsk_mod1 = zeros(1,nsymbol);qpsk_mod2 = zeros(1,nsymbol);data_receive1 = zeros(1,nsymbol);data_receive2 = zeros(1,nsymbol);data_receive = zeros(1,nsymbol*2);Wrongnumber = 0;S
2、ymbolWrongnumber = 0;for i=1:nsymbol %调制symbol1 = data(2*i-1);symbol2 = data(2*i);if symbol1 = 0 qpsk_mod2(i) = 0;elseif symbol1 = 0 qpsk_mod2(i) = 1;elseif symbol1 = 1 qpsk_mod2(i) = 0;elseif symbol1 = 1 qpsk_mod2(i) = -1;endendSNR_dB = 1:10;%信噪比 dB 形式SNR = 10.(SNR_dB/10);%信噪比转化为线性值for loop= 1:10si
3、gma = sqrt(1/(2*SNR(loop);%根据符号功率求噪声功率qpsk_receive1 = qpsk_mod1 + sigma * randn(1,nsymbol);qpsk_receive2 = qpsk_mod2 + sigma * randn(1,nsymbol); %添加复高斯白噪声for k=1:nsymbolif qpsk_receive2(k) qpsk_receive1(k) data_receive2(k) = 1;endif qpsk_receive2(k) -qpsk_receive1(k) data_receive1(k) = 0;endif qpsk_
4、receive2(k) -qpsk_receive1(k)data_receive1(k)=0;if qpsk_receive2(k) qpsk_receive1(k)data_receive2(k) = 1;elsedata_receive2(k) = 0;endelseif qpsk_receive2(k) qpsk_receive1(k)data_receive2(k) = 0;elsedata_receive2(k) = 1;endenddata_receive(2*k-1) = data_receive1(k);data_receive(2*k) = data_receive2(k)
5、;endfor p=1:(nsymbol*2)if data_receive(p) = data(p)Wrongnumber = Wrongnumber + 1;endendfor l=1:nsymbolif data_receive1(l)=data(2*l-1);SymbolWrongnumber = SymbolWrongnumber + 1;elseif data_receive2(l) = data(2*l);SymbolWrongnumber = SymbolWrongnumber + 1;endendPe(loop)=SymbolWrongnumber/nsymbol;Pb(lo
6、op)=Wrongnumber/(nsymbol*2);Wrongnumber = 0 ;SymbolWrongnumber = 0;endPe_theory = 1-(1-qfunc(sqrt(SNR).2;Pb_theory = 0.5* erfc(sqrt(SNR/2);semilogy(SNR_dB,Pb,-k*,SNR_dB,Pb_theory,-bo,SNR_dB,Pe,-r,SNR_dB,Pe_theory,g)title(QPSK 信号在 AWGN 信道下的性能 );xlabel(信噪比/dB);ylabel( 误码率);legend(误比特率,理论误比特率,误码率,理论误码率);grid on;