%Demonstration of waterfill algorithm
%Total power is P
%Noise power is N
N=1;
P=10;
G=randn(2,3);
[U,S,V]=svd(G);
lambda=(2*S(1,1)*S(2,2))/((S(1,1)+S(2,2))*1+S(1,1)*S(2,2)*P);
P1=(1/lambda)-(N/S(1,1));
P2=(1/lambda)-(N/S(2,2));
figure
bar([1/lambda 1/lambda],’b’)
hold
bar([N/S(1,1) N/S(2,2)],’r’)
