SlideShare a Scribd company logo
1 of 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% All rights reserved by Krishna Pillai, http://www.dsplog.com

% The file may not be re-distributed without explicit authorization

% from Krishna Pillai.

% Checked for proper operation with Octave Version 3.0.0

% Author        : Krishna Pillai

% Email         : krishna@dsplog.com

% Version       : 1.0

% Date          : 23rd October 2008

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



% Script for computing the BER for BPSK modulation in a

% Rayleigh fading channel with 2 Tx, 2Rx MIMO channel

% Zero Forcing equalization



clear

N = 10^6; % number of bits or symbols

Eb_N0_dB = [0:25]; % 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;



    % Receiver



    % Forming the Zero Forcing 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

    ipHat = real(yHat)>0;
% 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, ZF)');

xlabel('Average Eb/No,dB');

ylabel('Bit Error Rate');

title('BER for BPSK modulation with 2x2 MIMO and ZF equalizer
(Rayleigh channel)');

More Related Content

What's hot

Equalization
EqualizationEqualization
Equalizationbhabendu
 
Large scale path loss 1
Large scale path loss 1Large scale path loss 1
Large scale path loss 1Vrince Vimal
 
Non orthogonal multiple access
Non orthogonal multiple accessNon orthogonal multiple access
Non orthogonal multiple accessShalikramRajpoot
 
Decimation and Interpolation
Decimation and InterpolationDecimation and Interpolation
Decimation and InterpolationFernando Ojeda
 
Chapter 7 multiple access techniques
Chapter 7 multiple access techniquesChapter 7 multiple access techniques
Chapter 7 multiple access techniquesKaushal Kabra
 
OKUMURA, HATA and COST231 Propagation Models
OKUMURA, HATA and COST231 Propagation ModelsOKUMURA, HATA and COST231 Propagation Models
OKUMURA, HATA and COST231 Propagation ModelsMohammed Abuibaid
 
Digital Communication: Information Theory
Digital Communication: Information TheoryDigital Communication: Information Theory
Digital Communication: Information TheoryDr. Sanjay M. Gulhane
 
cell splitting and sectoring
cell splitting and sectoringcell splitting and sectoring
cell splitting and sectoringShwetanshu Gupta
 
Multiple Access Techniques for 5G
Multiple Access Techniques for 5GMultiple Access Techniques for 5G
Multiple Access Techniques for 5GSitha Sok
 
Channel estimation - F. Ling
Channel estimation - F. LingChannel estimation - F. Ling
Channel estimation - F. LingFuyun Ling
 
Time Division Multiplexing
Time Division MultiplexingTime Division Multiplexing
Time Division MultiplexingSpandit Lenka
 
Prioritizing handoffs
Prioritizing handoffsPrioritizing handoffs
Prioritizing handoffsAJAL A J
 
Concepts of & cell sectoring and micro cell
Concepts of & cell sectoring and micro cellConcepts of & cell sectoring and micro cell
Concepts of & cell sectoring and micro cellKundan Kumar
 
Pulse amplitude modulation
Pulse amplitude modulationPulse amplitude modulation
Pulse amplitude modulationVishal kakade
 
Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)Soumen Santra
 
L 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcmL 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcmDEEPIKA KAMBOJ
 
Chapter 9 computation of the dft
Chapter 9 computation of the dftChapter 9 computation of the dft
Chapter 9 computation of the dftmikeproud
 

What's hot (20)

Equalization
EqualizationEqualization
Equalization
 
Large scale path loss 1
Large scale path loss 1Large scale path loss 1
Large scale path loss 1
 
Ofdma
OfdmaOfdma
Ofdma
 
Non orthogonal multiple access
Non orthogonal multiple accessNon orthogonal multiple access
Non orthogonal multiple access
 
Decimation and Interpolation
Decimation and InterpolationDecimation and Interpolation
Decimation and Interpolation
 
Chapter 7 multiple access techniques
Chapter 7 multiple access techniquesChapter 7 multiple access techniques
Chapter 7 multiple access techniques
 
