BPSK/QPSK的误比特率比较性能

效果图

BPSK/QPSK的误比特率比较性能_第1张图片

BPSK

clear
SNR_dB=1:1:15;
SNR=10.^(SNR_dB/10);
N=1e6;
M=2;
msg=randi([0,1],1,N);
y=pskmod(msg,M);


for i=1:length(SNR_dB)
    N0_dB=10*log10(0.5/SNR(i));%噪声功率变成dB
    w=wgn(1,N,N0_dB);
    h=raylrnd(1/sqrt(2),1,N);%瑞利信道

    y_AWGN=y+w;
    y_AWGN_y1=pskdemod(y_AWGN,M);
    bit_AWGN=length(find(msg~=y_AWGN_y1));
    BPSK_AWGN_sim(i)=bit_AWGN/N;%误码率

    y_R=y.*h+w;
    y_R_y1=pskdemod(y_R,M);
    bit_R=length(find(msg~=y_R_y1));
    BPSK_R_sim(i)=bit_R/N;%误码率
end
%QPSK_AWGN_the=0.5*erfc(sqrt(SNR));
%QPSK_R_the=0.5*(1-sqrt((SNR)./(1+SNR)));

%绘图
figure;
semilogy(SNR_dB,BPSK_AWGN_sim,'-ko');hold on;
%semilogy(SNR_dB,QPSK_AWGN_the,'-k');hold on;
semilogy(SNR_dB,BPSK_R_sim,'-b*');hold on
%semilogy(SNR_dB,QPSK_R_the,'-b');grid on;
grid on;
%legend('AWGN仿真','AWGN理论','瑞利仿真','瑞利理论');
legend('AWGN-误比特率','瑞利仿真-误比特率');
title('BPSK误码性能分析');
xlabel('信噪比(dB)');ylabel('误比特率');


 QPSK


SNR_dB=1:1:15;
SNR=10.^(SNR_dB/10);
N=1000000;
M=4;
msg=randi([0,M-1],1,N);
y=pskmod(msg,M);


for i=1:length(SNR_dB)
    N0_dB=10*log10(0.5/SNR(i));%噪声功率变成dB
    w=wgn(1,N,N0_dB);
    %h = (randn(N,1)+1i*randn(N,1))/sqrt(2);
    h=raylrnd(1/sqrt(2),1,N);%瑞利信道

    %%误符号率%%
    %高斯信道
    y_AWGN=y+w;
    y_AWGN_y1=pskdemod(y_AWGN,M);
    bit_AWGN=length(find(msg~=y_AWGN_y1));
    QPSK_AWGN_sim(i)=bit_AWGN/N;%误码率
    %瑞利信道
    y_R=y.*h+w;
    y_R_y1=pskdemod(y_R,M);
   % y_R_y1=pskdemod(y_R,M,pi/4,'gray');
    bit_R=length(find(msg~=y_R_y1));
    QPSK_R_sim(i)=bit_R/N;%误码率

    %%误比特率%%
    %高斯信道
    y__AWGN_y1_bit=dec2bin(y_AWGN_y1);
    msg_bit=dec2bin(msg);
    [m,n]=size(msg_bit);
    every_AWGN=0;
       for p=1:m  %行
            for k=1:n  %列
                R1=msg_bit(p,k);
                B2=y__AWGN_y1_bit(p,k);
                if R1~=B2
                    every_AWGN=every_AWGN+1;
                end           
            end
      end
    every_AWGN
    error_bit__AWGN(i)=every_AWGN/(2*N)
% 
    %瑞利信道
    msg_bit=dec2bin(msg);
    y_R_y1_bit=dec2bin(y_R_y1);
    [m,n]=size(msg_bit);
    every_R=0;
       for p=1:m  %行
            for k=1:n  %列
                R1=msg_bit(p,k);
                B2=y_R_y1_bit(p,k);
                if R1~=B2
                    every_R=every_R+1;
                end           
            end
      end
    every_R
    error_bit_R(i)=every_R/(2*N)

end

%QPSK_AWGN_the=0.5*erfc(sqrt(SNR));
%QPSK_R_the=0.5*(1-sqrt((SNR)./(1+SNR)));

%绘图
figure;
semilogy(SNR_dB,QPSK_AWGN_sim,'-ko');hold on;
%semilogy(SNR_dB,QPSK_AWGN_the,'-k');hold on;
semilogy(SNR_dB,QPSK_R_sim,'-b*');hold on
%semilogy(SNR_dB,QPSK_R_the,'-b');grid on;
semilogy(SNR_dB,error_bit_R,'-r*');hold on
semilogy(SNR_dB,error_bit__AWGN,'-r*');hold on
grid on;

%legend('AWGN仿真','AWGN理论','瑞利仿真','瑞利理论');
legend('AWGN的误码率','瑞利的误码率','高斯的误比特率','瑞利的误比特率');
title('QPSK误码性能分析');
xlabel('信噪比(dB)');ylabel('误比特率');


比较函数

SNR_dB=1:1:15;
SNR=10.^(SNR_dB/10);

figure

semilogy(SNR_dB,BPSK_AWGN_sim,'-r');hold on;
hold on;
semilogy(SNR_dB,BPSK_R_sim,'--r');
hold on;
semilogy(SNR_dB,error_bit__AWGN,'bo');hold on;
hold on;
semilogy(SNR_dB,error_bit_R,'b*');
hold on;

grid on;

legend('BPSK-AWGN仿真','BPSK-瑞利仿真','QPSK-AWGN仿真','QPSK-瑞利仿真');
title('BPSK/QPSK误码性能对比');
xlabel('信噪比(dB)');ylabel('误码率');

你可能感兴趣的:(matlab,人工智能,算法,机器学习)