MIMO 检测算法 ML、ZF、MMSE 等(采用 BPSK 调制,平坦瑞利信道)

  • u2_120186
    了解作者
  • 2.4KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 1
    下载次数
  • 2022-04-20 03:26
    上传日期
MIMO检测算法ML,ZF,MMSE等。采用BPSK调制,平坦瑞利信道 (MIMO detection algorithm ML, ZF, MMSE, etc. Using BPSK modulation, flat Rayleigh channel)
mimo_ml_zf_mmse_bpsk_rayleigh_channel.zip
  • mimo_ml_zf_mmse_bpsk_rayleigh_channel.m
    7KB
内容介绍
%% % ML-ZF-MMSE 检测算法比较 % bpsk调制-瑞利衰落信道-2个发送端,2个接收端 %% clc clear N = 10^4; % 发送的符号数目 Eb_N0_dB = 0:20; % 信噪比范围 nTx = 2; nRx = 2; %% %ML for ii = 1:length(Eb_N0_dB) % 发送端 ip = rand(1,N)>0.5; % 等概率产生0和1 s = 2*ip-1; % BPSK 调制 0 -> -1; 1 -> 0 sMod = kron(s,ones(nRx,1)); % sMod = reshape(sMod,[nRx,nTx,N/nTx]); % 将矩阵转换为[nRx,nTx,N/nTx ]形式 h = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; % 瑞利衰落信道 n = 1/sqrt(2)*[randn(nRx,N/nTx) + j*randn(nRx,N/nTx)]; % 0均值高斯白噪声 % 加入噪声后在信道中传输 % a = h.*sMod; %将两个矩阵的第三维分别相乘 % b = sum(h.*sMod,2);%将第三维加为一列 % c = squeeze(sum(h.*sMod,2));%变换为2x10矩阵 % d = 10^(-Eb_N0_dB(ii)/20)*n;%噪声为2x10矩阵 y = squeeze(sum(h.*sMod,2)) + 10^(-Eb_N0_dB(ii)/20)*n; % 最大似然接收 % ---------------------------- % 当 [s1 s2 ] = [+1,+1 ] sHat1 = [1 1]; sHat1 = repmat(sHat1,[1 ,N/2]); sHat1Mod = kron(sHat1,ones(nRx,1)); sHat1Mod = reshape(sHat1Mod,[nRx,nTx,N/nTx]); %发送矩阵 zHat1 = squeeze(sum(h.*sHat1Mod,2)) ; %接收矩阵 %e = abs(y - zHat1); %取理论接收与实际接收的绝对值 J11 = sum(abs(y - zHat1),1);%将两行加为一行 % 当 [s1 s2 ] = [+1,-1 ] sHat2 = [1 -1]; sHat2 = repmat(sHat2,[1 ,N/2]); sHat2Mod = kron(sHat2,ones(nRx,1)); sHat2Mod = reshape(sHat2Mod,[nRx,nTx,N/nTx]); zHat2 = squeeze(sum(h.*sHat2Mod,2)) ; J10 = sum(abs(y - zHat2),1); % 当 [s1 s2 ] = [-1,+1 ] sHat3 = [-1 1]; sHat3 = repmat(sHat3,[1 ,N/2]); sHat3Mod = kron(sHat3,ones(nRx,1)); sHat3Mod = reshape(sHat3Mod,[nRx,nTx,N/nTx]); zHat3 = squeeze(sum(h.*sHat3Mod,2)) ; J01 = sum(abs(y - zHat3),1); % 当 [s1 s2 ] = [-1,-1 ] sHat4 = [-1 -1]; sHat4 = repmat(sHat4,[1 ,N/2]); sHat4Mod = kron(sHat4,ones(nRx,1)); sHat4Mod = reshape(sHat4Mod,[nRx,nTx,N/nTx]); zHat4 = squeeze(sum(h.*sHat4Mod,2)) ; J00 = sum(abs(y - zHat4),1); % 从四组数值中找出最小值jj,所在位置dd rVec = [J11;J10;J01;J00]; [jj dd] = min(rVec,[],1); % mapping the minima to bits ref = [1 1; 1 0; 0 1; 0 0 ]; ipHat = zeros(1,N); ipHat(1:2:end) = ref(dd,1); ipHat(2:2:end) = ref(dd,2); % 统计错误 f = find([ip - ipHat]);%发生错误所在位置 nErrML(ii) = size(find([ip - ipHat]),2);%错误个数 end %% %ZF for ii = 1:length(Eb_N0_dB) % 发送端 ip = rand(1,N)>0.5; % 等概率生成 0,1 s = 2*ip-1; % BPSK 调制 0 -> -1; 1 -> 0 %a = ones(nRx,1) sMod = kron(s,ones(nRx,1)); % sMod = reshape(sMod,[nRx,nTx,N/nTx]); % 变换矩阵形式为[nRx,nTx,N/NTx ] h = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; % 瑞利信道 n = 1/sqrt(2)*[randn(nRx,N/nTx) + j*randn(nRx,N/nTx)]; % 0均值高斯白噪声 % 加入白噪声后在信道中传输 y = squeeze(sum(h.*sMod,2)) + 10^(-Eb_N0_dB(ii)/20)*n; % 接收端 % 求伪逆矩阵 G = inv(H^H*H)*H^H % H^H*H 的矩阵维数为 [nTx x nTx]. 即 [2 x 2] % [2x2]矩阵的转置为 [a b; c d] = 1/(ad-bc)[d -b;-c a] hCof = zeros(2,2,N/nTx); hCof(1,1,:) = sum(h(:,2,:).*conj(h(:,2,:)),1); % d hCof(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1); % a hCof(2,1,:) = -sum(h(:,2,:).*conj(h(:,1,:)),1); % c hCof(1,2,:) = -sum(h(:,1,:).*conj(h(:,2,:)),1); % b hDen = ((hCof(1,1,:).*hCof(2,2,:)) - (hCof(1,2,:).*hCof(2,1,:))); % ad-bc hDen = reshape(kron(reshape(hDen,1,N/nTx),ones(2,2)),2,2,N/nTx); % hInv = hCof./hDen; % inv(H^H*H) hMod = reshape(conj(h),nRx,N); % H^H yMod = kron(y,ones(1,2)); % 接收信号矩阵化 yMod = sum(hMod.*yMod,1); % H^H * y yMod = kron(reshape(yMod,2,N/nTx),ones(1,2)); % yHat = sum(reshape(hInv,2,N).*yMod,1); % inv(H^H*H)*H^H*y % 接收端 硬判决解码 ipHat = real(yHat)>0; % 统计错误 nErrZF(ii) = size(find([ip- ipHat]),2); end %% %MMSE for ii = 1:length(Eb_N0_dB) % 发送端 ip = rand(1,N)>0.5; s = 2*ip-1; % BPSK 调制 0 -> -1; 1 -> 0 sMod = kron(s,ones(nRx,1)); % sMod = reshape(sMod,[nRx,nTx,N/nTx]); % [nRx,nTx,N/NTx ] h = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; n = 1/sqrt(2)*[randn(nRx,N/nTx) + j*randn(nRx,N/nTx)]; % 加入高斯白噪声后在信道中传输 y = squeeze(sum(h.*sMod,2)) + 10^(-Eb_N0_dB(ii)/20)*n; % 接收端 % MMSE W = inv(H^H*H+sigma^2*I)*H^H % H^H*H i的维数为[nTx x nTx]. 即[2 x 2] % [2x2]矩阵的逆 [a b; c d] = 1/(ad-bc)[d -b;-c a] hCof = zeros(2,2,N/nTx) ; hCof(1,1,:) = sum(h(:,2,:).*conj(h(:,2,:)),1) + 10^(-Eb_N0_dB(ii)/10); % d hCof(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1) + 10^(-Eb_N0_dB(ii)/10); % a hCof(2,1,:) = -sum(h(:,2,:).*conj(h(:,1,:)),1); % c hCof(1,2,:) = -sum(h(:,1,:).*conj(h(:,2,:)),1); % b hDen = ((hCof(1,1,:).*hCof(2,2,:)) - (hCof(1,2,:).*hCof(2,1,:))); % ad-bc hDen = reshape(kron(reshape(hDen,1,N/nTx),ones(2,2)),2,2,N/nTx); hInv = hCof./hDen; % inv(H^H*H) hMod = reshape(conj(h),nRx,N); % H^H yMod = kron(y,ones(1,2)); yMod = sum(hMod.*yMod,1); % H^H * y yMod = kron(reshape(yMod,2,N/nTx),ones(1,2)); yHat = sum(reshape(hInv,2,N).*yMod,1); % inv(H^H*H)*H^H*y %接收端 ipHat = real(yHat)>0; % 统计错误 nErrMMSE(ii) = size(find([ip- ipHat]),2); end %% %无衰落bpsk调制 for ii = 1:length(Eb_N0_dB) % Transmitter ip = rand(1,N)>0.5; s = 2*ip-1; n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % Noise addition y = s + 10^(-Eb_N0_dB(ii)/20)*n; % additive white gaussian noise % receiver - hard decision decoding ipHat = real(y)>0; % counting the errors nErrBPSK(ii) = size(find([ip- ipHat]),2); end %% %比特错误率 simBer1 = nErrML/N; % 仿真比特错误率 simBer2 = nErrZF/N; simBer3 = nErrMMSE/N; % simBer4 = nErrBPSK/N; EbN0Lin = 10.^(Eb_N0_dB/10); % theoryBer_nRx1 = 0.5.*(1-1*(1+1./EbN0Lin).^(-0.5)); % p = 1/2 - 1/2*(1+1./EbN0Lin).^(-1/2); % theoryBerMRC_nRx2 = p.^2.*(1+2*(1-p)); theoryBerBPSK = 0.5*erfc(sqrt(EbN0Lin)); % bpsk theoretical ber 0.5erfc(sqrt(r)) %% %作图 close all figure % semilogy(Eb_N0_dB,theoryBer_nRx1,'bp-','LineWidth',2); % semilogy(Eb_N0_dB,theoryBerMRC_nRx2,'kd-','LineWidth',2); semilogy(Eb_N0_dB,simBer1,'*g-','LineWidth',2); %ML hold on semilogy(Eb_N0_dB,simBer2,'oy-','LineWidth',2); %ZF semilogy(Eb_N0_dB,simBer3,'+r-','LineWidth',2); %MMSE % semilogy(Eb_N0_dB,simBer4,'mx-','LineWidth',2); semilogy(Eb_N0_dB,theoryBerBPSK,'b.-','LineWidth',2); %BPSK axis([0 20 10^-5 0.5]) grid on legend('sim (nTx=2, nRx=2, ML)','sim (nTx=2, nRx=2, ZF)','sim (nTx=2, nRx=2, MMSE)', 'theory BPSK'); % legend('theory (nTx=1,nRx=1)', 'theory (nTx=1,nRx=2, MRC)', 'sim (nTx=2, nRx=2, ML)','sim (nTx=2, nRx=2, ZF)','sim (nTx=2, nRx=2, MMSE)', 'theory BPSK'); xlabel('Average Eb/No,dB'); ylabel('Bit Error Rate'); title('BER for BPSK modulation with 2x2 MIMO and three kinds of equalizer (Rayleigh channel)');
评论