Infinity loop - waterfilling algorithm
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2020-4-20
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?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!