I am reading Arts of Electronics and they are showing this circuit:
It says that D1 compensates for D2's forward drop by providing 0.6V of bias. I don't understand this circuit at all. Is the +5V an external 5v source? How does it compensate?
The \$R_1\$, \$R_3\$ and \$D_1\$ circuit basically creates a 0.6V bias on the other side of the capacitor, so that a positive swing in the signal does not have to overcome a 0.6V hurdle. \$D_1\$ and \$R_3\$ form a shunt voltage regulator. The 0.6V voltage is conveyed to \$D_2\$ which is on the verge of conducting, as a result. So only a small positive upswing from the input is required to bring it to conduction. Because the input is capacitively coupled, it is pure AC. Its swings are additively superimposed on top of the bias voltage that exists on the other side of the capacitor. The 5V source is just from somewhere in the rest of the circuit. There is nothing special about it.
Perhaps you can get a different perspective by redrawing the circuit so that voltage falls from top to bottom. In this view, we highlight how the input is biased to 0.6V, but the output is 0.6V below that, down across the voltage drop of D1. So for instance suppose that the input creates a positive swing of 0.1V. This becomes 0.7V at the top of D2 (the whole point of the bias). At the bottom of D2, that swing is 0.1V again. D2 lets through enough current so that R2 has 0.1V across it.
A negative swing of 0.1V turns to 0.5V. But this cannot create a -0.1V output at the bottom of D2; that is nonsense because it is outside of our supply range. 0.5V is not enough to forward bias D2, and so the output is at 0V, pulled to ground by R2, which has almost no current flowing across it to create any voltage.
The purpose of R1 is to act as a flexible linkage to separate the reference 0.6 voltage, which is quite stiff, from the point where the signal is injected, which must on the contrary be free to swing about 0.6V. R1 also protects the diode from the input current swings. If we replace R1 by a wire, it won't work because the signal will try to move the voltage at the top of D1, whose cathode is pinned to ground. The input's positive swings will dump current through D1, abusing it. That creates a poor input impedance, resulting in an inability to generate the right voltage on or under D2.
On the other hand, if R1 is made large, the compensation diminishes, because the reference voltage is able to exert less control over the bias.
simulate this circuit – Schematic created using CircuitLab
To make it nicer for simulation, let us make the capacitor way bigger: 10 uF. Then we can use a nice, low frequency like 1000 Hz, which will not pass very well through a 100 pF capacitor into a less than 1K impedance. Also, let's hook up a signal source with a 3V amplitude. If you run the time domain simulation, you will see that the output waveform is quite precisely chopped in half.
I’ve been stuck by the same circuit and it uncovered a bunch of things that I didn’t understand in detail. So I’ll try to go very low-level in my explanation. If you notice anything wrong, please tell me and I’ll correct. Please also read the other answers, as they provide very valuable high-level insight.
First, make sure you understand diode voltage drop (if not google it). Diodes "consume" ~0.6-0.7V of your input, in other words, the voltage across the diode is ~0.6V. Since Voltage in series adds up, this means R3 sees ~4.3V (5V of the current source minus 0.6V of the diode).
simulate this circuit – Schematic created using CircuitLab
Next, we add a second path in parallel. This can be tricky to understand. e.g. Why would the current take the path with the resistors at all? But in the end, this is simple again: The diode takes 0.6V. R1 & R2 run in parallel to the diode, so they in total have 0.6V as well. Now they form a voltage divider, so we get \${1\over 11}\cdot 0.6V\$ across R1 and \${10\over 11}\cdot 0.6V\$ across R2.
To make things more complicated, there’s another diode in between R1 & R2. You could argue, that there’ll be another 0.6V drop across D2, which means across R1 & R2 will be 0V each, i.e. no current flowing at all. In practice Diodes will let some current through even before the 0.6V threshold is reached. If you simulate the circuit, it’ll calculate the drop to be only 0.4V with a current of 20μA. So there’ll be some very very small current going through the D2 side, while most of the current (4300μA or 99.5%) goes through D1. But as you can see, the point where SIG enters the circuit would in both cases still be at ~0.6V potential.
Now the final part to the puzzle is how the signal and 0.6V add to each other. In other words, how these two voltages become superimposed. I suggest to read up on how this works, if this is unclear, the following brief example illustrates the concept: You can consider the capacitor a voltage source and you calculate voltages for each source separately and add them up later.
So if 0.1V are discharged during the rising signal edge, the voltage potential will be 0.6V + 0.1V, the diode removes 0.6V of these, so the output only sees 0.1V again (minus neglectable minor voltages for the inaccuracies).
The external 5V source via R3 produces about 0.6V on D1's anode. Ignore the input signal for now. The 0.6V level on D1 is transferred, via R1 to the anode of D2.
Because the cathode of D2 is connected to 0V via the 10k resistor, D2 is on the verge of conducting - this is where you need it to be for a semi-decent precision half wave rectification of a signal.
The signal arrives on D2's anode and all positive values will further enhance the forward bias of D2 hence the positive half cycle of the signal gets transferred to the output across R2.
Because D2 is on the cusp of being forward biased, any negative parts of the signal will reduce the forward bias of D2 and turn the device off thus, the negative half-cycles do not pass through D2.
A proper analysis would show a distortion (on the output waveform) around the mid-point of the signal but as a first approximation it will bear a reasonable resemblance to a precision half wave rectifier.
This is Figure 1.70 on page 36. Compensating the forward voltage drop of a diode signal rectifier. Art of Electronics. Third Edition.
This case might be analyzed in a few steps.
First. We see that the current flows from the +5V source via D1 to Ground. Because we put resistor R3 on the way of this current, the battery is not shorted to Ground but losing only a few milliamps. This is a very low current in practical terms.
Second. In this scheme all voltages are measured relative to Ground. Imagine that we don't have capacitor C (no signal), and we don't have Vout (it is just a probe). We take a conventional voltage meter, and then poke one of its probes to Ground and the other one to point P on the scheme. What value will our voltage meter show us? The voltage meter WILL certainly show us some value across the legs of R1! It can't refuse doing its job.
What are our options for the voltage at point P?
Can this voltage be higher than +0.6V? No, we don't have any voltage source around point P. The only source in this scheme is +5V that drains to Ground via R3 and D1.
Can this voltage be lower than +0.6V? No, D2 is locked for all positive voltages equal or below +0.6V.
The only remaining option is exactly +0.6V!
Concluding remarks
If we take away R1 the Vout probe will not sense anything. The capacitor will be effectively shorted to ground via D1.
If we take away R2, then D2 will have its right leg shorted to Ground and Vout will always be probing Ground.
If we take away current limiting resistor R3, then the battery will be shorted to ground via D1. And will discharge immediately.
If we take away D1, then the battery +5V will be shorted to ground via R3. And therefore both legs of R1 (by all the above logic) will be linked to Ground.
Another way to explain it
Remember that electricity has analogy with water pipes. Voltage is the level of water. Current is the amount of water passing though a pipe. Resistors are just pipes with different diameters. Capacitors are like flexible (rubber) membranes put into water pipes. Inductors are water wheels.
In our case we the water flows though pipe R3 to ground. Just before D1 its level is 0.6V (meters) above the Ground. Resistor R1 is just a small pipe. It cannot push water indefinitely to point P as 0.6V water level is insufficient to open valve D2. It cannot suck water from point P because valve D2 is shut and does not allow water to flow from Ground via pipe R2.
The water just flows through pipe R1 toward point P. The water level (voltage) across pipe R1 is the same. Namely +0.6V (meters).
Now we put back capacitor C (membrane). Remember that for simplicity in the above discussion we took away C and disconnected this scheme from where it was to be able to analyze it in isolation.
Now we connect the whole scheme to where it is intended to, and see the water outbursts (ripple) between valve D2 and pipe R2 with the measuring stick Vout. The capacitor (membrane C) does not draw water from Vin. So the whole scheme is just "sensing" water pressure, no water is actually being drawn via Vin. Membrane C (capacitor) is blocking it.