Está en la página 1de 9

MATLAB Simulation

Comparison MIMO-SVD and MIMO-SM


MIMO-SVD
clear
clc
disp('This program calculates the Bit Error Rate for 16QAM with MIMO
spatial Multiplexing Zero Forcing')
disp('BER is plotted in a jpeg file: BER.jpg')
disp(' ')

%================================================
%================================================
% Select the range of SNR per bit to simulate
startSNRperBitdB = 0;
endSNRperBitdB = 20;
stepSNRdB = 2;
snrArray=(startSNRperBitdB : stepSNRdB: endSNRperBitdB);
numSNRsteps=length(snrArray);
%================================================
%================================================
% To turn ON/OFF fading
isFadingOn=1;
%================================================
%================================================

% for 16-QAM 4 bits make one symbol


numBitsPerSymbol = 4;

% Number of 16-QAM symbols per frame


numSymbolsPerFrame = 100;

% Number of channel bits per frame


numChannelBits=numSymbolsPerFrame*numBitsPerSymbol;

% Maximum number of frames to simulate per SNR. This number shuld be


large
% enough otherwise the BER curve will not be smooth
numIterations = 10000;

% Each SNR, stop iterations after getting this number of frame errors
enoughFrameErrors=400 ;

%=============================
%Loop over SNR per symbol
%=============================
errorArray=zeros(numSNRsteps, 2); % first column is SNR, 2'nd column is
BER
for snrCounter = 1:numSNRsteps

SNRperBitdB=snrArray(snrCounter)
SNRperBit=10^(SNRperBitdB/10) ;

% SNR per symbol is 4 times SNR per bit (16-QAM symbol carries 4
bits)
SNRperSymbol=SNRperBit * numBitsPerSymbol ;

%=============================
%Loop over frames of bits
%=============================
sumBitError = 0; % reset number of bit errors
sumFrameError=0; % reset number of frame errors
numSimulatedSymbols = 0; % reset number of simulated symbols
for frameCounter = 1 : numIterations

%*********************************
% We need to stop simulating this SNR if we already got enough
% frame errors. This saves simulation time at low SNR values
if sumFrameError >= enoughFrameErrors
break
end
%*********************************

% generate 1/0 channel bits for this frame randomly


TxFrameBits(1:numChannelBits)= round(rand(1,numChannelBits));

% generate the corresponding QPSK Symbols using an m function


TxFrameSymbols = QAM16_modulate( TxFrameBits) ;

MIMOTxFrameSymbols=reshape(TxFrameSymbols,2,0.5*length(TxFrameSymbols))
;
%====================================
%
% Singular Value Decomposition
%
%
%====================================
% generate fading gain: Rayleigh, non-selective
% We need to make sure that each elemnts of the complex gain
% has E(|fadingGain|^2)=1
numMIMOSymbolsPerFrame=length(MIMOTxFrameSymbols);
if isFadingOn==1
% Rayleigh fading gains
fadingGain0= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
fadingGain1= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
fadingGain2= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
fadingGain3= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
else
% No fading
fadingGain= 1;
end
FadingGainMatrix=zeros(2,2*numMIMOSymbolsPerFrame);
U=zeros(size(FadingGainMatrix));
Sigma=zeros(size(FadingGainMatrix));
V=zeros(size(FadingGainMatrix));
for xx=1:2:2*numMIMOSymbolsPerFrame
FadingGainMatrix(:,xx:xx+1)=[fadingGain0((xx+1)/2)
fadingGain1((xx+1)/2);fadingGain2((xx+1)/2) fadingGain3((xx+1)/2)];

[U(:,xx:xx+1),Sigma(:,xx:xx+1),V(:,xx:xx+1)]=svd(FadingGainMatrix(:,xx:
xx+1));
end
SVDMIMOTxFrameSymbols=zeros(size(MIMOTxFrameSymbols));
for xx=1:2:length(V)
SVDMIMOTxFrameSymbols(:,(xx+1)/2)=
V(:,xx:xx+1)*MIMOTxFrameSymbols(:,(xx+1)/2);
end
% Apply fading to the transmitted symbols
fadedSymbols=zeros(size(SVDMIMOTxFrameSymbols));
for xx=1:2:length(FadingGainMatrix)
fadedSymbols(:,(xx+1)/2)= FadingGainMatrix(:,xx:xx+1)*
SVDMIMOTxFrameSymbols(:,(xx+1)/2) ;
end
%====================================
%====================================

% generate AWGN samples for every channel Symbol


AWGN0=sqrt(1/SNRperSymbol/2)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
AWGN1=sqrt(1/SNRperSymbol/2)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));

AWGNMatrix=[AWGN0;AWGN1];

% add channel symbols to AWGN


