[sci.electronics] Sigmoid transfe function

krishna@aecom.YU.EDU (Krishna Ambati) (08/23/88)

Concerning circuits that yield a tanh transfer function, I wonder
whether the following will work?

			     D1

			____|/|___
		       |    |\|   |
		    ---|          |---
		   |   |____|\|___|   |
		   |        |/|       |
		   |         D2       |
		   |                  |
		   |                  |
		   |         C        |
		   |--------| |-------|
		   |                  |
		   |         R        |
		   |-------/\/\-------|
		   |                  |
		   |                  |
		   |       |\         |
     V(in) .-------|-------|-\        |
			   |  \_______|_____. V(out)
			   |  /
		   |-------|+/
		   |       |/
		   |
		  GND

What is the transfer function of this circuit?

Krishna Ambati
krishna@aecom.uucp
ins_aajk@jhunix.uucp

bph@buengc.BU.EDU (Blair P. Houghton) (08/24/88)

In article <1982@aecom.YU.EDU> krishna@aecom.YU.EDU (Krishna Ambati) writes:
>
>Concerning circuits that yield a tanh transfer function, I wonder
>whether the following will work?
>
>			     D1
>
>			____|/|___
>		       |    |\|   |
>		    ---|          |---
>		   |   |____|\|___|   |
>		   |        |/|       |
>		   |         D2       |
>		   |                  |
>		   |                  |
>		   |         C        |
>		   |--------| |-------|
>		   |                  |
>		   |         R        |
>		   |-------/\/\-------|
>		   |                  |
>		   |                  |
>		   |       |\         |
>    V(in) .-------|-------|-\        |
>			   |  \_______|_____. V(out)
>			   |  /
>		   |-------|+/
>		   |       |/
>		   |
>		  GND
>
>What is the transfer function of this circuit?

It's not tanh(Vin); that's for sure.  I do want to thank you
for unrusting my op-amp design talents.  This was some fun!

