% Script for computing the BER for BPSK modulation in a
% Rayleigh fading channel with 2 Tx, 2Rx MIMO channel
%with ZF,ML and MMSE recievers
clear
N = 10^6; % number of bits or symbols
Eb_N0_dB = [0:25]; % multiple Eb/N0 values
nTx = 2;
nRx = 2;
disp('Simulating for 2X2 BPSK System with different equalizers.....................Please wait')
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;
% Receiver for ZF equalization matrix W = inv(H^H*H)*H^H
% H^H*H is of dimension [nTx x nTx]. In this case [2 x 2]
% Inverse of a [2x2] matrix [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 term
hCof(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1) ; % a term
hCof(2,1,:) = -sum(h(:,2,:).*conj(h(:,1,:)),1); % c term
hCof(1,2,:) = -sum(h(:,1,:).*conj(h(:,2,:)),1); % b term
hDen = ((hCof(1,1,:).*hCof(2,2,:)) - (hCof(1,2,:).*hCof(2,1,:))); % ad-bc term
hDen = reshape(kron(reshape(hDen,1,N/nTx),ones(2,2)),2,2,N/nTx); % formatting for division
hInv = hCof./hDen; % inv(H^H*H)
hMod = reshape(conj(h),nRx,N); % H^H operation
yMod = kron(y,ones(1,2)); % formatting the received symbol for equalization
yMod = sum(hMod.*yMod,1); % H^H * y
yMod = kron(reshape(yMod,2,N/nTx),ones(1,2)); % formatting
yHat = sum(reshape(hInv,2,N).*yMod,1); % inv(H^H*H)*H^H*y
% receiver - hard decision decoding on second spatial dimension
ipHat2SS = real(yHat(2:2:end))>0;
ipHatMod2SS = 2*ipHat2SS-1;
ipHatMod2SS = kron(ipHatMod2SS,ones(nRx,1));
ipHatMod2SS = reshape(ipHatMod2SS,[nRx,1,N/nTx]);
% new received symbol - removing the effect from second spatial dimension
h2SS = h(:,2,:); % channel in the second spatial dimension
r = y - squeeze(h2SS.*ipHatMod2SS);
% maximal ratio combining - for symbol in the first spatial dimension
h1SS = squeeze(h(:,1,:));
yHat1SS = sum(conj(h1SS).*r,1)./sum(h1SS.*conj(h1SS),1);
yHat(1:2:end) = yHat1SS;
% receiver - hard decision decoding
ipHat = real(yHat)>0;
% counting the errors
nErr(ii) = size(find([ip- ipHat]),2);
% Receiver for the MMSE equalization matrix W = inv(H^H*H + sigma^2*I)*H^H
% H^H*H is of dimension [nTx x nTx]. In this case [2 x 2]
% Inverse of a [2x2] matrix [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) + 0*10^(-Eb_N0_dB(ii)/10); % d term
hCof(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1) + 0*10^(-Eb_N0_dB(ii)/10); % a term
hCof(2,1,:) = -sum(h(:,2,:).*conj(h(:,1,:)),1); % c term
hCof(1,2,:) = -sum(h(:,1,:).*conj(h(:,2,:)),1); % b term
for kk = 1:2
if kk == 1
sortIdx = [];
hCof(1,1,:) = sum(h(:,2,:).*conj(h(:,2,:)),1) + 10^(-Eb_N0_dB(ii)/10); % d term
hCof(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1) + 10^(-Eb_N0_dB(ii)/10); % a term
hCof(2,1,:) = -sum(h(:,2,:).*conj(h(:,1,:)),1); % c term
hCof(1,2,:) = -sum(h(:,1,:).*conj(h(:,2,:)),1); % b term
elseif kk == 2
% Sorting the equalization matrix based on the channel power on each dimension
% since the second spatial dimension is equalized first, the channel
% with higher power assigned to second dimension
normSS1 = squeeze(hCof(2,2,:));
normSS2 = squeeze(hCof(1,1,:));
sortIdx = find(normSS2 < normSS1);
end
% sorting the H^H*H + sigma^2*I matrix
hCofSort = hCof;
if ~isempty(sortIdx)
hCofSort(2,2,sortIdx) = hCof(1,1,sortIdx) + 10^(-Eb_N0_dB(ii)/10);;
hCofSort(1,1,sortIdx) = hCof(2,2,sortIdx) + 10^(-Eb_N0_dB(ii)/10);;
hCofSort(1,2,sortIdx) = hCof(2,1,sortIdx);
hCofSort(2,1,sortIdx) = hCof(1,2,sortIdx);
end
hDen = ((hCofSort(1,1,:).*hCofSort(2,2,:)) - (hCofSort(1,2,:).*hCofSort(2,1,:))); % ad-bc term
hDen = reshape(kron(reshape(hDen,1,N/nTx),ones(2,2)),2,2,N/nTx); % formatting for division
hInvSort = hCofSort./hDen; % inv(H^H*H)
% sorting the H matrix
hSort = h;
if ~isempty(sortIdx)
hSort(:,2,sortIdx) = h(:,1,sortIdx);
hSort(:,1,sortIdx) = h(:,2,sortIdx);
end
% Equalization - Zero forcing
hModSort = reshape(conj(hSort),nRx,N); % H^H operation
yModSort = kron(y,ones(1,2)); % formatting the received symbol for equalization
yModSort = sum(hModSort.*yModSort,1); % H^H * y
yModSort = kron(reshape(yModSort,2,N/nTx),ones(1,2)); % formatting
yHatSort = sum(reshape(hInvSort,2,N).*yModSort,1); % inv(H^H*H)*H^H*y
% receiver - hard decision decoding on second spatial dimension
ipHat2SS = real(yHatSort(2:2:end))>0;
ipHatMod2SS = 2*ipHat2SS-1;
ipHatMod2SS = kron(ipHatMod2SS,ones(nRx,1));
ipHatMod2SS = reshape(ipHatMod2SS,[nRx,1,N/nTx]);
% new received symbol - removing the effect from second spatial dimension
h2SS = hSort(:,2,:); % channel in the second spatial dimension
r = y - squeeze(h2SS.*ipHatMod2SS);
% maximal ratio combining - for symbol in the first spatial dimension
h1SS = squeeze(hSort(:,1,:));
yHat1SS = sum(conj(h1SS).*r,1)./sum(h1SS.*conj(h1SS),1);
yHatSort(1:2:end) = yHat1SS;
yHatSort = reshape(yHatSort,2,N/2) ;
if ~isempty(sortIdx)
yHatSort(:,sortIdx) = flipud(yHatSort(:,sortIdx));
end
yHat = reshape(yHatSort,1,N);
% receiver - hard decision decoding
ipHat = real(yHat)>0;
% counting the errors
nErr2(kk,ii) = size(find([ip- ipHat]),2);
end
% 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
nErr3(ii) = size(find([ip- ipHat]),2);
end
simBer = nErr/N; % simulated ber
simBer2 = nErr2/N;
simBer3 = nErr3/N;
EbN0Lin = 10.^(Eb_N0_dB/10);
theoryBer
没有合适的资源?快使用搜索试试~ 我知道了~
equalizers_bpsk.rar_Different
共1个文件
m:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 105 浏览量
2022-07-14
02:20:45
上传
评论
收藏 2KB RAR 举报
温馨提示
Comparison of different Equalizers for mimo
资源推荐
资源详情
资源评论
收起资源包目录
equalizers_bpsk.rar (1个子文件)
equalizers_bpsk.m 9KB
共 1 条
- 1
资源评论
寒泊
- 粉丝: 76
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功