It's the first part you will have trouble with; a frequency measuring circuit. This is done with a differential amplifier. You compare the two frequencies, of the same phase, giving you a zero output. The phase part is the hardest. You will need to set the phase up using two generated clocks. One clock is the signal, the other clock is the reference oscillator.