Sounds like a PLL. After comparator with a specific level (making a digital signal) just feed the 2 signals with an XOR followed by an external low pass filter (simple R-C).
Yea, you are right,
I was also thinking the same way but without a low pass. But I think it's better to put a low pass.