Logarithm and exponential function with OpAmps

27 Feb 2022 - tsp
Last update 28 Feb 2022
Reading time 7 mins

A look at diodes

So lets first take a look at diodes. These are build by forming pn-junctions - i.e. usually a p-well inside a n-well on p substrate in the most common circumstances. The pn junction conducts current only when biased in one direction but not into the other. A typical diode data-sheet shows three regions:

When bias voltage is increased above a given threshold the diode switches into conductive region. In this case the current in large signal region is described in theory the best way by the so called Shockley equation that provides a basic model for drift due to biasing, thermal diffusion and thermal recombination-generation processes. The curves shown in datasheets are usually looking approximately linear due to logarithmic scaling:

[ I \approx I_S(T) * (e^{\frac{U}{n * U_t}} - 1) ]

In this equation:

As one can clearly see from the formula this is approximately an exponential function (dropping the $-1$ term is insignificant in the large signal operation region of the diode)

Ideal diode forward current

Building an logarithmic amplifier

So how does one build an exponential amplifier using this knowledge about diodes? The idea is simple and works the same as as the inverting amplifier. One just uses the diode in the feedback path:

Logarithmic amplifier

How does this circuit work? Basically one just has to look at the current balance at the non inverting summation point while assuming that this summation point is virtual ground since the operational amplifier compares with the reference ground on the non inverting input:

[ I_R = \frac{U_{in}}{R_1} \\ I_D \approx I_S(T) * e^{\frac{U_D}{n * U_t}} \\ I_R = I_D \\ \frac{U_{in}}{R_1} = I_S(T) * e^{\frac{U_{out}}{n * U_t}} \\ \frac{U_{in}}{R_1 * I_S(T)} = e^{\frac{U_{out}}{n * U_t}} \\ \ln(\frac{U_{in}}{R_1 * I_S(T)}) = \frac{U_{out}}{n * U_t} \\ n * U_t * \ln(\frac{U_{in}}{R_1 * I_S(T)}) = U_{out} \\ n * U_t * \ln(U_{in}) - \underbrace{n * U_t * \ln(R_1 * I_S(T))}_{\approx 0} = U_{out} ]

In the above equations I’ve assumed that $I_S(T)$ is typically on the range of $10^{-9}$ ampere. Thus the logarithm might be in the range of $-10$ when using $k\Omega$ resistors. In addition to a typical $U_t$ on the range of $0.03V$ this leads to voltages in the $-0.4V$ range - this has to be compensated for in the final design of course but will be neglected during the circuit description.

As one can see $U_{out} \propto \ln{U_{in}}$

Note that these equations only hold as long as the input signal is positive with respect to the reference ground since the diode would block the feedback voltage when operating in the other regime.

To make the equations a little bit more readable one can of course absorb the scaling factor into the base of the exponential:

[ \frac{U_{in}}{R_1 * I_S(T)} = e^{\frac{U_{out}}{n * U_t}} \\ \frac{U_{in}}{R_1 * I_S(T)} = (e^{\frac{1}{n * U_t}})^{U_{out}} \\ a = e^{\frac{1}{n * U_t}} \\ \frac{U_{in}}{R_1 * I_S(T)} = a^{U_{out}} \\ \log_{a}(\frac{U_{in}}{R_1 * I_S(T)}) = U_{out} \\ \log_{a}(U_{in}) - \log_{a}(R_1 * I_S(T)) = U_{out} ]

Building an exponential amplifier

Now one can calculate the natural logarithm one might also want to do the other way round and calculate the exponential function. This can be done by simply using the diode in the input path instead of the feedback.

Exponential amplifier

The equations work exactly the same way as for the logarithmic amplifier before - but they have input and output voltage exchanged:

[ I_R = \frac{U_{out}}{R_1} \\ I_D approx I_S(T) * e^{\frac{U_D}{n * U_t}} \\ I_R = I_D \\ \frac{U_{out}}{R_1} = I_S(T) * e^{\frac{U_{in}}{n * U_t}} \\ U_{out} = R_1 * I_S(T) * e^{\frac{U_{in}}{n * U_t}} ]