RxChannelSymbols = fadedSymbols + AWGNMatrix ;

% Remove channel effect (assuming perfect channel estiamtion)


% Apply the channel equalizer to equalize the fading channel
effect
%equalizedSymbols=RxChannelSymbols ./ fadingGain ;

equalizedSymbols=zeros(size(RxChannelSymbols));
for xx=1:2:length(U)

equalizedSymbols(:,(xx+1)/2)=inv(Sigma(:,xx:xx+1))*ctranspose(U(:,xx:xx
+1))*RxChannelSymbols(:,(xx+1)/2);
end

equalizedSymbols=reshape(equalizedSymbols,1,2*length(equalizedSymbols))
;
% Apply QAM thresholds
[Real16, Imag16] = QAM16_thresholds(equalizedSymbols) ;
% decide the received channel bits
RxFrameBits = QAM16_demodulate(Real16, Imag16) ;

% Decide the number of bit erros in this frame


numBitErrors= sum(TxFrameBits ~= RxFrameBits);

if numBitErrors>0
frameError=1;
else
frameError=0;
end

% accumulate bit error counter


sumBitError = sumBitError + numBitErrors ;

% Accumulated frame erros


sumFrameError = sumFrameError + frameError ;

% accumulate the number of simulated symbols till now


numSimulatedSymbols = numSimulatedSymbols + numSymbolsPerFrame;

end
%=============================
%End looping over frames of bits
%=============================
BitErrorRate = sumBitError/numSimulatedSymbols/numBitsPerSymbol ;

errorArray(snrCounter,1:2) = [SNRperBitdB BitErrorRate];

end
%=============================
%End looping over SNR per symbol
%=============================

semilogy(errorArray(:,1) , errorArray(:,2),'-o', 'LineWidth',2)


ha=gca ;
set(ha,'fontsize',16)

grid
ha2=xlabel('E_b/N_o in dB');
ha3=ylabel('Bit Error Rate');
set(ha2, 'FontSize', 14);
set(ha3, 'FontSize', 14);

