I am now doing a MATLAB for calculating the capacity of a MIMO channel with CSI. Therefore, I need to use water filling to have the power level....but I have some problem that the result graph is concave downward. can anyone give me some suggesting where I did it wrong??
clear
nr=2;
nt=2;
minN = min(nr,nt);
transmitSNR = -20;
for k=1:21 %- set the value of Po/No in dB
for m=1:1000
for t=1:nr
for y=1:nt
a=1/sqrt(2)*randn(nr,nt);
b=1/sqrt(2)*randn(nr,nt);
H=a+1i*b; %- complex form of H
end
end
%- Hr=R^1/2*H;
[S V D]=svd(H);
cap(m)=0;
for n=1:1:minN
lambda(n) = V(n,n);
end
[lambda L] = sort(lambda,'descend');
lambda = lambda(find(lambda > 0)); % ignoring non-positive eigenvalues
pl = -1;
try
while (min(pl) < 0)
mu = (transmitSNR + sum(1 ./ lambda)) / length(lambda);
pl = mu - 1 ./ lambda;
lambda = lambda(1:end-1);
end
catch
disp('There exists no water filling level for the input eigenvalues. Check your data and try again')
end
pl = [pl; zeros(length(L) - length(pl), 1)]; % assigning zero power for weak eigen-modes
pl(L) = pl;
for n=1:1:minN
cap(m) = cap(m) + sum( log2(1 + pl(n).*lambda));
end
end
capacity(k)=mean(cap);
SNR(k) = transmitSNR;
transmitSNR = transmitSNR+2;
end
plot (SNR,capacity,'d-m'); hold on;
title('Graph of SNR & channel capacity');
xlabel('SNR,dB');
ylabel('Channel capacity');