0% found this document useful (0 votes)
212 views

Cep Matlab Code

This MATLAB code simulates a 2x2 QAM MIMO system using maximum likelihood (ML) detection over a Rayleigh flat fading channel. It generates 16-QAM symbols, adds them to a 2x2 Rayleigh channel, and adds white Gaussian noise. It then performs ML detection by computing the distance between the received signal and all possible transmitted signal combinations to find the most likely transmitted symbols. It calculates the bit error rate (BER) by comparing the detected and transmitted symbols over a range of signal-to-noise ratio (SNR) values, and plots the theoretical and simulated BER curves.

Uploaded by

Muhammad Furqan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views

Cep Matlab Code

This MATLAB code simulates a 2x2 QAM MIMO system using maximum likelihood (ML) detection over a Rayleigh flat fading channel. It generates 16-QAM symbols, adds them to a 2x2 Rayleigh channel, and adds white Gaussian noise. It then performs ML detection by computing the distance between the received signal and all possible transmitted signal combinations to find the most likely transmitted symbols. It calculates the bit error rate (BER) by comparing the detected and transmitted symbols over a range of signal-to-noise ratio (SNR) values, and plots the theoretical and simulated BER curves.

Uploaded by

Muhammad Furqan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Making a 2x2 QAM MIMO system using ML detection in

Rayleigh flat fading channel.


MATLAB Code:
% Script for computing the BER for 16 QAM modulation in a
% Rayleigh fading channel with 2 Tx, 2Rx MIMO channel
% Maximum Likelihood equalization
% symbol error rate for 16-QAM modulation
N = 2*10^5; % number of symbols
alpha16qam = [-3 -1 1 3]; % 16-QAM alphabets
Es_N0_dB = [0:20]; % multiple Es/N0 values
ipHat = zeros(1,N);
nTx=2;
nRx=2;
for ii = 1:length(Es_N0_dB)
ip = randsrc(1,N,alpha16qam) + j*randsrc(1,N,alpha16qam);
s = (1/sqrt(10))*ip; % normalization of energy to 1
h = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; % Rayleigh channel
n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white guassian noise, 0dB variance
y = s + 10^(-Es_N0_dB(ii)/20)*n; % additive white gaussian noise
% demodulation
y_re = real(y); % real part
y_im = imag(y); % imaginary part
ipHat_re(find(y_re< -2/sqrt(10))) = -3;
ipHat_re(find(y_re > 2/sqrt(10))) = 3;
ipHat_re(find(y_re>-2/sqrt(10) & y_re<=0)) = -1;
ipHat_re(find(y_re>0 & y_re<=2/sqrt(10))) = 1;
ipHat_im(find(y_im< -2/sqrt(10))) = -3;
ipHat_im(find(y_im > 2/sqrt(10))) = 3;
ipHat_im(find(y_im>-2/sqrt(10) & y_im<=0)) = -1;
ipHat_im(find(y_im>0 & y_im<=2/sqrt(10))) = 1;
ipHat = ipHat_re + j*ipHat_im;
nErr(ii) = size(find([ip- ipHat]),2); % couting the number of errors
end
simBer = nErr/N;

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);

%if [s1 s2 ] = [-1,-1 ]


sHat5 = [-1+j -1-j];
sHat5 = repmat(sHat5,[1 ,N/2]);
sHat5Mod = kron(sHat5,ones(nRx,1));
sHat5Mod = reshape(sHat5Mod,[nRx,nTx,N/nTx]);
zHat5 = squeeze(sum(h.*sHat5Mod,2)) ;
J05 = sum(abs(y - zHat5),1);
%if [s1 s2 ] = [-1,-1 ]
sHat6 = [-1-j 1-j];
sHat6 = repmat(sHat6,[1 ,N/2]);
sHat6Mod = kron(sHat6,ones(nRx,1));
sHat6Mod = reshape(sHat6Mod,[nRx,nTx,N/nTx]);
zHat6 = squeeze(sum(h.*sHat6Mod,2)) ;
J06 = sum(abs(y - zHat6),1);
rVec = [J11;J10;J01;J00;J05;J06]; % Finds the minimum from the four possible
combinations
[u dd] = min(rVec,[],1);
ref = [101 99; 101 -101; 101 -99; 99 -99 ; 99 -101; -101 -99]; % Bits mapping
pHat = zeros(1,N);
pHat(1:2:end) = ref(dd,1);
pHat(2:2:end) = ref(dd,2);
nErr(i) = size(find([d- pHat]),2);
gy=[-1+j,-1-j, 1-j, 1+j];
QAM_table = [-3-3j, -3-j, -3+3j, -3+j, -1-3j, -1-j, -1+3j, -1+j,
3-3j, 3-j, 3+3j, 3+j, 1-3j, 1-j, 1+3j, 1+j]/sqrt(10);
metric = 100000;
tt=sum(h.*sMod,2);
sHat1Mod = reshape(tt,nRx,N/nTx);
for l = 1:16
x1_tmp=QAM_table(l);
x_tmp(1) = QAM_table(l); Esti_y1 = y - sHat1Mod.*x1_tmp;
for m = 1:16
x2_tmp=QAM_table(m);
x_tmp(2) = QAM_table(m);
Esti_y2 = Esti_y1 - sHat1Mod.*x2_tmp;
for n = 1:16
x3_tmp=QAM_table(n);
x_tmp(3) = QAM_table(n);
Esti_y3 = Esti_y2 - sHat1Mod.*x3_tmp;
for o = 1:16
x4_tmp=QAM_table(o);
x_tmp(4) = QAM_table(o);
Esti_y4 = Esti_y3 - sHat1Mod.*x4_tmp;

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)');

You might also like