Loading

数字通信—QPSK格雷码与非格雷码比较

1 仿真结果

参数设置:

  1. 信噪比:0~10dB
  2. 码元个数:1000000
  3. 调制方式:QPSK
  4. 格雷码和非格雷码的星座图:

仿真结果:

对于 QPSK 有格雷码和非格雷码两种编码方式,这里只需要改变从 bit 流映射成调制符号的方式就可以了。对于这两种编码方式其实其误码率性能是一样的,因为对于 QPSK 来说每一个象限只有一种调制符号,所以一旦错到别的象限就是错了一种符号。但是他们的误比特率是不一样的,从下面的仿真结果中也可以看出来,格雷码的效果是优于非格雷码的,这是因为格雷码相邻的符号间只有一个 bit 是不一样的,这样错到相邻的象限也只会造成 1bit 的错误。

2 仿真代码

%% QPSK
clear;
clc;
M = 4;                %QPSK的阶数
SNR = (0:1:10);       %信噪比范围
nsymbol = 1000000;    %符号个数
data_source = randsrc(nsymbol,2,[0 1]); 
%% 坐标点映射(采用非格雷映射)
[a1,b1] = find(data_source(:,1) == 0 & data_source(:,2) == 0);    %00的索引  
data_send_1(a1) = -1-1j; 
[a2,b2] = find(data_source(:,1) == 0 & data_source(:,2) == 1);    %01的索引
data_send_1(a2) = -1+1j; 
[a3,b3] = find(data_source(:,1) == 1 & data_source(:,2) == 0);    %10的索引
data_send_1(a3) = 1+1j;  
[a4,b4] = find(data_source(:,1) == 1 & data_source(:,2) == 1);    %11的索引
data_send_1(a4) = 1-1j;  
%% 坐标点映射(采用格雷映射)
[c1,d1] = find(data_source(:,1) == 0 & data_source(:,2) == 0);    %00的索引  
data_send_2(c1) = -1-1j; 
[c2,d2] = find(data_source(:,1) == 0 & data_source(:,2) == 1);    %01的索引
data_send_2(c2) = -1+1j; 
[c3,d3] = find(data_source(:,1) == 1 & data_source(:,2) == 1);    %11的索引
data_send_2(c3) = 1+1j;  
[c4,d4] = find(data_source(:,1) == 1 & data_source(:,2) == 0);    %10的索引
data_send_2(c4) = 1-1j;  
%% 
%symbol=[-1-1j, -1+1j, 1-1j, 1+1j];      %QPSK的符号坐标点
Es = norm(data_send_1).^2 / nsymbol;     %一个符号的能量(QPSK每个符号的能量都是相等的)
Eb = Es/(log2(M));                       %一个比特的能量
snr = 10.^(SNR/10);                      %信噪比dB转化成数值
N0  =Eb./snr;                            %求出在该比特能量下对应的噪声功率
sigma=sqrt(N0/2);                        %要分成实部和虚部,所以功率要除上2
for Eb_NO=1:length(sigma) 
    n1=sigma(Eb_NO)*randn(1,nsymbol); 
    n2=sigma(Eb_NO)*randn(1,nsymbol); 
    receive_1=data_send_1+n1+n2*1i;          %加噪声
    receive_2=data_send_2+n1+n2*1i;          %加噪声
    resum=0; 
    total=0; 
    %===========================
    %接收符号判决
    %===========================
    m1 = find(real(receive_1)>=0 & imag(receive_1)>0);
    n1 = find(real(receive_2)>=0 & imag(receive_2)>0);
    redata_1(m1,1) = 1;
    redata_1(m1,2) = 0;
    redata_2(n1,1) = 1;
    redata_2(n1,2) = 1;
    m2 = find(real(receive_1)<=0 & imag(receive_1)>0);
    n2 = find(real(receive_2)<=0 & imag(receive_2)>0);
    redata_1(m2,1) = 0;
    redata_1(m2,2) = 1;
    redata_2(n2,1) = 0;
    redata_2(n2,2) = 1;
    m3 = find(real(receive_1)<0 & imag(receive_1)<=0); 
    n3 = find(real(receive_2)<0 & imag(receive_2)<=0); 
    redata_1(m3,1) = 0;
    redata_1(m3,2) = 0;
    redata_2(n3,1) = 0;
    redata_2(n3,2) = 0;
    m4 = find(real(receive_1)>0 & imag(receive_1)<=0); 
    n4 = find(real(receive_2)>0 & imag(receive_2)<=0); 
    remessage(1,m4)=1-1i;
    redata_1(m4,1) = 1;
    redata_1(m4,2) = 1;
    redata_2(n4,1) = 1;
    redata_2(n4,2) = 0;
    
    total_symbol_1 = length(find(data_source(:,1)~=redata_1(:,1) ...
        | data_source(:,2)~=redata_1(:,2))); %找出不一样的符号
    total_symbol_2 = length(find(data_source(:,1)~=redata_2(:,1) ...
        | data_source(:,2)~=redata_2(:,2))); %找出不一样的符号
    
    total_bit_1 = length(find((data_source-redata_1)~=0));
    total_bit_2 = length(find((data_source-redata_2)~=0));
    
    [total_1,ratio1] = biterr(data_source,redata_1);
    [total_2,ratio2] = biterr(data_source,redata_2);
    
    Pb_1(Eb_NO) = total_bit_1/(nsymbol*2);
    Pb_2(Eb_NO) = total_bit_2/(nsymbol*2);
    
    Pe_1(Eb_NO) = total_symbol_1/nsymbol;
    Pe_2(Eb_NO) = total_symbol_2/nsymbol;
end
% scatterplot(receive_1)
% title('接收信号的星座图')
figure(1);          
semilogy(SNR,Pb_1,'k-X',SNR,Pb_2,'k-s',SNR,Pe_1,'r-o',SNR,Pe_2,'r-*')
legend('非格雷码QPSK仿真误比特率','格雷码QPSK仿真误比特率','非格雷码QPSK仿真误码率',...
    '格雷码QPSK仿真误码率')
title('QPSK格雷编码与非格雷编码性能性能比较')
xlabel('信噪比/dB');ylabel('误比特率/误码率')
grid on
posted @ 2021-05-11 09:10  MayeZhang  阅读(2721)  评论(0编辑  收藏  举报