格雷映射-误码率讲解及MATLAB仿真 part3

第三部分:基于如下图所示的QPSK基带传输系统
格雷映射-误码率讲解及MATLAB仿真 part3_第1张图片
(1)利用格雷编码,将长度为100000的传输比特映射到QPSK复信号串上。
(2)调制后的QPSK信号通过加性高斯白噪声(AWGN)信道传输。
(3)我们将使用最大似相似ML)接收器来检测接收到的信号(将接收符号的距离与所有可能的符号值进行比较,并选择使距离最小的符号)。
(4)在QPSK解调之后,接收的比特将与传输的比特进行比较。
(5)改变SNR,对比仿真值和理论值。
通过MATLAB仿真结果和理论值相对比:
(注释为英文)

clc;
close all;
%%%%%%%%%%%%% 仿真过程 %%%%%%%%%%%%%%%%%%%
data=randi([0 1],1,200000);% generate 200000 random values of 1 or 0
a=reshape(data,100000,2);%It is divided into two columns
a1=a(:,1);   %the first column representing the real part
b1=a(:,2);   %the second column representing the imaginary part
s = a1+b1*i; % a bit vector of length 100000
q1=0+0*i;    %represent θm=pi/4
q2=0+1*i;    %represent θm=3pi/4
q3=1+1*i;    %represent θm=5pi/4
q4=1+0*i;    %represent θm=7pi/4
sig=zeros(100000,1); % sig represent the original signal

for i=1:100000  %loop for modulation
    if (s(i)==q1)
       x=sqrt(2)/2; y=sqrt(2)/2; %corresponding to 00
       sig(i)=x+y*1i; %save the complex number
    end

    if (s(i)==q2)
       x=-sqrt(2)/2; y=sqrt(2)/2; %corresponding to 01
       sig(i)=x+y*1i; %save the complex number
    end
    if (s(i)==q3)
       x=-sqrt(2)/2; y=-sqrt(2)/2; %corresponding to 11
       sig(i)=x+y*1i; %save the complex number
    end
    if (s(i)==q4)
       x=sqrt(2)/2; y=-sqrt(2)/2; %corresponding to 10
       sig(i)=x+y*1i; %save the complex number
    end
end

%Transmitter constellation point(theoretical):
send_set = [(sqrt(2)/2)+1i*(sqrt(2)/2),-(sqrt(2)/2)+1i*(sqrt(2)/2),-(sqrt(2)/2)-1i*(sqrt(2)/2),(sqrt(2)/2)-1i*(sqrt(2)/2)];    

SNR = [0,2,4,6]; %four different SNR values
distance=zeros(1,4);% preset distance
detect=zeros(1,100000); %preset detect value
BEP=zeros(1,length(SNR)); %preset BEP

for p=1:4  % loop for four SNR
    error=0;%initial error value
    sigPower = sum(abs(sig).^2)/length(sig);  %Find the signal power
    noisePower=(sigPower/(10^(SNR(p)/10)))/2;  %Find the noise power
    noise = sqrt(noisePower/2)* (randn(size(sig)) + 1i*randn(size(sig))); %generate the Gaussian noise
    sig_noise = sig+noise; % generate the signal after adding the noise
   
    for t = 1:100000 %loop for 100000 points demodulation
        for w = 1:4 % check distance
            distance(w) = norm(sig_noise(t) - send_set(w))^2;%The distance of the received signal to all constellation points
        end
        position= find(distance == min(distance));%The position of the minimum distance from the constellation      
        detect(t) = send_set(position);  %The symbol after demodulation               
        if (detect(t)~= sig(t))  %Count the number of error symbols
            error = error + 1;      
        end  
    end
    BEP(p) = error/200000;  %Error symbol rate of QPSK simulation
    
end


%%%%%%%%%%%%% 计算理论值 %%%%%%%%%%%%%%%

SNR1=zeros(1,4); %preset SNR1 (not in db)
Pb=zeros(1,4);   %preset theoretical BEP
for m=1:4        %loop to change db into real value
    SNR1=10^(SNR(m)/10);
    Pb(m)=log10((0.5)*erfc(sqrt(2*SNR1)/sqrt(2))); % calculate theoretical BEPs
end

SNR_mag = 10.^(SNR/10) ;         %Change the SNR from dB to magnatitude
Pb = 1/2*erfc(sqrt(SNR_mag));    
semilogy(SNR,BEP,'o',SNR,Pb);
grid on
xlabel('SNR(dB)')    %abscissa
ylabel('BEP')    %ordinate
title('Bit error probability for differnet SNR'); %title
legend('Simulated BEPs','theoretical BEPs');      %legend

结果:

格雷映射-误码率讲解及MATLAB仿真 part3_第2张图片

补充:
理论值计算方法:

格雷映射-误码率讲解及MATLAB仿真 part3_第3张图片

你可能感兴趣的:(通信工程,matlab,网络通信)