OKUMURA, HATA and COST231 Propagation Models
OKUMURA, HATA and COST231 Propagation ModelsOKUMURA, HATA and COST231 Propagation Models
OKUMURA, HATA and COST231 Propagation Models
 
Digital Communication: Information Theory
Digital Communication: Information TheoryDigital Communication: Information Theory
Digital Communication: Information Theory
 
cell splitting and sectoring
cell splitting and sectoringcell splitting and sectoring
cell splitting and sectoring
 
Multiple Access Techniques for 5G
Multiple Access Techniques for 5GMultiple Access Techniques for 5G
Multiple Access Techniques for 5G
 
Sampling theorem
Sampling theoremSampling theorem
Sampling theorem
 
Channel estimation - F. Ling
Channel estimation - F. LingChannel estimation - F. Ling
Channel estimation - F. Ling
 
Time Division Multiplexing
Time Division MultiplexingTime Division Multiplexing
Time Division Multiplexing
 
Equalization
EqualizationEqualization
Equalization
 
Prioritizing handoffs
Prioritizing handoffsPrioritizing handoffs
Prioritizing handoffs
 
Concepts of & cell sectoring and micro cell
Concepts of & cell sectoring and micro cellConcepts of & cell sectoring and micro cell
Concepts of & cell sectoring and micro cell
 
Pulse amplitude modulation
Pulse amplitude modulationPulse amplitude modulation
Pulse amplitude modulation
 
Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)
 
L 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcmL 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcm
 
Chapter 9 computation of the dft
Chapter 9 computation of the dftChapter 9 computation of the dft
Chapter 9 computation of the dft
 

Viewers also liked

matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmGyana Ranjan Mati
 
Matlab source codes section | Download MATLAB source code freerce-codes
Matlab source codes section | Download MATLAB source code freerce-codesMatlab source codes section | Download MATLAB source code freerce-codes
Matlab source codes section | Download MATLAB source code freerce-codeshafsabanu
 
Wireless Channel Modeling - MATLAB Simulation Approach
Wireless Channel Modeling - MATLAB Simulation ApproachWireless Channel Modeling - MATLAB Simulation Approach
Wireless Channel Modeling - MATLAB Simulation ApproachJayamohan Govindaraj
 
Implementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedImplementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedRosdiadee Nordin
 
Multiuser MIMO-OFDM simulation framework in Matlab
Multiuser MIMO-OFDM simulation framework in MatlabMultiuser MIMO-OFDM simulation framework in Matlab
Multiuser MIMO-OFDM simulation framework in MatlabPavel Loskot
 
Simulation of A Communications System Using Matlab
Simulation of A Communications System Using MatlabSimulation of A Communications System Using Matlab
Simulation of A Communications System Using MatlabPolytechnique Montreal
 
Simulating communication systems with MATLAB: An introduction
Simulating communication systems with MATLAB: An introductionSimulating communication systems with MATLAB: An introduction
Simulating communication systems with MATLAB: An introductionAniruddha Chandra
 
MATLAB and Simulink for Communications System Design (Design Conference 2013)
MATLAB and Simulink for Communications System Design (Design Conference 2013)MATLAB and Simulink for Communications System Design (Design Conference 2013)
MATLAB and Simulink for Communications System Design (Design Conference 2013)Analog Devices, Inc.
 
Simulation of Wireless Communication Systems
Simulation of Wireless Communication SystemsSimulation of Wireless Communication Systems
Simulation of Wireless Communication SystemsBernd-Peter Paris
 
Mimo ofdm wireless communications with matlab
Mimo ofdm wireless communications with matlabMimo ofdm wireless communications with matlab
Mimo ofdm wireless communications with matlabntnam113
 
Mimoofdm based system
Mimoofdm based systemMimoofdm based system
Mimoofdm based systemRajat Dak
 
Ofdm sim-matlab-code-tutorial web for EE students
Ofdm sim-matlab-code-tutorial web for EE studentsOfdm sim-matlab-code-tutorial web for EE students
Ofdm sim-matlab-code-tutorial web for EE studentsMike Martin
 
Mimo ofdm by abhishek pandey
Mimo ofdm by abhishek pandeyMimo ofdm by abhishek pandey
Mimo ofdm by abhishek pandeyabhi29513
 