First, put a significant resistance (call it Ri) in series with Vin, or
you'll get only a step at Vin crossing 0 where Vout goes from Vd to -Vd.
Vd is the threshold voltage of the diodes (assume ideal diodes
with forward resistance zero, reverse infinite; this assumption
doesn't change the result too much.)

Call the potential at the inverting input Vinv.  It is the op-amp's
duty to keep this voltage equal to the noninverting-input voltage,
which you have tied to ground, or suffer nonlinearity.

Now we have three cases:

1.  |Vout - Vinv| < Vd, which is to say |Vout| < Vd, since this is the
	linear region, and the op-amp may do its job proudly.

	We find

		Vout            R
		----  = - ------------- ;
		 Vin      Ri + s C R Ri

	which, for low frequency (s) is approximately
	
		Vout       R
		----  = - --- ; 
		 Vin       Ri
	
	and, it is a lowpass filter, so any frequency above 1/(RC) is
	significantly attenuated.  For the purpose of "sigmoidality"
	we worry about all frequencies, especially the lower
	ones.  But, neurons drive themselves and their peers.
	I won't worry here about what the lowpass characteristic
	does to neuromimetic activity.

2.  Vout - Vinv >= Vd;

	Now the resistance of D1 drops to zero.  R and C are well and
	truly shorted, and any current from the op-amp output can be
	fed back to the inverting input.  Most importantly, that
	amount of current will be fed back which is equal to the
	amount taken by Vin; i.e.,

		      Vinv - Vin    Vout - Vd - Vin
		I =   ---------- =  --------------- ;
			  Ri              Ri

	and the only truth about Vout is 

		Vout = Vd + I Ri + Vin = Vout

	This means that the op-amp sets Vout at its convenience.
	Its convenience is to set Vout to keep Vinv = Vnoninv = 0;
	hence

		Vout = Vd .

	Here is where things can get ugly if you include the series
	resistance of the diodes.  Practically, it only adds a little
	bit to the Vout vs Vin line, causing it to slope upward a bit,
	rather than being flat.  One other effect of reality is a
	slight rounding at the point where regions 1 and 2 meet.

3.  Vout - Vin <= Vd;

	See region 2 for the currents; since Vin and Vinv have both
	switched sign, I will have also.  (Betcha didn't know that
	about me :-)  The output volts are just

		Vout = -Vd .

The full effect is


			       | Vout
			       |
	xxxxxxxxxxxxxxxxxxxx   - Vd
			    x  |
			     x |
			      x|
        -----------------------x--------------------
			       |x		  Vin
			       | x
			       |  x
			   -Vd -   xxxxxxxxxxxxxxxxx
			       |

So, what you have just invented (not really :-( ) is a double-sided
clipping circuit that operates as a low-pass filter for small-signal
input.

With the slight rounding at the corners, this can be considered
a "sigmoid", but you have to emphasize the "-oid" heavily.

I think for the purposes of the Hopfield model it will work; just
feed this one's output through another inverting amp with gain
set so that Vin = Vd gives Vout = 1.

It's easier to leave out the diodes and capacitor and run the thing with
supply voltages of +/-1v. the op-amp will clip on its own.

				--Blair
				  "Even an Electrical Engineer
				   could do such a thing; I'm
				   sure of it..."

ankleand@athena.mit.edu (Andy Karanicolas) (08/27/88)

In article <1982@aecom.YU.EDU> krishna@aecom.YU.EDU (Krishna Ambati) writes:
>
>Concerning circuits that yield a tanh transfer function, I wonder
>whether the following will work?
>
>			     D1
>
>			____|/|___
>		       |    |\|   |
>		    ---|          |---
>		   |   |____|\|___|   |
>		   |        |/|       |
>		   |         D2       |
>		   |                  |
>		   |                  |
>		   |         C        |
>		   |--------| |-------|
>		   |                  |
>		   |         R        |
>		   |-------/\/\-------|
>		   |                  |
>		   |                  |
>		   |       |\         |
>    V(in) .-------|-------|-\        |
>			   |  \_______|_____. V(out)
>			   |  /
>		   |-------|+/
>		   |       |/
>		   |
>		  GND
>
>What is the transfer function of this circuit?
>
>Krishna Ambati
>krishna@aecom.uucp
>ins_aajk@jhunix.uucp

NOTE:  THE VIEWS EXPRESSED HERE ARE NOT NECESSARILY THOSE OF M.I.T.

First of all, for this cirucit to work, some kind of input impedance
is needed (unless a current source is used for the input), call it
rin.

Assume the op-amp and diodes are ideal.  Also, leave out the R-C
network for now.  For an ideal op-amp (in a stable connection) the (-)
and (+) inputs will be at the same voltage, namely 0 volts.  Now, sum
the currents into the (-) input:

-->  vin/rin + ix*(exp(vout/vth) - 1) - ix*(exp(-vout/vth) - 1) = 0

     (vth is the thermal voltage or kT/q)

-->  vin/rin + 2*ix*sinh(vout/vth) = 0

-->  vout = -vth*arcsinh[ vin/(2*ix*rin) ]

Now, this is not the most pleasant thing in the world to deal with.
However, this equation can be simplified when |vout/vth| >> 1.  

For the case where |vout/vth| >> 1:

-->  vin/rin + ix*exp(vout/vth) ~= 0, vout > 0
-->  vin/rin - ix*exp(-vout/vth) ~= 0, vout < 0

simplifying,

-->  vout = vth*log[ -vin/(ix*rin) ], vout > 0  (vin < 0)
-->  vout = -vth*log[ vin/(ix*rin) ], vout < 0  (vin > 0)

No doubt, this is not a tanh function.  It is more like a log|vin|
type of transfer function. Note that when vin is near 0,
the approximations for these equations do not work and the arcsinh
horror is needed.  

One problem with this circuit is that the output swing will be small
because the turn-voltage of most diodes is around 0.6V or so.  If much
more output voltage is demanded, the diode current, and hence the
op-amp output current, will become excessive.  One way to extend the
output voltage swing would be to include a series resistor with each
diode. However, this will result in the transfer function slope
increasing on the extremes.  Of course, an amplifier can be added to
magnify the output voltage.

The resistor in the R-C network is needed or the transfer function
slope, or gain, will become excessive when vin is near 0.  With the
proper choice of R, this circuit might yield a transfer function that
is similar to the tanh function.  The slope of the transfer function
near vin = 0 can be set by the ratio of r to rin.  The inclusion of
the capacitor forms something like a lead compensator, except that the
zero and pole will move around depending on the output voltage.  In
any case, predicting the dynamic behavior of this circuit is not too
easy since the diodes are non-linear elements.

Try it out and see what you get!

Andy Karanicolas
Microsystems Technology Laboratory
ankleand@caf.mit.edu