Detection of saw tooth or square wave