Infinity loop - waterfilling algorithm
2 views (last 30 days)
Show older comments
I'm trying to write a code to carry out the Waterfilling algorithm for MIMO channels. I've written the code below but there is something wrong with my WHILE loop. I get negative power and also endless loop at the end. I'm trying to write the code for the given formula below:

and here is my code:
P=zeros(1,r);
sq=zeros(1,3);
for i=1:numel(SNR)
p=1;
go = true;
while go
for j=1:r-p+1
K(j)=1/L(j);
T =sum(K);
end;
m =(1/(r-p+1))*(1+ (1/0.1)*T);
for j=1:r-p+1
P(j)= m-(1/(0.1*L(j)));
if P(r-p+1)< 0
P(r-p+1)=0;
end;
sq(j) = sum(P);
if sq(j) <= 1.00005
go = false;
else
p=p+1;
end;
end;
end;
for j=1:r
C_equal_t2(j)=log2(1+SNR(i)*L(j)*P(j));
C_eigen(i)=sum(C_equal_t2);
end;
end;
2 Comments
Geoff Hayes
on 20 Apr 2020
Ahmad - in your code you have
for j=1:r-p+1
P(j)= m-(1/(0.1*L(j)));
if P(r-p+1)< 0
P(r-p+1)=0;
end;
% etc.
end
Why, on each iteration of the loop, do you check to see if
P(r-p+1)< 0
? You are doing the same comparison for each j. Do you mean this to be
if P(j) < 0
P(j)=0;
end;
instead?
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!