How Can speed up "for" loop ?

9 ビュー (過去 30 日間)
NYYmin
NYYmin 2021 年 3 月 6 日
コメント済み: NYYmin 2021 年 3 月 7 日
Hi,
How can I speed up following 'for' loops? Help me please.Thanks.
N=1000 > 30sec , N=1000 > 10min , N=100000 > 5hr up can't produce result
N = 100000;
B= 0.3;
Pf=linspace(0.9,0.1,n);
data = randi([0,1],N, 1);
for k=1:2
Lambda= (1+sqrt(2/N)*qfuncinv(Pf))*var(wgn(N, 1,0) .* sqrt(p(k)/2));
for i = 1:length(Pf)
Nd_BPSK=0;
for j=1:N
noise_BPSK = wgn(N, 1,0) .* sqrt(p(k)/2);
h_BPSK = raylrnd(B, N, 1);
receive_BPSK = abs(h_BPSK).*send_BPSK + noise_BPSK;
T_simu_BPSK(i)=sum(abs(receive_BPSK).^2)/N;
if T_simu_BPSK(i) > Lambda(i)
Nd_BPSK=Nd_BPSK+1;
end
end
Pd_simu_BPSK(i,k)=Nd_BPSK/j;
end
for i = 1:length(Pf)
Nd_QPSK=0;
for j=1:N
noise_QPSK = wgn(N/2, 2, 0) .* sqrt(p(k)/2);
h_QPSK = raylrnd(B, N/2, 2);
receive_QPSK = abs(h_QPSK).*send_QPSK + noise_QPSK;
receive_QPSK2=reshape(receive_QPSK,N,1);
T_simu_QPSK(i)=sum(abs(receive_QPSK2).^2)/N;
if T_simu_QPSK(i) > Lambda(i)
Nd_QPSK=Nd_QPSK+1;
end
end
Pd_simu_QPSK(i,k)=Nd_QPSK/j;
end
end

回答 (1 件)

darova
darova 2021 年 3 月 6 日
I don't see here any i or j. You can place them outside loops
  3 件のコメント
NYYmin
NYYmin 2021 年 3 月 7 日
Generate signal strength,If it is not in the loop,it not random.
The program is to compare the signal is greater than the threshold.
If T is fixed, the number of detections N is meaningless.
All j cycles are the same number.
Maybe I need good computer to run this.
Thank you.
NYYmin
NYYmin 2021 年 3 月 7 日
Maybe I can use parfor?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeQPSK についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by