Initial algorithm for measuring frequency