% Figure 2.19: Cumulative distribution functions of the maximal achievable
% rate at 10dB for a SISO channel, a 2x2 MIMO channel and a 4x4 MIMO channel.
% Elisabeth de Carvalho, April 2012

clear all

SNRdB  = 10;  % in dB
SNR = 10.^(SNRdB./10);  % linear scale

% number of channel realization
It = 100000;

% initialize variables
Cmimo4x4 = zeros(1,It);
Cmimo2x2 = zeros(1,It);
Csiso = zeros(1,It);

% collect realizations of the maximal achievable rate
for kk=1:It
    
    Hmimo4x4 = ( randn(4) + j*randn(4) )/sqrt(2);
    Cmimo4x4(kk) =  log2(real(det( eye(4) + SNR/4*Hmimo4x4*Hmimo4x4' )));
    
    Hmimo2x2 = ( randn(2) + j*randn(2) )/sqrt(2);
    Cmimo2x2(kk) =  log2(real(det( eye(2) + SNR/2*Hmimo2x2*Hmimo2x2' )));
    
    Hsiso = ( randn + j*randn )/sqrt(2);
    Csiso(kk) =  log2(real(det( 1 + SNR*Hsiso*Hsiso' )));
    
end


% CDF estimates
xi = linspace(0,15,201);
CDFmimo4x4 = ksdensity(Cmimo4x4,xi,'function','cdf');
CDFmimo2x2 = ksdensity(Cmimo2x2,xi,'function','cdf');
CDFsiso    = ksdensity(Csiso,xi,'function','cdf');

%plot
figure(1)
plot(xi,CDFmimo4x4,'k');
hold on
plot(xi,CDFmimo2x2,'k');
grid
plot(xi,CDFsiso,'k');
xlabel('Selected Rate R')
ylabel('Probability')
title('Cumulative Density Function at 10dB')
text(12,.75,'4x4 MIMO')
text(6.7,.75,'2x2 MIMO')
text(4.1,.75,'SISO')
hold off
