## Sigmoid Devices

### By Harvey Morehouse

**Contents:**

### Modified Half Sigmoid Device

**About
the writer**:
Harvey Morehouse is a contractor/consultant with many years of experience
using circuit analysis programs. His primary activities are in Reliability,
Safety, Testability and Circuit Analysis. He may be reached at harvey.annie@verizon.net.
Simple questions for which I know the answer are free. Complex questions,
especially where I am ignorant of the answers, are costly!!!

**Summary**:
A previous paper described a model useful in creating devices which
switch between two equal magnitude values of a different sign. Here
we will create a Sigmoid model that switches smoothly between two different
magnitude values.

**Sigmoid
function:**

This function arises in many dynamical systems because it is the solution to a first order differential equation:

dx / dt = k x - a x2

It is expressed in the form:

f(x) = 1/(1 + e-ax)

A graph of this function is shown in Figure 1 following:

Figure 1

Sigmoid Function

Figure 1 was taken from reference 1. Reference 2 provides a neat little graphic that shows the effects of modifying the parameters.

**Modified
Half Sigmoid Function Model:**

Let us make a few assumptions as a basis for the model. The first is that the input signal will range in value from at least MinV as a minimum to at least MaxV as a maximum. At an input equal in magnitude to MinV the output should be minimum and at an input equal in magnitude to MaxV the output should be maximum. The modified Signoid curve of the previous paper was:

S(a,x.MaxVAL, MinVAL, MaxV, MinV) = MinVAL +2*MaxVAL*(1/(1+e-(a*(x-Vmid)))-0.5)where a = 12/(MaxV)

The previous paper showed how one could use this model to vary between a very small to a very large value, however, the curve was effectively offset such that one input transition effectively started or ended at the curve midpoint, and the transitions did not show gradual transitions to and from that point. The manner by which we will transform the input is by the formula:

xt = MinV + 2*x/MaxV

Assuming that the MinV equals -1 (and MaxV equals 1), we add to MinV twice the proportionate amount of the value represented by the quotient of the unmodified input x and MaxV. Again, we assumed the input will range from zero to some positive value equal to or greater than one.

This will be used to produce an output that will vary in a Sigmoid type fashion. With these transformed values, which will range from -1 to 1 (or greater) we can produce a curve that will vary smoothly from a minimum to a maximum value Two equations will be solved, of the form:

and

A typical graph of these curves is shown in the following Figure 2:

Figure 2

Modified Half Sigmoid Spreadsheet Graph

The Slh function curve is in blue, while the Shl curve is in violet. The two curves arise from the fact that there is odd symmetry of the function - that is, f(x) = -f(-x).

A SPICE model of a circuit which will implement this relation is shown in Figure 3 following:

Figure 3

Modified Sigmoid Test Circuit

The equations programmed into the B1 and B2 generators are shown above and below those respective elements. The test circuitry consists of the elements below the dashed line, as well as V1 and V3 sources with the ground. The V3 source is a zero volt generator, used just to maintain the N2 node identity.

It is intended later that the values of 'a', MaxVAL and MinVAL will be parameters passed to the subcircuit.

A netlist of the circuit is as follows:

ModifiedHalf Sigmoid curve.cpr

*

*Created by Harvey Morehouse

*

*B2SPICE VER 4.X AND 5.X compatible***** main circuit

R1 N1 N2 10Meg

Va a 0 2.800000000000e+001

VMin MinVAL 0 5.000000000000e-003

VMax MaxVAL 0 1.000000000000e+007

R3 N2 N6 10Meg

R4 a 0 1K

R5 MinVAL 0 1K

R6 MaxVAL 0 1K

R2 N5 N6 1Meg

B2 N5 N6 v =v(MinVAL)+ v(MaxVAL)/(1+exp(v(a)*(-1+2*v(N1,N2))))

B1 N3 N4 v =v(MinVAL)+ v(MaxVAL)/(1+exp(- (v(a)*(-1+2*v(N1,N2)))))

R7 N3 N4 1Meg

R8 N2 N4 10Meg

V1 N1 0 PULSE( 0.000000000000e+000 5.000000000000e+000 0.000000000000e+000 5.000000000000e-005 5.000000000000e-005 5.000000000000e-004 1.000000000000e-003)

V3 0 N2 0.000000000000e+000

.TRAN 5E-8 0.002 0 1E-7 uic.OPTIONS method = trap

.end

The model itself is fairly straightforward, and conforms to the previously developed equations. A graph of the output from the circuit is shown in the following Figure 4.

Figure 4

