Synchronizing to an time-varying external pulse

Thanks guys. Good advice.