The output of the IF filter-amplifier is essentially a signal at 40 kHz that contains information about the instantaneous amplitudes of the input signal components, one at a time. Hence, it is basically a sine wave of single frequency and varying amplitude. We however need only the envelope for our purpose; the alternating signal can be done away with.
For this purpose, we use a peak detector. It consists of a diode capable of handling high frequencies along with an RC network whose time constant is large enough to filter out the alternating part and small enough to follow the envelope without appreciable distortion.
The time constant of the circuit is given by:
T = R1C1
When the input voltage is higher than the voltage across C1 (= Vout), the diode conducts and the capacitor charges up to the new voltage. When the input drops below the capacitor voltage level, the diode gets reverse-biased and stops conducting. The capacitor then discharges through R1 at a rate just rapid enough to follow the input envelope without much ripple. Thus, the output is the envelope of the input signal.