Modified Sigmoid Test Circuit Graph 1

The expanded trace shows a portion of the input leading edge in blue. The red trace is the Slh curve output, whereas the green curve is the Shl output. It is not apparent from the graph, however, the Slh output value is at 5.007mV until the start of the input voltage rise, and the Shl output is at 10M. After the input reaches about 420mV the outputs start to transition and are essentially complete by the time the input is at about 620 mV. The curves are well behaved, and switching is essentially completed in about 2µ sec.

**Conclusions:**

A Modified Half Sigmoid circuit model has been created which can be useful in creating devices or functions that smoothly switch between different magnitude values. It is assumed that the control input will switch between zero and some positive level. It is assumed that switching during the input rise and fall times is desired, but there is no specific need to tailor this rise time, although through the use of the 'a' parameter and the input rise time some crude control may be achieved. This device should be added to the standard library as a building block.

Later articles are planned that will show how this model and the Modified Full Sigmoid circuit model can be used to create smooth switches, square loop core models, voltage limiters and simple relays, time permitting.

**References:**

1 http://astronomy.swin.edu.au/~pbourke/other/sigmoid/

2 http://www.ii.metu.edu.tr/~ion526/demo/java/NNOC/Sigmoid.html

### Modified Full Sigmoid Device

**Summary**:
A sigmoid curve can be useful in SPICE modeling of devices which switch
from one state to another. It provides a smooth transition between extremities.
It is also continuously differentiable, and somewhat so in a SPICE numerical
world, unlike some piecewise linear models.

**Sigmoid
function:**

This function arises in many dynamical systems because it is the solution to a first order differential equation

dx / dt = k x - a x2

It is expressed in the form:

f(x) = 1/(1 + e-ax)

A graph of this function is shown in Figure 1 following:

Figure 1

Sigmoid Function

Figure
1 was taken from reference 1. Reference 2 provides a neat little graphics
which shows the effects of modifying the parameters.

To utilize this function in models, an inductor, there are three little
problems. The first is that the midpoint of the curve, where x = 0,
is a value of 0.5. Clearly this requires that the input or the output
must be offset. The second is the scaling of the input for, as the graph
in figure 1 reveals for the unmodified curve, the exponent value of
'-ax' must be greater in magnitude than about 12 to fully reach the
extreme values of plus and minus 0.5.

**Modified
Sigmoid Function Model:**

Let us make a few assumptions as a basis for the model. The first is that the input signal will range in value from at least MinV as a minimum to at least MaxV as a maximum. At an input equal in magnitude to MinV the output should be minimum and at an input equal in magnitude to MaxV the output should be maximum. Now the midpoint of the curve will be when the input is at the value Vmid = (MaxV - MinV)/2. To achieve this, the original Sigmoid curve will be slightly modified to become:

S(a,x.MaxVAL, MinVAL, MaxV,MinV) = MinVAL +2*MaxVAL*(1/(1+e-(a*(x-Vmid)))-0.5)

where a = 12/(MaxV)

It is convenient to construct a small spreadsheet to explore the above equation to ensure that the math is correct, as shown in Figure 2 following:

Figure 2

Modified Sigmoid Datasheet Check

Using a spreadsheet similar to that of Figure 2, one can see that the equation does, using the values shown, produce a value of -1e7 when the input 'x' is negative 1, and value of +1e7 when 'x' equals positive 1. The average slope of the curve is about equal to (Max - Min)/(Vmax - Vmin) over the input range of 'x' from -1 to +1.

A SPICE model of a circuit which will implement this relation is shown in Figure 3 following:

Figure 3

Modified Sigmoid Test Circuit

A netlist of the circuit is as follows:

Modified Sigmoid curve.cpr*

* Created by Harvey Morehouse

*

* B2SPICE format

****** main circuit

R1 N1 N2 10Meg

Vmax MaxV 0 5.000000000000e+000

Vmin MinV 0 0.000000000000e+000

Va a 0 1.200000000000e+001

VMin1 MinVAL 0 5.000000000000e-003

VMax1 MaxVAL 0 1.000000000000e+007

R3 MinV 0 1K

R4 a 0 1K

R5 MinVAL 0 1K

R6 MaxVAL 0 1K

R2 MaxV 0 1K

B1 N3 0 v =v(MinVAL)+ 2*v(MaxVAL)*(1/(1+exp(- (v(a)/v(maxV))*(v(N1,N2) -((v(maxV) +v(MinV))/2)))) -.5)

R7 N3 0 1Meg

R8 N2 0 10Meg

