Average period of input signal and regenerate a signal according to the cycle