0% found this document useful (0 votes)
22 views6 pages

MIMO Exp5

The document analyzes the capacity of a MIMO system over Rayleigh fading channels with different numbers of transmit and receive antennas. It calculates the singular values of the channel matrix and distributes transmit power based on water-filling. Plots of average capacity, CDF of capacity, and PDF of singular values are generated.

Uploaded by

kjoshime23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

MIMO Exp5

The document analyzes the capacity of a MIMO system over Rayleigh fading channels with different numbers of transmit and receive antennas. It calculates the singular values of the channel matrix and distributes transmit power based on water-filling. Plots of average capacity, CDF of capacity, and PDF of singular values are generated.

Uploaded by

kjoshime23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab-MIMO

KAPIL JOSHI
802361003

EXPERIMENT – 5
CODE -

clc;
clear all;
close all;
%% +Overview -----------------------------------------------------
---------
% In this code, we drive the Capacity of a MIMO system over
Rayleigh fading
% channel with different number of transmit and receiver antennas.
For each
% setting of a MIMO channel, after calculating the singular values
of the
% channel matrix, transmit power is distributed based on water-
filling
% algorithm. The obtained capacity is the best that MIMO system
can deliver
% as the full channel state information is used both at TX and RX
side.
% -Overview -----------------------------------------------------
---------
%% +Clear --------------------------------------------------------
---------
clear % clear all variables in the workspace
close all % close all open figures
clc % clear command window
% -Clear --------------------------------------------------------
---------
%% +Independent parameters ---------------------------------------
---------
% system parameters
numOfTxAntennas = [1 2 3 2 4]; % a vector to hold number of
antennas at
% the transmitter side
numOfRxAntennas = [1 2 2 3 4]; % a vector to hold number of
antennas at
% the receiver side
% related to AWGN channel
noisePower = 1e-4; % AWGN noise power
signalToNoiseRatio_dB = -10:3:20; % a vector to hold SNR
values

% loop parameters
numOfIterations = 1e4; % number of iterations (should
be above
% 1e3 for accurate result)
% related to plots
16 | P a g e
curveType = {'b.-';'rs-';'g+--';'k--^';'m--d'};
% -Independent parameters ---------------------------------------
---------

%% +Check Independent parameters ---------------------------------


