Op amp production of y=ln(x)

I am looking to implement a true ln(x) function in an op amp circuit, operating at audio frequencies.

The goal is to feed a signal x into a quadratic equation (positive values only), and spit out a value y using analog computing techniques. I am currently ignoring temperature stability for simplicity.

To perform the exponentiation, I planned on converting the instantaneous signal x with a logarithm ln(x). Once I have ln(x), it is possible to square and do x**4 using multiplication (prior to the antilog). A summing stage at the end will add/subtract the terms involved.

For example:

y = a * x**4 - b * x**2

should be easily done, if I can get a proper ln(x) and it's antilog.

The following page under the heading "Logarithmic output" shows a typical circuit:

+------|>|---+ | D1 | | |\ | | | \ | Vin ----R----+--| -\ | | >-----+------ Vout +--| +/ | | / | |/ | ----- --- -

The wiki sez:

Vout = -VT * ln ( Vin / ( Is * R ) )

where:

VT ~= 25 mV at room temp. Is = saturation current for the diode D1

The problem that I have is that I want to eliminate the denominator underneath Vin. Ideally, I want to get:

Vout = ln ( Vin ).

VT is simple enough to work around with a compensating gain stage.

For the pesky Is * R denominator, I can make R large, perhaps 1M. At some point though, if R is too large, noise becomes a factor.

For Is, I can use a larger diode, such as a

1N4004 rectifier diode, with larger Is value (presumably somewhere in the 1E-09 range).

But even with large R and a larger Is, I still have a denominator that is < 1, leading to a larger x in ln(x).

I would like to get x = Vin.

Is there an alternate circuit design that can achieve this? Or are there ready-made chips that would do this more easily? I'll obviously need the antilog of the same.

Warren

Reply to
Warren
Loading thread data ...

I'd much prefer factoring the polynomial and using multipliers, due to the dynamic range issue. Taking the fourth power of anything gets nasty pretty fast at large or small inputs, and even if your final polynomial is something nice and bounded, e.g. a Chebyshev, the individual terms are not well behaved in general. Forming a polynomial as a product of individual monomial terms is *much* better-conditioned.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058

email: hobbs (atsign) electrooptical (period) net
http://electrooptical.net
Reply to
Phil Hobbs

Phil Hobbs expounded in news: snipped-for-privacy@electrooptical.net:

What if it were reduced to a cubic?

The range of x will be fairly restricted, BTW.

Warren

Reply to
Warren

If you're sure that the sensitivity is low enough for your application, sure, you can use whatever order you like.