V1 N1 N2 PULSE( 0.000000000000e+000 5.000000000000e+000 0.000000000000e+000 5.000000000000e-005 5.000000000000e-005 5.000000000000e-004 1.000000000000e-003)

.TRAN 5E-8 0.002 0 5E-7 uic.OPTIONS method = trap

.end

The model itself is fairly straightforward, and conforms to the previously developed equations. In the circuit diagram of Figure 3, everything below the dashed line, and generator v1 are part of a test setup. In the final model it is intended that the outputs MaxV, MinV, MaxVAL, MinVAL and 'a' will be parameters passed to a parameterized subcircuit of the device.

A graph of the output from the circuit is shown in the following Figure 4.

Figure 4

Modified Sigmoid Test Circuit Graph 1

The output switches nicely between +/- 10 Megs. Now the values of MaxV and MinV were chosen to be +1 and -1 respectively.

Now it is easy to get confused using this model. Suppose one wished to implement a function which produced an output varying from -N to +N. And suppose these values were to be reached when x was -5 to +5. One could just plug the values into the equation and everything works nicely. In that case, the 'MinV' value would be set equal to the negative of the 'MaxV'. Note that the actual voltage excursion limits could be outside of these limits.

Suppose however one wished to model a device which varied from a very small value at x=0, to a very large value at x=1, from .005 to 1e7 ohms. Clearly these values present no problems. The problem however is with the input. Assume the input went from zero to 1 volts positive (or more). The switch is to toggle essentially fully at 1 volt. What values are to be used for Vmax and Vmin? If one uses values of +1 and 0 respectively, it will NOT work. The circuit is designed to produce a +/- output which is bilateral. What you would get is an output which varied from about -1e7 to +1e7 for inputs of 0 and 1 for x.

What we need to do is, in effect, to offset the input value of 'x'. What we can do is to set maxV and minV to complementary values. Suppose we used +1 and -1, with an input from zero to one volts? In that case we would get the results as shown in the graph of Figure 5 following:

Figure 5

Modified Sigmoid Test Circuit Graph 2

Well, we are close, but this is clearly not a full Sigmoid type curve output, but only a half Sigmoid curve output. The transitions about zero are not smooth. There is a way to do this, however it requires modification to the circuit. This will be covered in a subsequent paper where a Modified Half Sigmoid circuit model will be presented.

**Conclusions:**

A Modified Full Sigmoid circuit model has been created which can be useful in creating devices or functions which smoothly switch between equal magnitude values of opposite sign. This device should be added to the standard library as a building block.

A later article will discuss creating a Modified Half Sigmoid circuit that will smoothly switch between unequal extremities of value.

**References:**

1 http://astronomy.swin.edu.au/~pbourke/other/sigmoid/

2 http://www.ii.metu.edu.tr/~ion526/demo/java/NNOC/Sigmoid.html

### Smooth Transition Sigmoid Switch

**Summary**: Using a Sigmoid function
a smooth transition model is developed. This largely eliminates large
discontinuities resulting from the use of generic switches in models
that cause convergence problems.

**Sigmoid
function:**

This function arises in many dynamical systems because it is the solution to a first order differential equation

dx / dt = k x - a x2

It is expressed in the form:

f(x) = 1/(1 + e-ax)

A graph of this function is shown in Figure 1 following:

Figure 1

Sigmoid Function

Figure 1 was taken from reference 1. Reference 2 provides a neat little graphics which shows the effects of modifying the parameters. Of particular note is that, if the sign of the exponent is changed, the curve transitions from unity to zero with increasing x.

To utilize this function to model a switch, there are three little problems. The first is that the midpoint of the curve, where x = 0, results in a value of 0.5. Clearly this required that the input control voltage, typically from zero to a positive value, must be offset. The second is the scaling of the input itself. To obtain a greater slope in the mid region the magnitude of the input voltage must be adjusted.

Figure 2 following shows a first-pass model of the NO switch model with a test circuit.

Figure 2

Sigmoid NO test circuit #1

In Figure 2, the switch is represented by the B3 current generator, with a test circuit comprised of v1 generator in series with R1 providing the stimulus. The controls for the switch resistance consist of nonlinear voltage sources B1 and B2, with their associated resistors R2 and R4, with the switch control voltage being the level across resistor R3.

Device A1 and R1 are used for test purposes. A1 is a differentiator, which is used to investigate the variations in switch resistance.

The controlling equations for the B1 through B3 generators are provided in the text near each respective generator. Normally we would expect the control voltage (v2) to be referenced to ground.

Here it is assumed for the moment that the input switch controlling voltage varies from zero to one volt. The B1 controlling equation is:

