Infinity loop - waterfilling algorithm
조회 수: 11 (최근 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!