% Figure 2.17: Capacity vs number of antennas for a 4xM and a Mx4 MIMO system.
% Elisabeth de Carvalho, April 2012

clear all

% Maximum number of transmit and receive antennas
Mmax = 8;

% number of channel realization
It = 10000;


% initialize variables: ergodic capacity for each value of SNRdBrange
Cmimo4xM  = zeros(1, Mmax);
CmimoMx4  = zeros(1, Mmax);

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


for kk=1:It
    
    for M = 1:Mmax
        
        % MIMO tx=4 , rx = M
        Hmimo4xM = ( randn(M,4)   + j*randn(M,4)   )/sqrt(2);
        Cmimo4xM(M) = Cmimo4xM(M) + log2(real(det( eye(M) + SNR/4*Hmimo4xM*Hmimo4xM' )));
        
        % MIMO  tx=M , rx = 4
        HmimoMx4 = ( randn(4,M)   + j*randn(4,M)   )/sqrt(2);
        CmimoMx4(M) = CmimoMx4(M) + log2(real(det( eye(4) + SNR/M*HmimoMx4*HmimoMx4' )));
      
    end
    
end

% Compute average over all channel realizations
Cmimo4xM = Cmimo4xM/It
CmimoMx4 = CmimoMx4/It


% plot
figure(1)
plot(1:Mmax, Cmimo4xM,'k')
hold on
plot(1:Mmax, CmimoMx4,'k--')
xlabel('Number of tx or rx antennas M')
ylabel('Ergodic Capacity (bits/transmission)')
title('Ergodic Capacity for i.i.d. Rayleigh fast fading channel at high SNR (80dB)')
text(2.1,62,'slope = 4', 'rotation',56)
text(6,110,'MIMO 4xM')
text(6,100,'MIMO Mx4')
axis([1 8 20 120])
grid
hold off

