1. We will be in Read Only mode (no new threads, replies, registration) for several hours as we migrate the forums to upgraded software.

# log and antilog amplifier

Discussion in 'Homework Help' started by PG1995, Apr 25, 2012.

1. ### PG1995 Thread Starter Distinguished Member

Apr 15, 2011
813
6
Hi

Though I have four or five queries to make about log and antilog amplifiers, I will start with a basic and inportant one. Please have a look on the attachment to see Q1. Thank you.

Regards
PG

File size:
60.5 KB
Views:
195
2. ### WBahn Moderator

Mar 31, 2012
24,560
7,700
Q1 summary: 2V was applied to the input of a log amplifier and the output was calculated to be -0.150V. But neither the log(2) nor the ln(2) is 0.150, so where am I going wrong in understanding the operation?

The key point you are missing is that a log amplifier only says that the output (voltage, in this case) is proportional to the logarithm of the input (voltage, in this case).

Let's say that you now applied not 2V, but the cube of 2 volts (namely 8V). Regardless of which base you used when you took the logarithm of the first value, you would expect the output for the cube of that input value to be three times as big, or -0.450V (the minus sign being a result of it being an inverting amplifier).

The other thing you need to understand is that the only difference between taking the logarithms with respect to any pair of bases is a scaling constant.

