Cep Matlab Code
Cep Matlab Code
theoryBer = 3/2*erfc(sqrt(0.1*(10.^(Es_N0_dB/10))));
figure
semilogy(Es_N0_dB,theoryBer,'b.-','LineWidth',2);
hold on
semilogy(Es_N0_dB,simBer,'mx-','Linewidth',2);
axis([0 20 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Es/No, dB')
ylabel('Symbol Error Rate')
title('Symbol error probability curve for 16-QAM modulation')
% Maximum Likelihood Receiver
%if [s1 s2]=[+1,+1]
sHat1=[1+j,-1+j];
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+j -1-j];
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+j 1-j];
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+j 1-j];
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);
metric_tmp = sqrt(Esti_y4'*Esti_y4);
final_dis=reshape (Esti_y4,5,N);
if metric_tmp<metric
X_hat = x_tmp; metric = metric_tmp;
end
end
end
end
end
for k=1:N
%% decision process
[val,index]=min(abs(C-Esti_y4(k)));
bkest(k)=index-1;
%best(i)=id-1;
% BER computation
end
new_errors=biterr(bkest, bk);
total_errors(i)=(total_errors(i)+new_errors);
ber3(i)=total_errors(i)/(j*log2(M)*N);
% % nErr(i) = size(find([dk- pHat]),2); % Counts the # errors
% ber3 = nErr/N; % simulated ber semilogy(snr,ber3,'g-');
% plots the ber for legend('MMSE','ZF', 'ML'); xlabel('SNR (dB)'); ylabel('BER');
title('BER Performance of Different V-BLAST Detection Schemes over 2x10 MIMO
Channels with Rayleigh Channel'); axis([0 20 10^-6 0.5]) grid on
% 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);
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));
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 QAM modulation with 2x2 MIMO and ML equalizer (Rayleigh channel)');