for loop problem
2 views (last 30 days)
Show older comments
i have a for loop in m file.the strange is that when i excetute it for about 100 times everything is ok.when i increase the execution for over a 1000 times the loop crashes and outputs the result until the loop is reached.
the for loop is an implementation of self-correlation and cross-correlation functrions for packet detection in DSP.
i initialize the configuration of the m file with the below:
n=10;
t=1;
z=40;
floor_bit=5;
noise= -5 + (5+5).*rand(1,n);
[correlationResultAbs,stepAbs,correct_packets,incorrect_packets,S_off,xCorr1Abs,packet_number,K_log,t,db_log,p_log]=test_interpolated_packets(n,z,t,floor_bit,noise)
the m file is:
h = waitbar(0,'Please wait...');
steps = n;
% gia to interpolation theoro ton sintelesti t opou t=2 gia
% interpolation*2 kai t=4 gia interpolation*4
incorrect_packets=zeros;
correct_packets=zeros;
S_off(1:n)=zeros;
flag(1:n)=zeros;
packet_number(1,n)=zeros;
p_log(1:n)=zeros;
K_log(1:n)=zeros;
db_log(1:n)=zeros;
snr=noise;
for q=1:n
temp10=awgn_interpolated_packet(snr(q),t);
waitbar(q/ steps)
xCorr1Abs=zeros;
step=zeros; %sE kathe loop midenizo tous pinakes
correlationResult=zeros;
%-----ipologizo to awgn me ti variance kai epilego katallilo K
[K,p,db] = K_detection(temp10,t);
p_log(q)=p;
K_log(q)=K;
db_log(q)=db;
d=0; %arxikopoio ti step
flag_packet_start_found=1;
startpoint=0;
%---------------------------------aytoshsxetish-------------------------%---
for w=1:(128*t)
temp1=(temp10(w)*conj(temp10((3*t*165)+w)));
temp1_Floored=floored(temp1,floor_bit);
correlationResult(1)=correlationResult(1) +temp1_Floored;
temp2=temp10(w)*conj(temp10(w));
temp2_Floored=floored(temp2,floor_bit);
temp3=temp10((3*165*t)+w)*conj(temp10((3*t*165+w)));
temp3_Floored=floored(temp3,floor_bit);
d=d+temp2_Floored+temp3_Floored;
end
step(1)=(K)*(0.5)*d;
m=(4000*t); %exoume sinolika gia ta 30 ofdm stoixeia tou paketou +100 %stoixeia data 5050 stoixeia opote %4427+3*165+124=5050
stop=(4000*t);
%%orizw2 pinaka toso megalo wso ta apotelesmata pou xreiazomai
for u=1:m
temp4=-(temp10(u)*conj(temp10((3*t*165)+u)))+(temp10((t*128)+u)*conj(temp10(t*(3*165)+(t*128)+u)));
temp4_Floored=floored(temp4,floor_bit);
correlationResult(u+1)=correlationResult(u)+temp4_Floored;
%opote exw ypologisei oles tis aytosysxetiseis kai pleon thelw na valw to
%stept
temp5=((z)*(0.01))*(temp10((3*t*165)+u+(128*t))*conj(temp10((3*t*165)+u+(t*128)))-temp10((3*t*165)+u)*conj(temp10((3*t*165)+u)));
temp5b=((z)*(0.01))*(temp10((t*128+u))*conj(temp10((t*128+u)))-temp10(u)*conj(temp10(u)));
temp5_Floored=floored(temp5,floor_bit);
temp5b_Floored=floored(temp5b,floor_bit);
step(u+1)=step(u)+temp5_Floored+temp5b_Floored;
end
correlationResultAbs=abs(correlationResult);
stepAbs=abs(step);
for b=1:m
if correlationResultAbs(b)>stepAbs(b) %edo thelei panta prosoxi gia tin
%epilogi tou sintelesti sto katofli analoga to SNR
%pou exoume valei!!!
xcorr_start=b;
if b==32
startpoint=0;
elseif b<32
startpoint=-(32-b);
elseif b>32
startpoint=+(32+b);
end
if startpoint==-31;
correct_packets=correct_packets+1;
else
incorrect_packets=incorrect_packets+1;
end
break
elseif b==stop
%%an den mporesw na prosdiorisw startpoint prepei na xrisimopoihsw
%%ena flag
flag_packet_start_found=0;
return
end
end
flag(q)=flag_packet_start_found;
below the code continues to cross correlation and at the function declaration of the m file the declaration is the same as the one in the configuration file.
2 Comments
Answers (1)
See Also
Categories
Find more on PHY Components 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!