For instance, say our input is x (this isn't a voltage, just a number since we are just talking about the mathematics of logarithms right now). For a given base, b, the logarithm is simply the value, y, that satisfies the relation:

$
$

So let's take the log of both sides of the right hand expression. Pick your base, it doesn't matter; let's use natural logs.

$
ln(x) = y ln(b)
$

$
y = \frac{ln(x)}{ln(b)}
$

So, want the natural log of x to the base 1.234? Simply take the log of x to any base that is convenient and scale the result by dividing it by the log of the desired base with respect to the same base you used for the numerator.

The point is that if you really needed the output of your circuit to be interpretted as the logarithm of the input voltage in a particular base, all you (ideally) have to do is scale it appropriately either with a follow-on amplifier or by choosing a different value of the input resistor. In practice, there is also an offset that needs to be corrected for. To see this, note the symbolic solution given in the first part of the solution. The input voltage is scaled both before and after the ln() is taken. Thus you have not only a gain issue, but also an offset issue.

In practical circuits, it doesn't matter what base or what offset is used, as long as it is consistent throughout the circuit. Just as when using logs to multiply two numbers together, it doesn't matter which base you use, as long as you consistently use the same base.

BTW: I commend whoever put the example and the solution together. It is not often that you see an author actually track the units through the work properly.

PG1995 likes this.
3. ### PG1995 Thread Starter Distinguished Member

Apr 15, 2011
813
6
Thanks a lot, WBahn.

Although I can see you have put together your reply really nicely, I'm sorry I'm still struggling with this now as a result of my own limitations. I hope you won't mind helping me with this stuff a bit more.

Okay. Here, we apply +8V to the input instead of +2V. The answer is -0.184444 V. Shouldn't the answer be -0.44936 V because "8" is three times of "2"? Thanks.

Regards
PG

4. ### WBahn Moderator

Mar 31, 2012
24,560
7,700
It's because of that offset I mentioned.

Let's use a simple example that has nothing to do with logs. Assume I have an amplifier that gives you the following input/output data:

$
\begin{array}{cc}
Input (V) & Output (V)
1 & 4
2 & 7
3 & 10
4 & 13
\end{array}
$

What is the gain of this amplifier?

If you plot the above data, you would discover that the governing equation is

$
V_{out} \ = \ 3V_{in} \ + \ 1V
$

And so it has a gain of 3 with an offset of 1V.

But, if given a single data point, such as 1V in yields 4V out, and told that it has a gain of 3, you might reasonably expect that 2V in would result in 8V (i.e., doubling the input should double the output since the relationship would seem to be a linear one). But it isn't because of that offset.

To get a voltage that is 3 times in the input, you have to make a circuit that removes the offset by subtracting 1V.

When working with a log amplifier that uses a diode as the log element, things get more complicated even than the math. Note that if you put in 0V, then you would have zero current through the diode and,ideally, 0V at the output. But the log of 0, to any base, approaches negative infinity. This is actually somewhat consistent (but for a different reason) to what the circuit does because note that any positive voltage at the amplifier output is conistent with a 0V input since that would still result in no current flowing in the reverse-biased diode. But, for any positive input voltage, the output will be negative (implying a positive logarithm due to the inverting nature of the amplifier).

So let's look at the math again:

$
V_{out} \ = \ -V_t \ ln \left( \frac{V_{in}}{I_R R_1} \right)
$

Most people would proceed to split the logarithm into the difference of the log of the numerator and the log of the denominator, however the argument to the log function has to be dimensionless and this would give the argument to the each log function units of volts. If you are really careful, you can play these games, but a better way is introduce a constant that carries the necessary units information. In this case, we divide both the numerator and denominator by 1V:

$
V_{out} \ = \ -V_t \ ln \left( \frac{\frac{V_{in}}{1V}}{\frac{I_R R_1}{1V}} \right)
$

and then split it out:

$
V_{out} \ = \ -V_t \ \left[ ln \left( \frac{V_{in}}{1V} \right) - ln \left( \frac{I_R R_1}{1V} \right) \right]

V_{out} \ = \ -V_t \ ln \left( \frac{V_{in}}{1V} \right) \ + \ V_t \ ln \left( \frac{I_R R_1}{1V} \right)
$

For this example problem, the offset works out to be -0.132V.

Hopefully, at this point, you can start to see what you might do in the actual circuit, using a summing amplifier, to remove the offset and scale the output so that you get a voltage that is the logarithm of the input voltage in a particular base.

5. ### t_n_k AAC Fanatic!

Mar 6, 2009
5,448
790
Attached is an implementation which attempts to produce the desired outcome. It took a lot of tweaking of values to get a valid working simulation. This suggests a practical implementation isn't a trivial task.

File size:
22.2 KB
Views:
127
6. ### PG1995 Thread Starter Distinguished Member

Apr 15, 2011
813
6
Thank you very much, WBahn, t_n_k.

@WBahn: I don't get one thing that why we don't get correct result for an ideal circuit in this case. I understand that when this circuit will be implemented practically then we won't get correct results because then we will be dealing with non-ideal components and many errors will come into play and we will need to compensate for various errors such as offset voltage, offset current, etc. But here we can't even get correct result for an ideal circuit which has nothing much to do with those real world errors. To me, it means that there was problem with the derivation of the formula and we didn't account for some important factor. Do I make any sense to you? Please let me know.

@t_n_k: Could you please tell which software you used to draw that diagram? Thank you.

Best wishes
PG

Last edited: Apr 27, 2012
7. ### Jony130 AAC Fanatic!

Feb 17, 2009
4,923
1,381
Simply, the op amp output attempts to do whatever is necessary to make the voltage difference between his inputs was equal to zero.
So if you have 0V at the "+" input and the the op amps wants to have the same voltage at it's "-" input (0V).
So we have this situation:
The R1 current is equal to
IR1 = Vin/R1 = 20μA
And this current will flow through the diode.
This current will cause the voltage drop across the diode equal to:
Vd ≈ Vt * ln*(Id/Ir) = 25mV * ln (20μA/50nA) = 25mV * ln(400) =
25mV * 5.991 ≈ 0.1497V ≈ 150mV

It looks like a SIMetrix software

Last edited: Apr 27, 2012
PG1995 likes this.
8. ### WBahn Moderator

Mar 31, 2012
24,560
7,700
What are you considering to be the "correct" result in this ideal case?

The thing to keep in mind is that, even ideally, this amplifier is NOT taking the log of the input voltage, it is taking the log of the input voltage divided by the product of the thermal voltage and the input resistance and then multiplying that (the log of all that stuff) by the negative of the thermal voltage. So, even ideally, you have offsets and gains to deal with.

PG1995 likes this.
9. ### t_n_k AAC Fanatic!

Mar 6, 2009
5,448
790
Yes - Jony130 is correct.

Perhaps you have misinterpreted the name "Logarithmic Amplifier" ascribed to the circuit in question as being synonymous with an ideal log amplifier design. It's not - not even in an ideal theoretical sense. It's not a case of applying an input voltage Vin and expecting to get an output voltage of loge(Vin).

WBahn has proved the point mathematically quite satisfactorily. I suspect you haven't grasped the analysis given.

Perhaps some alternative observations might be of use.

1. You'll note that the diode [albeit ideal] must be biased by the input current flowing in the input resistor [100kΩ]. With a 1V input for instance, one would anticipate a bias current of 10uA [1V/100kΩ].
2. The same bias current flows into the ideal diode if the op-amp is ideal - since no input bias current would be required by the ideal amplifier itself.
3. The input bias current will set up a forward voltage drop across the diode which in an ideal world would exactly conform to the Shockley diode model equation.
4. Suppose the corresponding ideal diode forward voltage drop at 10uA happened to be 400mV. It doesn't matter what the actual is but this gives us a number to aid our understanding. The theoretical value would be equivalent to that value obtained via the Shockley equation on the basis of the diode theoretical physical parameters.
5. The anode end of the diode is sitting at 0V. This happens because the ideal op-amp forces the circuit conditions to set the -ve op-amp input to 0V since the +ve op-amp input is at 0V.
6. The cathode end of the diode is 400mV [forward diode voltage drop] lower in potential than the anode end of the diode. So the cathode is at -400mV. The cathode end of the diode is connected to the op-amp output so the op-amp output is also at -400mV.
7. Clearly -400mV isn't the natural logarithm of 1V [the input voltage].
8. However, suppose we change to input voltage to 2V. The input bias current will change to 20uA and the diode bias current will also be 20uA. This will mean the forward voltage drop across the diode will increase somewhat. Let's say it increases to 418.02mV. So the op-amp output is also -418.02mV.
9. So from 1V input to 2V input we have a corresponding output change of -18.02mV.
10. Suppose we increase the input to 5V with a corresponding adjustment in the diode bias current to 50uA. In the same manner as before we would expect a a change in the output voltage. On the basis of the previous change one would expect a theoretical increase in diode forward voltage to 441.845mV [based on an ideal Shockley equation model]. So the op-amp output would now be -441.845mV.
11. Let's review what's happened. With the input voltage change from 1V to 2V we had an output magnitude change of 18.02mV. From 1V to 5V we had an output magnitude change of 41.845mV. The ratio of the magnitude changes is 41.845/18.02=2.322.
12. The ratio of the natural logarithms of the corresponding inputs is loge(5)/loge(2)=1.6094/0.69315=2.322. So the output magnitude changes are responding to the natural logarithm of the inputs BUT with a constant offset of -400mV.
13. I can easily get rid of the -400mV offset problem by looking only at the output changes. To get the output signal changes to correspond exactly to the actual logarithm of the input voltage I would have to apply a multiplying factor to the output magnitude changes in repsonse to the input changes.
14. Returning to the case of an input of 1V is important. If the output value is -400mV with 1V input then removing the difference in magnitude of the aforementioned -400mV offset would give an output of 0V which satisfies the necessary result of loge(1)=0.
15. There's one final important question - what happens when the input is zero volts? We know that loge(0) is undefined so the point to note here is that we cannot ever allow the input to this circuit to be zero volts and expect a rational result.

Last edited: Apr 28, 2012
PG1995 likes this.
10. ### PG1995 Thread Starter Distinguished Member

Apr 15, 2011
813
6
Thank you very much, Jony, WBahn, t_n_k.

I still have to make some queries to clear up all this but let me mention your help has improved my understanding of several points. So, please don't be frustrated and even if I'm not understanding some of the stuff you are saying right now would make sense to me later. Thanks for the understanding. I will use t_n_k's last post.

Yes, I have misinterpreted because the op-amp circuit I have already studied corresponded to reality. For example, summing amplifier gives correct so does differentiator etc.

Yes, WBahn did a nice job in putting together the material and really appreciate but I wasn't able to fully grasp it because of my own shortcomings.

Q: For 1V input, the output voltage is -400mV and as you say the output value isn't correct because In(1)=0.

So, is it the actual error which leads to misleading result? In other words, if we had 0V output for 1V input, would the results still be wrong? Stating it other way, we need to take output value at 1V (which in our case is 400mv) as a reference 0V and need to measure any other output value with reference to it. Please let me know if I make any sense this time. Thank you for your time and help.

Regards
PG

11. ### WBahn Moderator

Mar 31, 2012
24,560
7,700
What error! You keep insisting on expecting the output to be in apples but have implemented an amplifier that outputs oranges and keep ignoring the fact that you still have to convert from oranges to apples.

Look at the equation at the very bottom of Post #4. To get the natural log of the voltage, you have to first subtract off the offset voltage of -0.132V (analogous to t_n_k's 400mV in his example). You then have to divide by the gain of -25mV.

If nothing else, consider that the output of your circuit is in volts, but the natural log of a number is just a number. Dividing by -25mV removes the units from the output.

Let's apply this to the example given in the problem. The circuit output is -150mV. We then subtract -132mV giving us -18mV. We then divide by -25mV giving us a final answer of 0.720.

The input was 2V. If we assume that the input scaling is 1V/number (in other words, that our input number is 2 and we converted that to volts by using 1V for a value of 1 and so on), then our circuit is saying that the ln(2) is 0.720, which is reasonably close to the true value of 0.693. The discrepancy is due to roundoff errors because we rounded everything to the nearest 1mV and, as you can see, the critical value in the computation is the -18mV so right there we have limited ourselves to potentially worse than 5% accuracy in the result.

If you go back and look at your integrator and differentiator circuits, you will probably find that they have a gain as well, though probably no offset.

PG1995 likes this.
12. ### PG1995 Thread Starter Distinguished Member

Apr 15, 2011
813
6
Thank you very much for the help, WBahn.

You know something things really take time to make sense. I found yours and t_n_k's last postings very helpful and my understanding has improved.

Best regards
PG