Hello, I'm not from Power electronics but I think the solution of this question might be Power electronics. Following is partial of the circuit. I want the value of Vreference to be the average value of the "Out" signal. The green signal is the output of (AM)envelope detector, this signal has 20kHz and 20mV peak-to-peak. How can I change the circuit between the green and blue circle, so that I can make the blue signal an average value of the green signal?

