MIMO系统ML检测(最大似然检测)

 
Nt = 2 ;
Nr = 2 ;
Len = 10000 ;
M= 4 ;
bitsPerSymbol = log2(M) ;
bitsTotal = bitsPerSymbol * Nt * Len ;

ALP = [-1+1i  ;-1-1* 1i ;1+1i ;1-1i] * sqrt(3/(2*(M-1)))  ; %QAM符号
%ALPbin = dec2bin( 0:M-1 , log2(M))  ; %QAM的二进制编码
SNRVect = 0:2:20 ;
SER = zeros( 1 ,length(SNRVect) )  ;
for snrLoop =  1: length (SNRVect)
    fprintf(' snrLoop = %d \n',snrLoop) ;
    %计算信噪比
    SNRdB = SNRVect(snrLoop) ;
    SNR  = 10^(SNRdB/10) ;
    %此处我们假设每根天线发送的信号能量为1   
    %N0 表示噪声的能量
    N0 = Nt * 1 / SNR ;   

    %产生随机比特流
    send = round(rand(1,bitsTotal)) ;
    sendReshape = reshape(send , Nt * bitsPerSymbol , Len ) ;
    symbols = zeros(Nt, Len) ;
    symbolsModulation = zeros(Nt ,Len) ;
    %发送端 4QAM调制
    fprintf('\n正在调制并发送 \n') ;
    for sendLoop = 1 :Len
        for antennaLoop = 1: Nt
            twoBits = sendReshape ( 2* antennaLoop-1 :2* antennaLoop, sendLoop) ;
            symbols  ( antennaLoop ,sendLoop)  = 2 * twoBits(1) + 1 * twoBits(2) +1 ;
            symbolsModulation ( antennaLoop ,sendLoop) = ALP(symbols  ( antennaLoop ,sendLoop) ) ;
        end
    end
    %经过信道
    H = (randn(Nr, Nt) + sqrt(-1) * randn(Nr , Nt))/ sqrt(2)  ; % 除以sqrt(2) 保证信道的能量为1
    n = (randn(Nr , Len) + sqrt(-1)*randn(Nr, Len )) * sqrt(N0) /sqrt(2) ; %保证噪声 n ~N(0,N0)
    y = H* symbolsModulation + n ;
    %接收端
    fprintf('\n正在译码 \n') ;
    symbolsDetect = zeros(2 , Len) ;
    for sendLoop = 1 :Len
         fprintf('%d %d \n',snrLoop ,sendLoop) ;
        %得到M*M种组合
        dml = zeros(M ,M ,Len) ;
        for i1 = 1:M
            for i2 = 1:M
                dml(i1, i2, sendLoop) = (norm (  y(: , sendLoop) - H * [ALP(i1) ; ALP(i2)] ) )  .^2 ; % 共16种组合
            end
        end
        dml_min = min( reshape(dml( :, :, sendLoop ) .' , 1, M*M)  ) ;
        %找到最合适的  然后译码
        for j1 = 1: M ;
            for j2 = 1:M
                if dml(j1 , j2, sendLoop) ==dml_min ;
                    symbolsDetect(1, sendLoop) = j1 ;
                    symbolsDetect(2, sendLoop) = j2 ;
                end
            end
        end

    end
    % 一个信噪比结束  统计SER
    SER(snrLoop)  = sum ( reshape(symbolsDetect , 1, Len * Nt) ~= reshape (symbols , 1, Len *Nt) )/ (Len * Nt) ;
end

semilogy( 0: 2 : 20 , SER)
  L=1000时,仿真结果如下: MIMO系统ML检测(最大似然检测)

你可能感兴趣的:(代码,matlab,ml,MIMO)