if isFadingOn==1
ha1=title('Bit Error Rate for MIMO-SVD 16QAM in Rayleigh Fading
Channel');
fileName=('16QAMfadingSVD');
else
ha1=title('Bit Error Rate for 16QAM in AWGN Channel');
fileName=('16QAMawgn');
end
set(ha1, 'FontSize', 14);

%text(5, 0.1,'text here')

saveas(gcf, fileName, 'fig')


saveas(gcf, fileName, 'jpg')
MIMO-SM
clear
clc
disp('This program calculates the Bit Error Rate for 16QAM with MIMO
spatial Multiplexing Zero Forcing')
disp('BER is plotted in a jpeg file: BER.jpg')
disp(' ')

%================================================
%================================================
% Select the range of SNR per bit to simulate
startSNRperBitdB = 0;
endSNRperBitdB = 20;
stepSNRdB = 2;
snrArray=(startSNRperBitdB : stepSNRdB: endSNRperBitdB);
numSNRsteps=length(snrArray);
%================================================
%================================================
% To turn ON/OFF fading
isFadingOn=1;
%================================================
%================================================

% for 16-QAM 4 bits make one symbol


numBitsPerSymbol = 4;

% Number of 16-QAM symbols per frame


numSymbolsPerFrame = 100;

% Number of channel bits per frame


numChannelBits=numSymbolsPerFrame*numBitsPerSymbol;

% Maximum number of frames to simulate per SNR. This number shuld be


large
% enough otherwise the BER curve will not be smooth
numIterations = 10000;

% Each SNR, stop iterations after getting this number of frame errors
enoughFrameErrors=400 ;

%=============================
%Loop over SNR per symbol
%=============================
errorArray=zeros(numSNRsteps, 2); % first column is SNR, 2'nd column is
BER
for snrCounter = 1:numSNRsteps

SNRperBitdB=snrArray(snrCounter)
SNRperBit=10^(SNRperBitdB/10) ;

% SNR per symbol is 4 times SNR per bit (16-QAM symbol carries 4
bits)
SNRperSymbol=SNRperBit * numBitsPerSymbol ;
%=============================
%Loop over frames of bits
%=============================
sumBitError = 0; % reset number of bit errors
sumFrameError=0; % reset number of frame errors
numSimulatedSymbols = 0; % reset number of simulated symbols
for frameCounter = 1 : numIterations

%*********************************
% We need to stop simulating this SNR if we already got enough
% frame errors. This saves simulation time at low SNR values
if sumFrameError >= enoughFrameErrors
break
end
%*********************************

% generate 1/0 channel bits for this frame randomly


TxFrameBits(1:numChannelBits)= round(rand(1,numChannelBits));

% generate the corresponding QPSK Symbols using an m function


TxFrameSymbols = QAM16_modulate( TxFrameBits) ;

MIMOTxFrameSymbols=reshape(TxFrameSymbols,2,0.5*length(TxFrameSymbols))
;
%====================================
%
% Spatial Multiplexing
%
%
%====================================
% generate fading gain: Rayleigh, non-selective
% We need to make sure that each elemnts of the complex gain
% has E(|fadingGain|^2)=1
numMIMOSymbolsPerFrame=length(MIMOTxFrameSymbols);
if isFadingOn==1
% Rayleigh fading gains
fadingGain0= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
fadingGain1= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
fadingGain2= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
fadingGain3= sqrt(0.5)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
else
% No fading
fadingGain= 1;
end
FadingGainMatrix=zeros(2,2*numMIMOSymbolsPerFrame);
for xx=1:2:2*numMIMOSymbolsPerFrame
FadingGainMatrix(:,xx:xx+1)=[fadingGain0((xx+1)/2)
fadingGain1((xx+1)/2);fadingGain2((xx+1)/2) fadingGain3((xx+1)/2)];
end
% Apply fading to the transmitted symbols
fadedSymbols=zeros(size(MIMOTxFrameSymbols));
for xx=1:2:length(FadingGainMatrix)
fadedSymbols(:,(xx+1)/2)= FadingGainMatrix(:,xx:xx+1)*
MIMOTxFrameSymbols(:,(xx+1)/2) ;
end
%====================================
%====================================

% generate AWGN samples for every channel Symbol


AWGN0=sqrt(1/SNRperSymbol/2)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
AWGN1=sqrt(1/SNRperSymbol/2)*(randn(1,numMIMOSymbolsPerFrame) +
j*randn(1,numMIMOSymbolsPerFrame));
AWGNMatrix=[AWGN0;AWGN1];

% add channel symbols to AWGN


RxChannelSymbols = fadedSymbols + AWGNMatrix ;

% Remove channel effect (assuming perfect channel estiamtion)


% Apply the channel equalizer to equalize the fading channel
effect
%equalizedSymbols=RxChannelSymbols ./ fadingGain ;
for xx=1:2:length(FadingGainMatrix)
G=FadingGainMatrix(:,xx:xx+1);
GH=ctranspose(G);
GHxG=GH*G;
Inverse_GHxG=inv(GHxG);
FinalG=Inverse_GHxG*GH;
EqualizedFadingGain(:,xx:xx+1)=FinalG;
end
equalizedSymbols=zeros(size(RxChannelSymbols));
for xx=1:2:length(EqualizedFadingGain)

equalizedSymbols(:,(xx+1)/2)=EqualizedFadingGain(:,xx:xx+1)*RxChannelSy
mbols(:,(xx+1)/2);
end

equalizedSymbols=reshape(equalizedSymbols,1,2*length(equalizedSymbols))
;
% Apply QAM thresholds
[Real16, Imag16] = QAM16_thresholds(equalizedSymbols) ;
% decide the received channel bits
RxFrameBits = QAM16_demodulate(Real16, Imag16) ;

% Decide the number of bit erros in this frame


numBitErrors= sum(TxFrameBits ~= RxFrameBits);

if numBitErrors>0
frameError=1;
else
frameError=0;
end

% accumulate bit error counter


sumBitError = sumBitError + numBitErrors ;

% Accumulated frame erros


sumFrameError = sumFrameError + frameError ;

% accumulate the number of simulated symbols till now


numSimulatedSymbols = numSimulatedSymbols + numSymbolsPerFrame;

end
%=============================
%End looping over frames of bits
%=============================
BitErrorRate = sumBitError/numSimulatedSymbols/numBitsPerSymbol ;

errorArray(snrCounter,1:2) = [SNRperBitdB BitErrorRate];

end
%=============================
%End looping over SNR per symbol
%=============================

semilogy(errorArray(:,1) , errorArray(:,2),'r-o', 'LineWidth',2)


ha=gca ;
set(ha,'fontsize',16)

grid
ha2=xlabel('E_b/N_o in dB');
ha3=ylabel('Bit Error Rate');
set(ha2, 'FontSize', 14);
set(ha3, 'FontSize', 14);

if isFadingOn==1
ha1=title('Bit Error Rate for MIMO-SM-ZF 16QAM in Rayleigh Fading
Channel');
fileName=('16QAMfading');
else
ha1=title('Bit Error Rate for 16QAM in AWGN Channel');
fileName=('16QAMawgn');
end
set(ha1, 'FontSize', 14);

%text(5, 0.1,'text here')

saveas(gcf, fileName, 'fig')


saveas(gcf, fileName, 'jpg')
Simulation Results