ML算法的matlab源码
clear
N = 50000; % number of bits or symbols
Eb_N0_dB = [0:20]; % multiple Eb/N0 values
nTx = 2;
nRx = 2;
for ii = 1:length(Eb_N0_dB)
% Transmitter
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
sMod = kron(s,ones(nRx,1)); %
sMod = reshape(sMod,[nRx,nTx,N/nTx]); % grouping in [nRx,nTx,N/NTx ] matrix
h = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; % Rayleigh channel
n = 1/sqrt(2)*[randn(nRx,N/nTx) + j*randn(nRx,N/nTx)]; % white gaussian noise, 0dB variance
% Channel and noise Noise addition
y = squeeze(sum(h.*sMod,2)) + 10^(-Eb_N0_dB(ii)/20)*n;
% Maximum Likelihood Receiver
% ----------------------------
% if [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)) ;
J11 = sum(abs(y - zHat1),1);
% if [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);
% if [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);
% if [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);
% finding the minimum from the four alphabet combinations
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);
% counting the errors
nErr(ii) = size(find([ip- ipHat]),2);
end
simBer = nErr/N; % simulated ber
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));
close all
figure
semilogy(Eb_N0_dB,theoryBer_nRx1,'bp-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBerMRC_nRx2,'kd-','LineWidth',2);
semilogy(Eb_N0_dB,simBer,'mo-','LineWidth',2);
axis([0 25 10^-5 0.5])
grid on
legend('theory (nTx=1,nRx=1)', 'theory (nTx=1,nRx=2, MRC)', 'sim (nTx=2, nRx=2, ML)');
xlabel('Average Eb/No,dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with 2x2 MIMO and ML equalizer (Rayleigh channel)');
相关文章
- [matlab] 6.粒子群优化算法
- matlab sum函数
- 3D-MIMO信道模型的理论概述和matlab仿真
- 基于BP/RBF神经网络的在线信道估计均衡算法matlab仿真
- 基于PSO的运输优化算法的MATLAB仿真
- 基于协同滤波的个性化推荐算法matlab仿真
- 【BOC同步跟踪】BOC信号跟踪算法的MATLAB仿真
- 【MATLAB教程案例94】基于Matlab的IHS图像融合算法仿真案例
- 【MATLAB教程案例78】基于GA优化的WSN最大覆盖率matlab仿真——扩展到任意一种优化算法解决WSN覆盖率问题
- 【MATLAB教程案例61】使用matlab实现基于ResNet残差网络的数据分类仿真分析
- 【MATLAB教程案例9】信道编译码之turbo编码译码算法matlab误码率仿真
- 规则LDPC和不规则LDPC译码算法MATLAB仿真
- 通过EM算法的参数辨识和分类识别matlab仿真
- 基于MATLAB的指纹识别算法仿真实现
- 基于SVM支持向量机的车牌分割识别算法matlab仿真
- 【AES图像加解密】基于AES图像加解密算法的MATLAB仿真
- 雷达回波信号的脉冲压缩matlab仿真
- 在MATLAB和OpenCV1.x环境下写的灰度图像分段线性变换源码
- 《数字图像处理与机器视觉——Visual C++与Matlab实现(第2版)》——第 1 章 MATLAB数字图像处理编程基础2.1 MATLAB R2011a简介
- 【Matlab算法】粒子群算法求解一维非线性函数问题(附MATLAB代码)
- 【Matlab算法】MATLAB求解背包问题(附MATLAB代码)
- 【Matlab算法】修正G-N法求解非线性最小二乘优化问题(附修正G-N法MATLAB代码)
- 【Matlab算法】进退法迭代求解无约束一维极值问题(附进退法MATLAB代码)
- MATLAB | 我用MATLAB复刻了这场颜色图生成大赛的作品
- 余胜威《MATLAB数学建模经典案例实战》2015年版
- matlab学习笔记一