How Can speed up "for" loop ?

1 Ansicht (letzte 30 Tage)
NYYmin
NYYmin am 6 Mär. 2021
Kommentiert: NYYmin am 7 Mär. 2021
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

Antworten (1)

darova
darova am 6 Mär. 2021
I don't see here any i or j. You can place them outside loops
  3 Kommentare
NYYmin
NYYmin am 7 Mär. 2021
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 am 7 Mär. 2021
Maybe I can use parfor?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by