if( omega*omegas<0){ count=count+1;}omegas=omega;//save old valueif(count==2){ T=t-ts;// period=time differences, not necessary starts from t=0 ts=t; count=0;//you need to reset the counter, unless you only want to calculate the first period}