---------
nOfAntennasVecTx = length(numOfTxAntennas);
nOfAntennasVecRx = length(numOfTxAntennas);
if nOfAntennasVecTx ~= nOfAntennasVecRx
error('Vectors numOfTxAntennas and numOfRxAntennas must
have the same size')
else
nOfAntennasVec = nOfAntennasVecRx; % number of elements
in antennas
end
if nOfAntennasVec < length(curveType)
error('Number of elements in numOfTxAntennas must be
smaller than %d.',...
length(curveType))
end
% -Check Independent parameters ---------------------------------
---------
%% +Dependent parameters -----------------------------------------
---------
% convert from dB to scalar
signalToNoiseRatio = 10.^(0.1*signalToNoiseRatio_dB);
% number of elements in SNR vector
nOfsignalToNoiseRatio = length(signalToNoiseRatio);
% allocate memory for capacity
CapacityVec = ...

zeros(nOfAntennasVec,nOfsignalToNoiseRatio,numOfIterations);
% allocate memory for singular value decompostion
lambdaVec = ...

zeros(nOfAntennasVec,nOfsignalToNoiseRatio,numOfIterations,nOfAnte
nnasVec);
% -Dependent parameters -----------------------------------------
---------

%% +Main ---------------------------------------------------------
---------
for n = 1 : nOfAntennasVec % loop over number of antennas
nTx = numOfTxAntennas(n); % num of Tx antennas in this
iteration
nRx = numOfRxAntennas(n); % num of Rx antennas in this
iteration
for j = 1 : nOfsignalToNoiseRatio
% load SNR for this iteration
snr = signalToNoiseRatio(j); % SNR at this
iteration
% calaculate transmit power
txPower = noisePower*snr; % we know SNR =
txPower/noisePower

17 | P a g e
% with the assumption
that
% there is no
pathloss. It
% means here txPower =
rxPower;
for i = 1 : numOfIterations % loop over number of
iterations
% generate channel coefficients
h = 1/sqrt(2)*(randn(nRx,nTx)+1i*randn(nRx,nTx));
% calaculate singular value decomposition
S = svd(h);
% store values of lambda in SVD
lambdaVec(n,j,i,1:min(nRx,nTx)) = S;
% find carrier to noise rations
cnr = S.^2/noisePower;
% find allocated power based on waterfilling
algorithm
allocatedPower = waterFilling(cnr,txPower);
% calculate the capacity
capacity = sum(log2(1+allocatedPower.*cnr));
% store the value
CapacityVec(n,j,i) = capacity;
end
end
end
% -Main ---------------------------------------------------------
---------
%% +Post processing ----------------------------------------------
---------
% take the average of the capacity
CapacityVecAvg = mean(CapacityVec,3);

% -Post processing ----------------------------------------------


---------
%% +Figures ------------------------------------------------------
---------
% plot capacity for different number of Tx and Rx antennas vs
SNR
f1 = figure(1);
clf
legendStr = cell(nOfAntennasVec,1);
for n = 1 : nOfAntennasVec % loop over number of antennas

plot(signalToNoiseRatio_dB,CapacityVecAvg(n,:),curveType{n})
hold on
legendStr{n} = sprintf('nTx = %d, nRx = %d',...
numOfTxAntennas(n),numOfRxAntennas(n));
end
xlabel('SNR [dB]')
ylabel('Capacity [b/s/Hz]')
grid on
title('Avg Capacity of a MIMO system for different num of tx-
rx antennas')
legend(legendStr,'location','best')

18 | P a g e
% plot distribution of capacity at SNR = 5dB
f2 = figure(2);
clf
targetSNRdB = 5;
Ind = find(signalToNoiseRatio_dB == targetSNRdB);
for n = 1 : nOfAntennasVec % loop over number of antennas
capacities = CapacityVec(n,Ind,:);
[y,x] = hist(capacities(:),30);
% update y
y = y ./ sum(y) ; % normalization
plot(x,cumsum(y),curveType{n})
hold on
end
xlabel('Capacity [b/s/Hz]')
ylabel('Probability of Capacity < GivenCapacity')
grid on
title(sprintf('CDF of the Capacity at SNR =
%ddB',targetSNRdB))
legend(legendStr,'location','best')

% plot pdf of lambda at target SNR for a given nTx and nRx
n = 5; % select a setting from nTx and nRx
nTx = numOfTxAntennas(n); % num of Tx antennas in this
setting
nRx = numOfRxAntennas(n); % num of Rx antennas in this
setting
f3 = figure(3);
clf
legendStr = cell(min(nTx,nRx),1);
for k = 1 : min(nTx,nRx)
lambdas = lambdaVec(n,Ind,:,k);
[y,x] = hist(lambdas(:),30);
% update y
y = y ./ sum(y) ; % normalization
plot(x,y,curveType{k})
hold on
if k == 1
legendStr{k} = '1st singular value';
elseif k == 2
legendStr{k} = '2nd singular value';
else
legendStr{k} = sprintf('%d-th singular value',k);
end
end
ylabel('Nolmalized probability')
xlabel('singular value')
legend(legendStr)
grid on
title(sprintf('normalized pdf of svd values for nTx=%d,
nRx=%d',nTx,nRx))
% -Figures ------------------------------------------------------
---------
%% +Save Figures -------------------------------------------------
---------
%saveas(f1,'avgCapacity','jpg');
%saveas(f2,'cdfCapacity','jpg');

19 | P a g e
%saveas(f3,'pdfLambdas','jpg');
% -Save Figures -------------------------------------------------
---------
%%
function P = waterFilling(CNR,Pmax)
%#codegen
% initial power allocation
initP = (Pmax + sum(1./CNR)) ./ ( length(CNR) ) - 1./CNR;

% waterfilling algorithm
while any( initP < 0 )
negIndex = initP <= 0;
posIndex = initP > 0;
NkRem = nnz(posIndex);
CNRRem = CNR(posIndex);
powAllcTemp = (Pmax + sum(1./CNRRem)) ./ (NkRem) -
1./CNRRem;
initP(negIndex) = 0;
initP(posIndex) = powAllcTemp;
end
P = initP;
end

PLOT -

20 | P a g e
21 | P a g e

You might also like