MIMO-OFDM for 4G network
MIMO-OFDM for 4G networkMIMO-OFDM for 4G network
MIMO-OFDM for 4G networknimay1
 
Performance analysis of adaptive noise canceller for an ecg signal
Performance analysis of adaptive noise canceller for an ecg signalPerformance analysis of adaptive noise canceller for an ecg signal
Performance analysis of adaptive noise canceller for an ecg signalRaj Kumar Thenua
 
Introduction To Wireless Fading Channels
Introduction To Wireless Fading ChannelsIntroduction To Wireless Fading Channels
Introduction To Wireless Fading ChannelsNitin Jain
 
Introduction to Massive Mimo
Introduction to Massive MimoIntroduction to Massive Mimo
Introduction to Massive MimoAhmed Nasser Agag
 
Number plate recognition system using matlab.
Number plate recognition system using matlab.Number plate recognition system using matlab.
Number plate recognition system using matlab.Namra Afzal
 

Viewers also liked (20)

matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdm
 
Matlab source codes section | Download MATLAB source code freerce-codes
Matlab source codes section | Download MATLAB source code freerce-codesMatlab source codes section | Download MATLAB source code freerce-codes
Matlab source codes section | Download MATLAB source code freerce-codes
 
Wireless Channel Modeling - MATLAB Simulation Approach
Wireless Channel Modeling - MATLAB Simulation ApproachWireless Channel Modeling - MATLAB Simulation Approach
Wireless Channel Modeling - MATLAB Simulation Approach
 
Implementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: SimplifiedImplementation of Wireless Channel Model in MATLAB: Simplified
Implementation of Wireless Channel Model in MATLAB: Simplified
 
Multiuser MIMO-OFDM simulation framework in Matlab
Multiuser MIMO-OFDM simulation framework in MatlabMultiuser MIMO-OFDM simulation framework in Matlab
Multiuser MIMO-OFDM simulation framework in Matlab
 
Simulation of A Communications System Using Matlab
Simulation of A Communications System Using MatlabSimulation of A Communications System Using Matlab
Simulation of A Communications System Using Matlab
 
Simulating communication systems with MATLAB: An introduction
Simulating communication systems with MATLAB: An introductionSimulating communication systems with MATLAB: An introduction
Simulating communication systems with MATLAB: An introduction
 
MATLAB and Simulink for Communications System Design (Design Conference 2013)
MATLAB and Simulink for Communications System Design (Design Conference 2013)MATLAB and Simulink for Communications System Design (Design Conference 2013)
MATLAB and Simulink for Communications System Design (Design Conference 2013)
 
Simulation of Wireless Communication Systems
Simulation of Wireless Communication SystemsSimulation of Wireless Communication Systems
Simulation of Wireless Communication Systems
 
Mimo ofdm wireless communications with matlab
Mimo ofdm wireless communications with matlabMimo ofdm wireless communications with matlab
Mimo ofdm wireless communications with matlab
 
MIMO OFDM
MIMO OFDMMIMO OFDM
MIMO OFDM
 
Mimoofdm based system
Mimoofdm based systemMimoofdm based system
Mimoofdm based system
 
Modulation techniques matlab_code
Modulation techniques matlab_codeModulation techniques matlab_code
Modulation techniques matlab_code
 
Ofdm sim-matlab-code-tutorial web for EE students
Ofdm sim-matlab-code-tutorial web for EE studentsOfdm sim-matlab-code-tutorial web for EE students
Ofdm sim-matlab-code-tutorial web for EE students
 
Mimo ofdm by abhishek pandey
Mimo ofdm by abhishek pandeyMimo ofdm by abhishek pandey
Mimo ofdm by abhishek pandey
 
MIMO-OFDM for 4G network
MIMO-OFDM for 4G networkMIMO-OFDM for 4G network
MIMO-OFDM for 4G network
 
Performance analysis of adaptive noise canceller for an ecg signal
Performance analysis of adaptive noise canceller for an ecg signalPerformance analysis of adaptive noise canceller for an ecg signal
Performance analysis of adaptive noise canceller for an ecg signal
 
