for loop problem

2 views (last 30 days)
Lampros-Eleftherios
Lampros-Eleftherios on 5 Mar 2012
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
Geoff
Geoff on 6 Mar 2012
When you say the loop 'crashes', is there an error message displayed?
Lampros-Eleftherios
Lampros-Eleftherios on 6 Mar 2012
there is no error message.matlab just stops the computations and outputs the results calculated untill this for loop that matlab exits.but it should continue to complete all the loops.
for example if there are 1000 loops to be done it can stop after 300 loops or after 500 loops etc etc...
yesterday i had to simulate for 500 loops but after 3x500 loops it starded crashing.so i continued on simulations of 250 loops saving results into ascii files in order to process results later.
in addition when i initialize the noise variable with a standar value for the whole simulation i have no problem.it may be problem of my mac?(memory etc etc) i am working on macbook pro (core 2 duo ,2.4 ghz,4gb ram)

Sign in to comment.

Answers (1)

Lampros-Eleftherios
Lampros-Eleftherios on 5 Mar 2012
also in some parts of the code when i copied from the matlab some comments were broken to the next line and it will be a little confusing to understand the code.excuse me for this.the comments are always written in greeklish(greek language in latin letters). thanks in advance!!!

Community Treasure Hunt

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

Start Hunting!