valley peak detector

Hi All,
I am not limited to the first circuit I posted. It can be a circuit with an op amp, or comparator.