Introduction To Wireless Fading Channels
Introduction To Wireless Fading ChannelsIntroduction To Wireless Fading Channels
Introduction To Wireless Fading Channels
 
Introduction to Massive Mimo
Introduction to Massive MimoIntroduction to Massive Mimo
Introduction to Massive Mimo
 
Number plate recognition system using matlab.
Number plate recognition system using matlab.Number plate recognition system using matlab.
Number plate recognition system using matlab.
 

Similar to Matlab code

bask, bfsk, bpsk
bask, bfsk, bpskbask, bfsk, bpsk
bask, bfsk, bpskblzz2net
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağıMerve Cvdr
 
Predicting organic reaction outcomes with weisfeiler lehman network
Predicting organic reaction outcomes with weisfeiler lehman networkPredicting organic reaction outcomes with weisfeiler lehman network
Predicting organic reaction outcomes with weisfeiler lehman networkKazuki Fujikawa
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfmeerobertsonheyde608
 
Time Dependent and Independent operations (signal and systems)
Time Dependent and Independent operations (signal and systems)Time Dependent and Independent operations (signal and systems)
Time Dependent and Independent operations (signal and systems)Omkar Rane
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Toshiyuki Shimono
 
Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876NgGiaHi
 
Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876NgGiaHi
 
Lecture 1
Lecture 1Lecture 1
Lecture 1butest
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfaartechindia
 
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfreservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfRTEFGDFGJU
 
Dct compressionfactor8.doc
Dct compressionfactor8.docDct compressionfactor8.doc
Dct compressionfactor8.docMITTU1
 
Surge Swab pressure code
Surge Swab pressure codeSurge Swab pressure code
Surge Swab pressure codeANKIT KUKREJA
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
Implicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcsImplicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcsParhamsagharchi
 

Similar to Matlab code (20)

CODING
CODINGCODING
CODING
 
bask, bfsk, bpsk
bask, bfsk, bpskbask, bfsk, bpsk
bask, bfsk, bpsk
 
Mnistauto 5
Mnistauto 5Mnistauto 5
Mnistauto 5
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağı
 
Predicting organic reaction outcomes with weisfeiler lehman network
Predicting organic reaction outcomes with weisfeiler lehman networkPredicting organic reaction outcomes with weisfeiler lehman network
Predicting organic reaction outcomes with weisfeiler lehman network
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Time Dependent and Independent operations (signal and systems)
Time Dependent and Independent operations (signal and systems)Time Dependent and Independent operations (signal and systems)
Time Dependent and Independent operations (signal and systems)
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...
 
Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876
 
Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876Tb16 nguyễn minhđan_20183876
Tb16 nguyễn minhđan_20183876
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
 
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfreservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
 
บทที่ 3
บทที่ 3บทที่ 3
บทที่ 3
 
Dct compressionfactor8.doc
Dct compressionfactor8.docDct compressionfactor8.doc
Dct compressionfactor8.doc
 
DTLC-GAN
DTLC-GANDTLC-GAN
DTLC-GAN
 
Surge Swab pressure code
Surge Swab pressure codeSurge Swab pressure code
Surge Swab pressure code
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Implicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcsImplicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcs
 
Image Processing
Image ProcessingImage Processing
Image Processing
 

Matlab code

  • 1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % All rights reserved by Krishna Pillai, http://www.dsplog.com % The file may not be re-distributed without explicit authorization % from Krishna Pillai. % Checked for proper operation with Octave Version 3.0.0 % Author : Krishna Pillai % Email : krishna@dsplog.com % Version : 1.0 % Date : 23rd October 2008 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Script for computing the BER for BPSK modulation in a % Rayleigh fading channel with 2 Tx, 2Rx MIMO channel % Zero Forcing equalization clear N = 10^6; % number of bits or symbols Eb_N0_dB = [0:25]; % 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
  • 2. 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 % Forming the Zero Forcing 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 ipHat = real(yHat)>0;
  • 3. % 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, ZF)'); xlabel('Average Eb/No,dB'); ylabel('Bit Error Rate'); title('BER for BPSK modulation with 2x2 MIMO and ZF equalizer (Rayleigh channel)');