indeed an elegant/clever way to find true period.

thanks!

will try to implement into my pendulum asap

if( omega*omegas<0){
count=count+1;
}
omegas=omega;//save old value
if(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
}

will update my progress on your forum soon :)