As one can see the output is proportional to the exponential of the input voltage. In both equations one can make ones life a little bit simpler when trying to imagine how these systems work by absorbing the scaling factor $\frac{1}{n * U_t}$ into the base as before:

[ \frac{U_{out}}{R_1} = I_S(T) * e^{\frac{U_{in}}{n * U_t}} \\ \frac{U_{out}}{R_1} = I_S(T) * a^{U_{in}} \\ U_{out} = R_1 * I_S(T) * a^{U_{in}} ]

A simple application: Mixing signals

So where does one use such circuits? Of course there are many applications such as audio volume and generic computation, deflecting beams in logarithmic or exponential way, building function generators, etc. - but one is particular impressive in my opinion. This is the mixing of signals for low frequency applications (higher frequencies usually prohibit the usage of operational amplifiers and use more sophisticated layouts such as Gilbert cells for example).

As one can see the expressions for the exponential and logarithmic amplifier do exactly cancel each other:

[ U_{out} = R_1 * I_S(T) * a^{U_{1}} \\ U_{out} = R_1 * I_S(T) * a^{\log_{a}(U_{in}) - \log_{a}(R_1 * I_S(T))} \\ U_{out} = R_1 * I_S(T) * a^{\log_{a}(\frac{U_{in}}{R_1 * I_S(T)})} \\ U_{out} = R_1 * I_S(T) * \frac{U_{in}}{R_1 * I_S(T)} \\ U_{out} = U_{in} ]

Of course in reality there will be some drift between both stages but usually it’s closed enough.

To mix signals one usually wants to multiply them.

[ U_{out}(t) = U_{in,1}(t) * U_{in,2}(t) ]

Unfortunately there is no direct way of multiplying using an operational amplifier. But there is one to perform additions - the summation amplifier:

Summation amplifier

The analysis of this circuit works similar to the inverting amplifier. One just has to sum up all currents flowing into the summation point at the inverting input:

[ I_{in,1} = \frac{U_{in,1}}{R_{in,1}} \\ I_{in,2} = \frac{U_{in,2}}{R_{in,2}} \\ I_{fb} = \frac{U_{out}}{R_{fb}} \\ I_{fb} = I_{in,1} + I_{in,2} ]

In the last equation it already has been taken into account that the current from feedback will flow into the different direction due to the inverting nature of this amplifier.

[ I_{fb} = I_{in,1} + I_{in,2} \\ \frac{U_{out}}{R_{fb}} = \frac{U_{in,1}}{R_{in,1}} + \frac{U_{in,2}}{R_{in,2}} \\ U_{out} = R_{fb} * (\frac{U_{in,1}}{R_{in,1}} + \frac{U_{in,2}}{R_{in,2}}) ]

In case all input resistors have the same resistance one only gets a single scaling factor:

[ I_{fb} = I_{in,1} + I_{in,2} \\ \frac{U_{out}}{R_{fb}} = \frac{U_{in,1}}{R_{in,1}} + \frac{U_{in,2}}{R_{in,2}} \\ U_{out} = \frac{R_{fb}}{R_{in}} * (U_{in,1} + U_{in,2}) ]

One can of course extend the concept of the summation amplifier to an arbitrary number of inputs:

[ U_{out} = R_{fb} * \sum_{n_{inputs}} \frac{U_{in,n}}{R_{in,n}} ]

So how does this summation become interesting for signal mixing? One can transform the problem of multiplication into an addition by taking the logarithm:

[ x * y \\ \ln(x*y) = \ln(x) + \ln(y) ]

Then one can of course apply the inverse transform again:

[ x * y \\ a^{\log_{a}(x*y)} = a^{\log_{a}(x) + \log_{a}(y)} ]

That way one can implement signal multiplication in an easy way using operational amplifiers:

Simple operational amplifier mixer

One of course has to take into account the saturation as well as the noise figures of the operational amplifiers.

This article is tagged: Tutorial, DIY, Electronics, Physics, Basics, Measurements, OpAmp


Data protection policy

Dipl.-Ing. Thomas Spielauer, Wien (webcomplains389t48957@tspi.at)

This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/

Valid HTML 4.01 Strict Powered by FreeBSD IPv6 support