v = 1/(1 + exp(-20*(v(5,0)-.5))

The v(5,0) - .5 term adjusts the input level to be centered about zero, whereas the -20 constant factor 'a' scales the input to vary from -10 to +10 volts. This implements the sigmoid function.

The B2 generator controlling voltage is:

v = v(2,0)/(v(3,0)*1e7)

What this does is to provide a voltage equal to that across the equivalent switch by the product of the sigmoid function and the open switch resistance value. This voltage is used to program current source B3 with the appropriate level of current dependent on the switch state.

The netlist for this circuit is:

sigmoid1.cpr

***** main circuit

R1 1 2 10K

R2 3 0 1K

R3 5 0 10Meg

R4 7 0 1K

B1 3 0 v = 1/(1 +exp(-20*(v(5,0)-.5)))

B2 7 0 v = v(2,0)/(v(3,0)*1e7)

V1 1 8 PULSE( 0.000000000000e+000 1.000000000000e+001 1.000000000000e-006 1.000000000000e-006 1.000000000000e+001 2.000000000000e+001)

V2 5 0 PULSE( 0.000000000000e+000 1.000000000000e+000 0.000000000000e+000 1.000000000000e-003 1.000000000000e-003 2.000000000000e-003 5.000000000000e-003)

B3 2 8 i = v(7,0)

R5 8 0 10MegK

A1 2 9 differentiator

R6 9 0 1K.model differentiator d_dt gain = 1.0 out_lower_limit = -1t out_upper_limit = 1t limit_range = 1.0p out_offset = 0.0

.TRAN 1E-7 0.01 0 1E-6 uic .OPTIONS method = gear

.end

A graph of the circuit output is shown in Figure 3 following:

Figure 3

Sigmoid NO test circuit #1, graph

In Figure 2 we can see the green sigmoid curve. The red curve shows
that when the switch is open, we see 9.99 volts across it, and when
closed, distressingly, 434.234 mV. We will fix that shortly. The switch
control has a 1mS rise and fall time, and it would be interesting
to see what occurs when these values are reduced. Using this value,
nothing appreciably changes, save that the differential curve in purple
has larger bumps, and the sigmoid curve looks more and more like a
square wave. The good thing is creating the differential of the switch
voltage does not crash the system.

Now we could fool with the circuit more, and indeed it is recommended that this be done. But we will now modify the test circuit to try to eliminate the large (relative) value of switch 'ON' resistance and to be able to set it to a desired value. Refer to Figure 4 following:

Figure 4

Sigmoid test circuit #2

The only major differences between this circuit and that of Figure 2 are that we added a generator B4 and R7 combination to create a zero volt level of resistance which is subtracted from the value computed by generator B1 in device B2, and then we added the desired on resistance, .010 ohms in this case, back in. Now the pulse rise and fall times were also changed to equal to 0.001 uS.

The graph of the output becomes as shown in Figure 5 following:

Figure 5

Sigmoid (NC) test circuit #2 graph #1

Here we separated the plots, but they behave very nicely in any event. The switch voltage varies from 999.001mV to 0.999 uV, and the resistance from 9.999Megs to 10m ohms. A little math will show the values are as expected.

Now, we have the basis for a NC switch model. To make this into a NO model, all we need to do is to change the sign of x, either at the input or in the model. Let us operate on the model. Voila!! Changing the -20 factor into a +20 factor in the B1 generator, we get the following Figure 6, for a NO switch.

Figure 6

Sigmoid (N0) test circuit #2 graph #1

Here we see that the operation of the switch has been modified to be closed when the switch control voltage is high, and it opens when the switch control voltage is low.

Some slight changes are required to make this/these models into useful parts. What is needed is to pass the maximum and minimum control voltages, the maximum and minimum resistances of the switch, and the scaling factor to the switch for maximum versatility. The STSNCT3 device to be turned into a parameterized subcircuit is shown in Figure 7 following:

Figure 7

STSNCT3 Device Model

It is expected that the folks at B2SPICE will add the STSNOT3 and STSNCT3 parts to the library in the near future.

**Conclusions:**

A smooth transition NO and NC switch model has been created using the Sigmoid function. Use of this device should eliminate some of the difficulties in using abrupt transition switches in many models. The methodology used in this article should also show persons how they can adapt other mathematical models and functions for use with SPICE.

**References:**

1
http://astronomy.swin.edu.au/~pbourke/other/sigmoid/

2 http://www.ii.metu.edu.tr/~ion526/demo/java/NNOC/Sigmoid.html