Diodes don't obey the diode equation, though...you're much better off using diode-connected transistors, by which I mean CB shorted. (A diode-connected transistor is actually the world's simplest feedback amplifier, as I recently realized when my diode degeneration network was crapping out down in the medium nanoamps.)

The other issue is that a 1 degree temperature difference between transistors will get you a 9% error in exp(log(x)). You definitely need to use a monolithic array, such as a MAT14, CA3127, or LM3046, and keep the dissipation way down to avoid on-chip gradients.

Keeping the current low also reduces errors due to the extrinsic emitter resistance R_EE' and the base spreading resistance R_B', which effectively make the I_C asymptotically linear rather than exponential in V_BE. (The effect is exactly like putting in a small emitter degeneration resistor.) R_EE' is an ohm or somewhat less for a small signal transistor, and R_B' is probably less than 100 ohms. (Still, for betas less than a few hundred, R_B' is also important.)

Another fun approach if you don't need too much speed is to use a single transistor and a few muxes--store the log of the input on a capacitor someplace, and then use the same transistor to form the antilog.

You also need to have a reference channel--it's I_C2/I_C1 of a differential pair that's the well-behaved exponential in Delta V_BE. If you put twice V_BE across a diode, you won't get the square of the input, you'll get lava.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058

email: hobbs (atsign) electrooptical (period) net
http://electrooptical.net
Reply to
Phil Hobbs

Can't be done. ln(x) only works if x is a dimensionless quantity, or if you want to define what the logarithm of a volt is, then try to figure out how it'd appear in a circuit, and how it could be added to a real number.

The best you can do is

Vout = V_r1 * ln(Vin / V_r2),

where V_r1 and V_r2 are some reference voltages inherent in your circuit.

In general, log amps tend to be sensitive to temperature (both Vt and Iss are temperature sensitive), and it is easier to compensate for this in a multiplying or squaring circuit. I would figure out how to do your polynomial stuff using multiplier chips, and I'd take Phil's advise about how to do it. If, in general, a * x^2 - b is always less than either one, then I'd go with

Vout = (a * x^2 - b) * x^2.

Note, too, that for the same reason you can't get Vout = ln(Vin), you can't get Vout = Vin^2 -- you can only get Vout = Vin^2/V_r, with V_r being some reference voltage.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

Phil Hobbs expounded in news: snipped-for-privacy@electrooptical.net:

..

..

..

It doesn't sound like a very practical approach for my hobby project. Too much to go wrong for my humble engineering and building skills. I'll need to ponder some other approaches with greater chances of success.

Save the grins but I'm toying with analog ways to arbitrarily sculpt a tube-like response in solid-state components, without going digital. There I said it. ;-) I know this has all been done before- this is just for fun mostly.

By arbitrary, I meant by arbitrary analog circuit design. Implementing the equations just seemed so nice and clinical.

So it sounds like if someone were to implement a true ln(x) function in a "proper" analog computer, it would be quite an engineering task to implement it and its anti-log. Nuts. Not the answer I was hoping for.

It's no wonder that EE books just briefly mention the log /anti-log op amp circuits.

Thanks, Warren

Reply to
Warren

Tim Wescott expounded in news:bv-dnVeRrKTSAMjQnZ2dnUVZ snipped-for-privacy@web-ster.com:

My x ranges from (nearly) 0 to 3, maybe 4 volts. It doesn't really mater to me what units it is in, but in my case I planned on using:

x = Vin (volts)

in the positive realm only. I know the value of zero and negative are problems.

In my case, 0 < x In general, log amps tend to be sensitive to temperature

Agreed.

That might work for me (I need to think about it more). That'll likely mean more LM13700 chips on the next mouser order. ;-)

Vout = Vin^2/V_r isn't too much of a hardship, since I could multiply it all by V_r to cancel out the division.

Warren

Reply to
Warren

Art of Electronics (2nd ed.) has a nice log amp circiut. Also suggestions for compensation of the temperature changes. You can also buy log amps.

George H.

Reply to
George Herold

You've got a fundamental confusion, here.

If Vin is 3V, then ln(Vin) is ln(3) + ln(volt). What's the natural log of a volt? How do you add the natural log of a volt to a real number? You can't! When you're done, how do you put the sum of a real number and the natural log of a volt onto a wire? Can't be done!! Not at all!!!

Saying "take the logarithm of a voltage" makes no sense when taken literally. You can take the logarithm of a _ratio_ of voltages, but you can't take the logarithm of a voltage directly. And when you're done doing that on paper, you can't transfer the result into the real world without having some way of representing that logarithm of ratios -- so you have translate that logarithm into _some_ real quantity.

So all effective logarithm circuits work by the equation I gave: some reference voltage times the natural log of the ratio of the input voltage and some other reference voltage. Either you choose those reference voltages (even if you choose them all to be 1 volt), or someone else chooses them for you.

It's the same with the squaring operation. If Vin is 3V, then Vin^2 is

9 * volts^2. What's the physical manifestation of a volt-squared? How do you put it on a wire? Etc., etc.
--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

No, not at all--I didn't mean to discourage you, because it it isn't bad at all. In fact I'm designing a box right now that has a logarithmic predistorter in it, to linearize the response of a differential pair in a highly precise measurement gizmo. In that one, I have to put in all sorts of compensation for R_EE' and so on, but you don't need to worry about it--just pick a smallish collector current and the problems pretty well go away.

Start with a MAT14 and a quad op amp. Drive one section (say Q1/A1) just like your circuit, but using one section of a MAT14, diode connected (CB shorted is the anode, E is the cathode. Push a constant current of about 100 uA through it, by connecting the input resistor to some convenient quite reference voltage. That's your -V_BE reference.

Use another section, Q2/A2, wired almost almost the same, but driven by your input (suitably offset so that it centers on the reference voltage and never goes too close to 0). The outputs of the two sections now generate the Delta V_BE you need, with exactly the right temperature behaviour and good tracking.

Connect the emitters of the remaining two sections to the output of A2. With their bases at ground, their collector currents will be a replica of Q2's. However, instead you drive their bases with Delta V_BE (which makes the squared term) and 2*Delta V_BE (which makes the cube). Run the collectors into a the summing junctions of A3 and A4, and use pots for the feedback resistors so you can adjust the size of the nonlinear terms to suit you.

The output of the entire circuit will be sums and differences of Vin and the outputs of A3 and A4--that'll cost you another op amp and a few more resistors.

Altogether it's probably $12 worth of parts, and you'll have a great time fiddling with it.

I'm flaked out with a bad cold at the moment, or I'd draw up something. If I've been too telegraphic with the above description, let me know. You can see the sort of thing I'm talking about in National Semi's AN-30,

formatting link
They want you to ground the bases of everything to avoid base current error, but the MAT14 has a beta of 400, so you don't care very much, and diode connection makes everything nice and stable--you can ditch all the capacitors they use in AN-30.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058

email: hobbs (atsign) electrooptical (period) net
http://electrooptical.net
Reply to
Phil Hobbs

But, 'audio frequencies' implies AC, and all AC waveforms go through zero. Your ln(x) function goes to negative infinity every time that happens. When (x) is negative, it's worse.

No op amp slews fast enough, or to a low enough voltage, to accomplish this task, as it is stated.

You can square small signals with a Gilbert cell, though, and make the fourth power with two cascaded square-circuits.

Reply to
whit3rd

A log/antilog (one-quadrant) approach isn't too bad for modelling a single-ended tube amp--both have to have some fairly serious amount of bias in order to work. For modelling a push-pull amp, you'd need four quadrants, you're right.

It's a hobby project, so if the OP makes something that sounds interesting, he might branch out to a more general approach.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058

email: hobbs (atsign) electrooptical (period) net
http://electrooptical.net
Reply to
Phil Hobbs

If the OP is trying to model the mushy limiting of toooobs, TANH would work well, and is easier to implement.

If you have to LOG compensate an amplifier (re and bulk RE), you can do it simply :-) as in:

formatting link
...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |

      Remember: Once you go over the hill, you pick up speed
Reply to
Jim Thompson

formatting link

might be worth looking at. It certainly helped me when I had to tackle a similar problem.

-- Bill Sloman, Nijmegen

Reply to
Bill Sloman

a

t- Hide quoted text -

That's nice Phil, When you feel better I'd love to see a pic of your circuit. What I started to draw from your description was not 'crossed' as in the app. note. I'm confused (or beer riden on a Friday night)(or both).

Is a +3500ppm resistor a fine piece of metal?

George H.

Reply to
George Herold

Hide quoted text -

That's right in the range of common pure metals, e.g. nickel and copper. (Still trying to find someone to put down a micron of nickel on some polyimide.)

The good news is that you don't need to temperature compensate to do polynomials--the temperatures cancel out, so they just have to be the same. Nowadays the right way to do TC compensation of log amps in instruments is to measure the temperature of a spare transistor in the array and either (a) force it to be constant, ideally using a second transistor on-chip, or (b) twiddle a dpot to mimic the compensating RTD element.

The app note makes it look much more complicated than it is--I guess in

1969 they didn't have transistors with the beautiful beta linearity of a MAT14, so they had to ground the bases and put up with a huge amount of extra gain inside the FB loop as a result.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058

email: hobbs (atsign) electrooptical (period) net
http://electrooptical.net
Reply to
Phil Hobbs

Can he just add an offset, say 5 volts to his 0-3 volt input signal? You could add another pot to the offset and play with that too. A LOG effects box. (I first thought the offset was a gain adjust, but it'snot.)

George H.

Reply to
George Herold

ad

c
n

ll

ty

nt

o

e.

y
e
.

replica

ich

n

nd

re

.

know.

i's

und

a

in

.net-Hide quoted text -

I've been starring at tables of the elements. If you take one over the Temp. co. it sorta points to absoulte zero. (As I'm sure you know.)

How big? Can you get someone too sputter it in a bell jar? In grad school people were known to peel the chrome off of old car bumper's.

George H.

t- Hide quoted text -

Reply to
George Herold

George Herold expounded in news: snipped-for-privacy@k7g2000yqj.googlegro ups.com:

..

Mine is backordered.

Buying a log amp makes sense to me, if it comes close to what I need (assuming a decent price).

Warren

Reply to
Warren

Phil Hobbs expounded in news: snipped-for-privacy@electrooptical.net:

..

..

..

Thanks for that and the ref to the ref to AN-30 below. I'll have to study that to see if I can absorb everything that's going on there.

Where do you buy MAT14s? It seems that tran-arrays of any kind are hard to find today.

Thanks Phil. I'll study that info. It looks like fun.

Warren

Reply to
Warren

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.