[Sphere Decoding] Simulation of spherical decoding under five modulation modes of BPSK, QPSK, 8PSK, 4QAM and 16QAM based on MATLAB

1. Software version

MATLAB2021a

2. Part of the core code

clear all   
Nt=2;                                                        
co_time=2;                                                  
Nr=2;                                                              
Nit=1000;                                                        
M_psk=16;  

x=pi/6;
%x=0.5;
m=exp(j*x);
n=sqrt(m);

snr_min=0;                                                         
snr_max=20;                                                       
graph_inf_bit=zeros(snr_max-snr_min+1,2);                          
graph_inf_sym=zeros(snr_max-snr_min+1,2);                          
num_X=4;
num_bit_per_sym=log2(M_psk);                                     
co_x=zeros(num_X,1);
for SNR=snr_min:snr_max                                          
    clc
    disp('Wait until SNR=');disp(snr_max);
    SNR
    n_err_bit=0;
    graph_inf_bit(SNR-snr_min+1,1)=SNR;
    for con_sym=1:Nit                                               
       bi_data=randint(num_X,num_bit_per_sym);
        
        for i=1:4
           if bi_data(i,:)==[0 0 0 0]
                data(i,1)=3+3*j;
            elseif bi_data(i,:)==[0 1 0 0]
                data(i,1)=3+j;
            elseif bi_data(i,:)==[1 1 0 0]
                data(i,1)=3-j;
            elseif bi_data(i,:)==[1 0 0 0]
                data(i,1)=3-3*j;
            elseif bi_data(i,:)==[0 0 0 1]
                data(i,1)=1+3*j;
            elseif bi_data(i,:)==[0 1 0 1]
                data(i,1)=1+j;
            elseif bi_data(i,:)==[1 1 0 1]
                data(i,1)=1-j;
            elseif bi_data(i,:)==[1 0 0 1]
                data(i,1)=1-3*j;
            elseif bi_data(i,:)==[0 0 1 1]
                data(i,1)=-1+3*j;
            elseif bi_data(i,:)==[0 1 1 1]
                data(i,1)=-1+j;
            elseif bi_data(i,:)==[1 1 1 1]
                data(i,1)=-1-j;
            elseif bi_data(i,:)==[1 0 1 1]
                data(i,1)=-1-3*j;
            elseif bi_data(i,:)==[0 0 1 0]
                data(i,1)=-3+3*j;
            elseif bi_data(i,:)==[0 1 1 0]
                data(i,1)=-3+j;
            elseif bi_data(i,:)==[1 1 1 0]
                data(i,1)=-3-j;
            else data(i,1)=-3-3*j;
            end
        end
        H1=(randn(Nt,Nr)+j*randn(Nt,Nr))/sqrt(2);
        
        X1=zeros(co_time,Nt);
       
       % X1=[data(1,1)+data(2,1)  data(3,1)-data(4,1)
       %     data(3,1)+data(4,1)  data(1,1)-data(2,1)]; 
         X1=[data(1,1)+m*data(2,1)  n*(data(3,1)-m*data(4,1))
             n*(data(3,1)+m*data(4,1))  data(1,1)-m*data(2,1)];      
        
        snr_de=10^(SNR/10);
        sig=sqrt(Nt/snr_de);
        Noise1=sig*(randn(co_time,Nr)+j*randn(co_time,Nr))/sqrt(2);
        
        R1=H1*X1+Noise1;
        Noise2=reshape(Noise1,4,1);
        
        I=eye(2,2);
        H2=kron(I,H1);
        %M=[1 1 0 0
        %   0 0 1 1
        %   0 0 1 -1
        %   1 -1 0 0];
        M=[1  m  0  0
           0  0  n  m*n
           0  0  n -m*n
           1 -m  0  0];
        C=[data(1,1);data(2,1);data(3,1);data(4,1)];
        %C=[data(1,1);m*data(2,1);n*data(3,1);m*n*data(4,1)];
        R2=H2*M*C+Noise2;
        
        G=[real(H2*M) -imag(H2*M);imag(H2*M) real(H2*M)];
        CC=[real(C);imag(C)];
        Noise=[real(Noise2);imag(Noise2)];
        RR=G*CC+Noise;
        S=[real(data(1,1))
           imag(data(1,1))
           real(data(2,1))
           imag(data(2,1))
           real(data(3,1))
           imag(data(3,1))
           real(data(4,1))
           imag(data(4,1))];
        
        H=[G(:,1) G(:,5) G(:,2) G(:,6) G(:,3) G(:,7) G(:,4) G(:,8)];
        R=H*S+Noise;
        C1=(2*Nt)*(2/(10^(SNR/10)));
        codebook=[-3 -1 1 3];
        
        y_2norm_temp = spheredecodetoML(R, C1, H, codebook);
           
        rr=[y_2norm_temp(1)+j*y_2norm_temp(2)
            y_2norm_temp(3)+j*y_2norm_temp(4)
            y_2norm_temp(5)+j*y_2norm_temp(6)
            y_2norm_temp(7)+j*y_2norm_temp(8)];
        
      
       U=[0 0 0 0;0 1 0 0;1 1 0 0;1 0 0 0;0 0 0 1;0 1 0 1;1 1 0 1;1 0 0 1;0 0 1 1;0 1 1 1;1 1 1 1;1 0 1 1;0 0 1 0;0 1 1 0;1 1 1 0;1 0 1 0];
       X=[3+3*j;3+j;3-j;3-3*j;1+3*j;1+j;1-j;1-3*j;-1+3*j;-1+j;-1-j;-1-3*j;-3+3*j;-3+j;-3-j;-3-3*j];
       Dis=zeros(4,16);
       re_met_bit=zeros(4,4);
for a=1:4
    for b=1:16
        Dis(a,b)=abs(rr(a,1)-X(b,1))^2;
    end
[Dis,index]=sort(Dis,2);
re_met_bit(a,:)=U(index(a,1),:);
end
                
        for con_dec_ro=1:num_X                                            
            for con_dec_co=1:num_bit_per_sym
                if re_met_bit(con_dec_ro,con_dec_co)~=bi_data(con_dec_ro,con_dec_co)
                   n_err_bit=n_err_bit+1;
                end
            end
        end
    end
   
    Perr_bit=n_err_bit/(num_X*Nit*num_bit_per_sym);
    graph_inf_bit(SNR-snr_min+1,2)=Perr_bit;
end

x_bit=graph_inf_bit(:,1);
y_bit=graph_inf_bit(:,2);
semilogy(x_bit,y_bit,'g-o');
xlabel('SNR, [dB]');
ylabel('Bit Error Probability');
grid on

3. Operation steps and simulation conclusion

16QAM

4QAM 

 8PSK

QPSK

 

BPSK

4. References

[1] Liu Jun, Wei Jibo, Lan Xing. Application of spherical decoding algorithm in MIMO system [J]. Modern Electronic Technology, 2008, 31(5):3.

D233

5. How to obtain the complete source code

Method 1: Contact the blogger via WeChat or QQ

Method 2: Subscribe to the MATLAB/FPGA tutorial, get the tutorial case and any 2 complete source code for free

Guess you like

Origin blog.csdn.net/ccsss22/article/details/124207557