%pip install ipympl==0.9.3
Requirement already satisfied: ipympl==0.9.3 in /usr/local/lib/python3.14/site-packages (0.9.3)
Requirement already satisfied: ipython<9 in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (8.39.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (2.5.5)
Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (0.2.0)
Requirement already satisfied: pillow in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (13.0.0)
Requirement already satisfied: traitlets<6 in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (5.16.1)
Requirement already satisfied: ipywidgets<9,>=7.6.0 in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (8.1.9)
Requirement already satisfied: matplotlib<4,>=3.4.0 in /usr/local/lib/python3.14/site-packages (from ipympl==0.9.3) (3.11.2)
Requirement already satisfied: decorator in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (5.3.1)
Requirement already satisfied: jedi>=0.16 in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (0.20.1)
Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (0.2.2)
Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (4.9.0)
Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (3.0.53)
Requirement already satisfied: pygments>=2.4.0 in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (2.21.0)
Requirement already satisfied: stack_data in /usr/local/lib/python3.14/site-packages (from ipython<9->ipympl==0.9.3) (0.6.3)
Requirement already satisfied: comm>=0.1.3 in /usr/local/lib/python3.14/site-packages (from ipywidgets<9,>=7.6.0->ipympl==0.9.3) (0.2.3)
Requirement already satisfied: widgetsnbextension~=4.0.16 in /usr/local/lib/python3.14/site-packages (from ipywidgets<9,>=7.6.0->ipympl==0.9.3) (4.0.16)
Requirement already satisfied: jupyterlab_widgets~=3.0.17 in /usr/local/lib/python3.14/site-packages (from ipywidgets<9,>=7.6.0->ipympl==0.9.3) (3.0.17)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (1.4.0)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (0.12.1)
Requirement already satisfied: fonttools>=4.28.2 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (4.68.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (1.5.1)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (26.3)
Requirement already satisfied: pyparsing>=3 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (3.3.3)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.14/site-packages (from matplotlib<4,>=3.4.0->ipympl==0.9.3) (4.0.0)
Requirement already satisfied: wcwidth>=0.1.4 in /usr/local/lib/python3.14/site-packages (from prompt_toolkit<3.1.0,>=3.0.41->ipython<9->ipympl==0.9.3) (0.9.4)
Requirement already satisfied: parso<0.9.0,>=0.8.7 in /usr/local/lib/python3.14/site-packages (from jedi>=0.16->ipython<9->ipympl==0.9.3) (0.8.7)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.14/site-packages (from pexpect>4.3->ipython<9->ipympl==0.9.3) (0.7.0)
Requirement already satisfied: tzdata in /usr/local/lib/python3.14/site-packages (from python-dateutil>=2.7->matplotlib<4,>=3.4.0->ipympl==0.9.3) (2026.6)
Requirement already satisfied: executing>=1.2.0 in /usr/local/lib/python3.14/site-packages (from stack_data->ipython<9->ipympl==0.9.3) (2.3.0)
Requirement already satisfied: asttokens>=2.1.0 in /usr/local/lib/python3.14/site-packages (from stack_data->ipython<9->ipympl==0.9.3) (3.0.2)
Requirement already satisfied: pure-eval in /usr/local/lib/python3.14/site-packages (from stack_data->ipython<9->ipympl==0.9.3) (0.2.4)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

[notice] A new release of pip is available: 26.2.2 -> 26.3
[notice] To update, run: pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.
import matplotlib
if not hasattr(matplotlib.RcParams, "_get"):
    matplotlib.RcParams._get = dict.get

7. Operational Amplifiers#

In this chapter we will have a look at the “Operational Amplifier” or, in short, “OPAMP”. OPAMPs are very versatile building blocks and can be used to implement various functions in electronic systems. They can be used as amplifiers, filters, integrators and many other applications, just by the addition of a few (passive) components. In order to understand how to use an OPAMP we need to look into electronic feedback principles first.

7.1. (Physics of) Feedback Systems#

Feedback in electronic systems is used in two ways, negative feedback and positive feedback (feedforward). Negative feedback is used more often. Negative feedback is used to stabilize or to control a system. In everyday life we use (unconsciously) a lot of negative feedback systems, even our own body consists of a large number of combined negative feedback systems! To make it clearer we can think of the following example: a heating system. In our house we have a heating system which can be used to maintain a comfortable temperature. In this heating system we have a few key elements:

  • heaters

  • thermostat, which consists of a control and a sensor

  • the room itself

When the room is cold, and we increase the control of the thermostat, it will sense that the temperature in the room is too low. It will send a signal to the heating system, which will switch on and start to generate heat. The room (heat-capacitance) will start to heat up. When the desired temperature of the room is reached, the thermostat sends a signal to the heaters, so they will switch off. The room will slowly cool down, till the thermostat “decides” that it is time to switch on the heaters again. By this the temperature in the room will remain (sort of) constant. Comparing this to a normal wood-burning stove, this will continue to produce heat, regardless of the temperature in the room. The wood stove has no temperature regulation at all.

Based on the description above we can identify a few key elements in the system:

  • a control input (setting the wanted value) (knob on the thermostat)

  • a comparing element, to check if the control input is higher or lower than the value we want to control (electronics inside the thermostat)

  • a measurement input to measure the value of the parameter we want to control (temperature sensor)

  • an actuator, a system to change the parameter we want to control (heaters)

The example and system description above are for a heating system, with the operational amplifier we will be controlling electrical signals. A block diagram of such a system is shown in Fig. 7.1.

../_images/feedback_loop2.svg

Fig. 7.1 Generic diagram of a system with negative feedback.#

In this system we see that there is an input voltage at “IN+”. This input is connected to a subtraction point (actually it is an adder, but as the other signal is inverted, it results in a subtractor). The output of this subtractor is connected to an amplifier, the output of this amplifier is connected to the output. The output is sampled with a passive network (in block β). This signal is fed to the inverting input of the adder (subtracted). This closes the feedback loop.

In order to further understand the functioning of this system, we will derive a transfer function for this system. As this is a nice linear system, we can derive the transfer step-by-step. The output voltage is the amplified voltage coming from the subtraction point, this voltage is \(U_{in+} - U_{in-}\). The voltage \(U_{in-}\) is the output voltage multiplied by the transfer of block β.

This gives:

(7.1)#\[ U_{out} = A_{ol} \cdot (U_{in+} - U_{in-}) \]

With:

(7.2)#\[ U_{in-} = \beta \cdot U_{out} \]

The total transfer is thus:

(7.3)#\[ U_{out} = A_{ol} \cdot (U_{in+} - (\beta \cdot U_{out})) = A_{ol} \cdot U_{in+} - A_{ol} * \beta \cdot U_{out} \]
(7.4)#\[ U_{out} (1 + A_{ol} \cdot \beta) = A_{ol} \cdot U_{in+} \]
(7.5)#\[ \frac{U_{out}}{U_{in+}} = \frac{A_{ol}}{1 + A_{ol} \cdot \beta} \]

Now we assume that the gain of the amplifier is very high, in the order of 100.000….1.000.000 times and that the block β contains passive components, thus β is between 0 to 1.

The transfer will then become:

(7.6)#\[ \frac{U_{out}}{ U_{in+}} ≈ \frac{1}{\beta} \]

Here we can see that the transfer of this system is determined by the passive feedback network which determines the factor \(\beta\). This is true, as long as the gain \(A_{ol}\) is very high, however this gain does not have to be very accurate. The feedback network \(\beta\) is determined by passive components, which generally have good accuracy.

7.1.1. OPAMP#

How does this relate to the OPAMP? The OPAMP is a complete circuit built in a chip, an integrated circuit. The circuit consists of a subtractor and high-gain amplifier (\(A_{ol}\)). A schematic of the amplifier is shown in Fig. 7.2.

../_images/OPAMP_internal.svg

Fig. 7.2 Schematic internal diagram of an OPAMP.#

In the diagram in Fig. 7.2, we see the two inputs, the non-inverting input (\(U_{in+}\)) and the inverting input (\(U_{in-}\)). The amplifier is shown as a controlled voltage source. Between the inputs we see an input impedance, which is in general very high. The output of the OPAMP has a source impedance, Zout, which is in general negligible. When drawing circuits, we generally use the symbol shown in Fig. 7.3 and Fig. 7.4, thus without the internal components.

../_images/OPAMP_symbol.svg

Fig. 7.3 Schematic symbol of an OPAMP.#

../_images/OPAMP_symbol_DIP.svg

Fig. 7.4 Schematic symbol of an OPAMP.#

In Fig. 7.3 and Fig. 7.4 we see the schematic diagram of the OPAMP. We see the power supply connections, +\(U_s\) and -\(U_s\), as well. The OPAMP is a complete circuit, therefore it needs power. Note that the power supply connections are not always shown in the symbol, sometimes they are not drawn, or drawn somewhere else in the schematics: don’t forget to them when you design a circuit yourself!

7.2. Golden (Electronic) Rules - the Zero Condition#

When analyzing OPAMP circuits, we use a few assumptions:

  1. There is no voltage difference between the inverting and the non-inverting input.

  2. There is no current (zero current) flowing into the inputs of the OPAMP.

  3. The output impedance of the OPAMP is zero ohms (behaves like a voltage source)

In order to put these rules in some perspective, some background is needed.

The first one: There is no voltage difference between the inverting and non-inverting input. In ideal op-amp analysis, we assume that this voltage difference is zero. This statement is as true as it is faulty. We have seen that the gain (\(A_{ol}\)) of an OPAMP is very big. The output voltage range of an OPAMP is between -15V and +15V (depends on the power supply voltage). In order to have a voltage output of, say +3V, we need a voltage on the input of the amplifier block of +3 / 100.000 = 30 \(\mu\)V. This voltage difference originating from the subtractor (difference in voltage between the inverting and non-inverting input) and is so small that it is hard to measure. In most circuit analyses, it can therefore be neglected. For this reason, we say that the voltage difference is zero. Besides this, the gain of 100.000 times is conservative, very often the gain is higher, giving an even smaller difference.

The second one: There is zero current flowing into the inputs of the OPAMP. When checking the specifications of an OPAMP in the datasheet we see that the current flowing into the inputs of an OPAMP is usually in the order of magnitude of pA (depends on the type of OPAMP). This current is very often so small compared to the other currents in the circuit that it can be neglected. For example, when other currents are in the µA or mA range, a pA input current has virtually no effect on the result. Furthermore, think about the input as a resistance: \(R = \frac{U_{in}}{I_{in}} \)= “few volts” / “pA” this will give a resistance in the order of hundreds of Giga-\(\Omega\)’s!

The last one: The output of an OPAMP behaves as a voltage source, has zero-ohm output impedance. This is the ideal model used in circuit analysis. The internal circuit of an OPAMP is constructed in such a way that the output has indeed very low impedance, although not perfect. Nevertheless, the output impedance of the OPAMP is further improved by the fact that the output voltage source is within the feedback loop. When the output voltage is too low, due to an external load, the feedback system will compensate for this and increase the output voltage to overcome the losses.

7.3. OPAMP Circuits in Practice (resistances in the Feedback)#

All this theory might seem a bit complicated. Furthermore, how to apply this in practice? Let’s have a look at some practical circuits. Things will become clearer then. In this chapter we will have a look at some basic topologies and other useful circuits.

7.3.1. Non-inverting Amplifier#

The first circuit we will have a look at, is the non-inverting amplifier. Non-inverting means that the amplified output voltage signal has the same polarity as the input signal. For this, the term “phase” is used, the input signal and output signal are in phase. This is in contrast with the inverting amplifier, as addressed later in this chapter, where the input and output voltage have opposite polarities, thus they are in counter-phase.

The non-inverting amplifier nicely follows the feedback scheme presented in the beginning of this chapter. It has an input (non-inverting input of the OPAMP), it has a passive feedback network connected to the output, and the output of this network is connected to the inverting input of the OPAMP. Now, look at the schematic diagram in Fig. 7.5.

../_images/NonInvAmpCircuit.svg

Fig. 7.5 Non-inverting amplifier with an OPAMP.#

The resistors \(R_f\) and \(R_i\) are forming a passive network. The two resistors will form a passive voltage divider, which will divide the output voltage \(U_{out}\). The divided voltage is sensed by the inverting input of the OPAMP. As no current flows into the OPAMP (zero condition!) the voltage divider is not influenced by the OPAMP’s input. From the feedback theory we learned that \(\beta\) should be ≤1. This is true for a voltage divider.

Now, what will be the gain of this circuit? The input signal is connected to the non-inverting input. Nothing else is connected to this pin, thus the voltage here will follow the input signal voltage. The first zero-condition states that both inputs (inverting and non-inverting) will have the same potential (no voltage difference). Thus, the potential of \(R_i\) will be equal to the input voltage. Ohm’s Law tells us that there will be a current through \(R_i\).

(7.7)#\[ I_{R_i} = \frac{U_{in-}}{R_i} = \frac{U_{in}}{R_i} \]

As this current cannot come from the input of the amplifier (second zero-condition, no current flows into the inputs of the OPAMP) all the current necessary for Ri has to be supplied through Rf. The voltage drop over Rf will be:

(7.8)#\[ U_{R_f} = I_{R_i} \cdot R_f \]

In order to have this voltage drop over \(R_f\), the output voltage needs to be:

(7.9)#\[ U_{out} = U_{R_f} + U_{R_i} = U_{R_f} + U_{in} \]

Combining equations (7.7), (7.8) and (7.9) gives:

(7.10)#\[ U_{out} = I_{R_i} \cdot R_f + U_{in} = \frac{U_{in}}{R_i} \cdot R_f + U_{in} = (\frac{R_f}{R_i} + 1) \cdot U_{in} \]

The transfer of the circuit will be:

(7.11)#\[ \frac{U_{out} }{ U_{in}} = \frac{R_f}{R_i} + 1 \]

The gain of this circuit will be a positive number, and will always be above 1. This means that the circuit will amplify its input signal and that the input and output voltage will be in phase.

Now assume that resistor \(R_f\) is 10 k\(\Omega\) and resistor \(R_i\) is 1 k\(\Omega\), then we can calculate the gain:

\[ G = \frac{U_{out}}{ U_{in}} = \frac{10 k\Omega }{ 1 k\Omega } + 1 = 10 + 1 = 11 \]

The output voltage will thus be the input voltage amplified by 11 times. The signals would look like the ones in Fig. 7.6.

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# Time axis
x = np.linspace(0, 6 * np.pi, 1000)   # about 6 periods

# Input and output signals (non-inverting amplifier: same phase, larger amplitude)
Uin = np.sin(x)
gain = 11.0
Uout = gain * np.sin(x)

# =======================
#       Plotting
# =======================

fig, ax = plt.subplots(figsize=(12, 6))

ax.plot(x, Uin, '--', color='blue', linewidth=2, label='Input Voltage')
ax.plot(x, Uout, color='red', linewidth=2, label='Output Voltage')

ax.set_xlim(x[0], x[-1]+ 1.5)
# ax.set_ylim(-gain, gain)

# Remove normal axis spines and ticks
for spine in ['top', 'right', 'bottom', 'left']:
    ax.spines[spine].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])

# Draw x (time) axis as an arrow
ax.annotate('', xy=(x[-1] + 0.5, 0), xytext=(x[0], 0),arrowprops=dict(arrowstyle='->', linewidth=1, color='black'))

# Draw y (voltage) axis as an arrow
ax.annotate('', xy=(x[0], gain), xytext=(x[0], -gain), arrowprops=dict(arrowstyle='->', linewidth=1, color='black'))

# Axis labels
ax.text(x[-1] + 0.6, 0, 'Time', va='center', fontsize=14)
ax.text(x[0], gain + 0.1, 'Voltage', ha='center', fontsize=14)

ax.legend(loc='upper right', frameon=False)

plt.tight_layout()
plt.show()
../_images/bc9e11865dac85fbaaed5296474fa4c44cda1a1243bac92a6d1823b2d43819dd.png

Fig. 7.6 Input signal and output signal of a non-inverting voltage amplifier.#

Here we can see that the input voltage and the output voltage are in phase, they have the same polarity (and shape), only the amplitude is different.

When a signal needs to be amplified with a different amplification factor, it will suffice to change the ratio of the resistors \(R_f\) and \(R_i\). In practice gains can be realized from 1 to 1000 times with a single OPAMP-amplifier.

A word about the resistor values: While in theory only the ratio of \(R_f\) and \(R_i\) is important to determine the gain, there are other things to consider in practice. Assume we would make the 11 times amplifier with a resistor \(R_f\) of 10 \(\Omega\) and \(R_i\) of 1 \(\Omega\) (compared to the 10 k\(\Omega\) and 1 k\(\Omega\) of the previous example). What would happen then? Based on formula 10, the gain would still be 11x. However, when the output voltage would be, say, 10 Volts, the OPAMP needs to supply a current of almost 1 Ampere through the feedback circuit. In practice an OPAMP cannot supply such a big current, furthermore, the circuit would not be very energy efficient. About 10 Watts of power would be dissipated in the feedback circuit (this will drain a battery pretty quickly!). Therefore we will usually see resistors in the range of k\(\Omega\)s to hundreds of k\(\Omega\)s in the feedback circuit. This is perfectly fine, as the ratio is what matters in the end.

7.3.2. Buffer or Voltage-follower#

While in practice the ratio of the resistors Ri and Rf is limited, they could be any ratio in theory. There is one theoretical situation which will yield a useful circuit in practice. This occurs when resistor Ri will infinite (∞). The gain of the circuit will then be:

(7.12)#\[ G = \frac{U_{out}}{ U_{in}} = \frac{R_f}{\infty} + 1 = 1 \]

The gain of the circuit will thus be 1x. By the way, an infinite resistance, means that it has been taken out of the circuit, so \(R_i\) is not present in the circuit anymore. Furthermore, resistor \(R_f\) could have any value in theory, so it could just as well be zero \(\Omega\) (a piece of wire). When implementing this, the circuit would look like the one shown in Fig. 7.7.

../_images/buffer.svg

Fig. 7.7 One time amplifier with an OPAMP.#

Now what is the advantage of such a unity-gain amplifier? Can’t we just replace it with a short piece of wire? Gain-wise the answer would be “Yes”. However, when we look at the impedances in the circuit we can get to a different conclusion.

The input impedance at \(U_{in}\) is infinite (no current flows into the OPAMP). The output of the OPAMP behaves as a voltage source (zero output impedance). Thus, we made a circuit which will not load the source, but is capable of driving a more low-ohmic load.

This type of circuit is called a buffer or voltage follower. It will find its application in situations where a source with a very high output impedance has to drive a following stage in the signal chain with a (fairly) low input impedance.

In practice one could think of a micro-probe which senses the potential of a single biological cell. This potential is measured over a long coaxial cable, with a lot of parasitic capacitances. When the cable is directly connected to the cell, all energy of the signal is necessary to drive the cable capacitance, so the signal will be totally absorbed by the cable. When the buffer is placed between the microprobe and the cable, the potential is sensed with zero energy. The signal on the cable, a copy of the cell potential, is delivered by the voltage source of the OPAMP. This would make it possible to measure the cell-potential over a shielded cable.

7.3.3. Inverting Amplifier#

Another basic configuration is the inverting amplifier. This type of amplifier will amplify a signal and change its polarity. Changing the polarity of a signal is sometimes of use in (complex) systems, for example when working with differential signals (topic of the next chapter). Sometimes the polarity of the signal is not important and only amplitude is of importance, then other characteristics of the inverting amplifier might make it the best candidate for the job.

First of all, let’s have a look at the basic circuit of an inverting amplifier, see Fig. 7.8.

../_images/Inverting-Amplifier.svg

Fig. 7.8 Inverting amplifier circuit, with a virtual-ground point#

When we have a look at the circuit diagram, we can still see a passive feedback network which consists of \(R_i\) and \(R_f\). This network is connected to the inverting (-) input (negative feedback!). But: the voltage source or input signal is connected to this network as well. The non-inverting (+) input, which was the signal input for the non-inverting amplifier is now connected to ground (0 Volt).

Let’s have a look at how this circuit will work. For this we will use the zero-conditions again. First of all, there is no voltage difference between the amplifier inputs. In this circuit, the non-inverting (+)input is connected to GND. Thus, the inverting (-) input will remain at ground level (0 Volt) all the time. Based on this, we can calculate the current which flows through \(R_i\), using Ohm’s Law.

(7.13)#\[ I_{R_i} = \frac{U_{in}}{R_i} \]

The current which flows through this resistor, must go somewhere. Now the second zero-condition will become of importance: No current flows into the inputs of the OPAMP. Here it means, that all the current which flows through \(R_i\), has to flow through \(R_f\). Assume the input voltage is positive, then the current through Ri will flow from left to right. This current will continue to flow through \(R_f\) from left to right as well. As the left side of Rf is at ground potential, the current will only flow to the right, when \(U_{out}\) is below ground potential, so negative. In formula:

(7.14)#\[ U_{out} = -I_{R_f} \cdot R_f = -I_{R_i} \cdot {R_f} \]

Based on equations (7.13) and (7.14) we are now able to derive the transfer for this circuit.

(7.15)#\[ U_{out} = -I_{R_i} \cdot R_f = -\frac{U_{in}}{ Ri} \cdot R_f = -U_{in} \cdot \frac{R_f}{R_i} \]
(7.16)#\[ G = \frac{U_{out}}{U_{in}} = - \frac{R_f}{R_i} \]

Here we can see that the gain is determined by the ratio of Rf and Ri. The minus-sign doesn’t indicate attenuation of the signal, but it indicates the phase-change. The input signal and output signal are in counter-phase. This is shown in Fig. 7.9.

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# Time axis
x = np.linspace(0, 4 * np.pi, 1000)   # about 4 periods

# Input and output signals (inverting amplifier: output is inverted)
Uin = np.sin(x)
gain = 11.0
Uout = -gain * np.sin(x)   # <-- Inversion happens here

# =======================
#       Plotting
# =======================

fig, ax = plt.subplots(figsize=(12, 6))

ax.plot(x, Uin, '--', color='blue', linewidth=2, label='Input Voltage')
ax.plot(x, Uout, color='red', linewidth=2, label='Output Voltage')

ax.set_xlim(x[0], x[-1] + 1.5)
# ax.set_ylim(-2.5, 2.5)

# Remove normal axis spines and ticks
for spine in ['top', 'right', 'bottom', 'left']:
    ax.spines[spine].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])

# Draw x (time) axis as an arrow
ax.annotate('', xy=(x[-1] + 0.5, 0), xytext=(x[0], 0), arrowprops=dict(arrowstyle='->', linewidth=1, color='black'))

# Draw y (voltage) axis as an arrow
ax.annotate('', xy=(x[0], gain), xytext=(x[0], -gain), arrowprops=dict(arrowstyle='->', linewidth=1, color='black'))

# Axis labels
ax.text(x[-1] + 0.6, 0, 'Time', va='center', fontsize=14)
ax.text(x[0], gain + 0.1, 'Voltage', ha='center', fontsize=14)

ax.legend(loc='upper center')

plt.tight_layout()
plt.show()
../_images/1d2d08d453cd7f3120865799c5a3e69ccacdb5876e46e7909007a0ea889020e7.png

Fig. 7.9 Input and output signal of an inverting amplifier.#

In the graph, in Fig. 7.9, we can see that the input signal and the output signal are opposite in polarity (phase). The output signal has a higher amplitude compared to the input signal. The difference will be the amplification factor.

Another important aspect of this circuit is the input impedance. With the non-inverting amplifier the signal was connected to the non-inverting input, no current would flow there, thus the input impedance was infinite. Here, with the inverting OPAMP, the input voltage source has to supply the current which flows through Ri and Rf. The input impedance will thus not be infinite. What will be the input impedance? For the input voltage it seems that it has to power a resistor which is connected to ground, the resistor \(R_i\). The input voltage source doesn’t “see” \(R_f\). Thus the input resistance of this amplifier equals \(R_i\). The output impedance of this circuit is determined by the voltage source inside the OPAMP. Thus the output impedance will remain 0 \(\Omega\), similar to the non-inverting amplifier. When choosing resistors it is good to realize that \(R_i\) will determine the input impedance. This resistor will usually be several k\(\Omega\)s. The other resistor is determined by the wanted gain-factor, and will be in the k\(\Omega\) region as well.

When looking at the gain factor of this circuit, we can see that the gain can be varied between 0 and (almost) infinite. In theory the gain could be below 1, so attenuation, instead of amplification. While attenuation is possible with an OPAMP circuit, it can be realised by a simpler resistor divider, therefore such circuit will used less frequenctly.

7.3.4. Virtual Ground Point#

When we analyzed the circuit we concluded that the inverting-input of the OPAMP will be at ground-potential. While this point is at ground-potential, it is not actual ground! As the current which flows there, should go somewhere else. In the situation of the inverting amplifier, the current will flow through Rf. Nevertheless, for the rest of the circuit, this point looks like a ground point, therefore we will call this a “virtual ground point”.

../_images/difference-between-real-ground-and-virtual-ground.svg

Fig. 7.10 Virtual ground point in an inverting amplifier.#

7.3.5. Current-to-Voltage Converter#

The virtual ground point which was described before has proven to be a very versatile characteristic in OPAMP circuits. As said any current flowing to the virtual ground point will continue its journey through another path, most often the resistor Rf. The most basic form is the current to voltage converter, its diagram is shown in Fig. 7.11.

../_images/Transimpedance_Amplifier__Op-Amp-Based_Current-to-Voltage_Signal_Converter.svg

Fig. 7.11 Current to voltage converter.#

This circuit has a current input, for example current generated by a photodiode, so not a voltage input which we see more often. The current at the input will flow towards the virtual ground point. As the current doesn’t flow into the OPAMP, the current continues its path through Rf. The transfer function of the circuits is as follows:

(7.17)#\[ U_{out} = -I_{in} \cdot R_f \]

The transfer function of the circuit will be:

(7.18)#\[ H = \frac{U_{out} }{I_{in}} = -R_f \]

The circuit has a transfer which could be expressed in \(\Omega\), because it will be voltage divided by current, as in Ohm’s Law. However, very often it is referred as “Volts / Ampere”, or derivatives, like mV/mA. As this amplifier converts current at its input to a voltage at the output it often referred to as “transimpedance amplifier”. In fact, the inverting amplifier from the previous section can be seen as a voltage to current conversion (with the resistor) followed by a transimpedance amplifier, which converts the current through \(R_i\) in Fig. 7.8 into \(U_out\).

One could argue that just a resistor is a current to voltage converter, as well. In a way this is true, since the voltage across a resistor is given by Ohm’s law. The advantage of the OPAMP circuit is not the conversion of current into voltage itself, but that it performs this conversion while keeping the input voltage approximately constant.

7.3.6. Summing Amplifiers#

Another application of OPAMPs is in summing amplifiers. A summing amplifier, or more correctly, an inverting summing amplifier can be used to add signals together, without the signals influencing each other. This amplifier makes use of a virtual ground point to add the signals together. For this the voltage to be added should be converted to a current first, which in this case can perfectly be done with a resistor. In Fig. 7.12 we see a summing amplifier with three inputs.

../_images/summing-amplifier.svg

Fig. 7.12 Summing amplifier with three inputs.#

For each of the input channels the input voltage will be converted to a current through the corresponding resistors. (This is in a similar way as to the inverting amplifier.) All of these currents will be added in the virtual ground point. The resulting current will then be converted to a voltage by Rf.

In order to get a transfer function for this circuit the following formulas can be used.

\[ I_1 =\frac{U_1}{R_1} ; I_2 =\frac{U_2}{R_2} ; I_3 =\frac{U_3}{R_3} \]

The resulting current is: \( I_f = I_1 + I_2 + I_3 \)

The output voltage is: \( U_{out} = -I_f \cdot R_f\)

All these formulas added together give:

\[ U_{out} = -R_f * (I_1 + I_2 + I_3) = -R_f * (\frac{U_1}{R_1} + \frac{U_2}{R_2} + \frac{U_3}{R_3}) \]
(7.19)#\[ U_{out} = -(U1 \cdot \frac{R_f}{R_1} + U2 \cdot \frac{R_f}{R_2}+ U3 \cdot \frac{R_f}{R_3}) \]

From equatiom (7.19) it can be seen that the voltage can be added with different ratios. As the currents are added in the summing point, virtual ground point, oeach input signal contributes independently to the output voltage. This type of circuit is used in complicated regulation systems, but another good example is an audio-mixer where the signals of multiple audio sources are added together (mixed).

7.3.7. Clipping#

OPAMPS will not work if they are not powered, so if (either) of their voltage supply pins are not connected. This supply voltages also limits the range of output voltage: the output voltage cannot be higher than the supplied voltage, and even stay a bit below.

For example: Consider an OPAMP circuit with an amplification of 10, and with \(U_{supply} = \pm \) 15V. If the input voltage is a sine with 2V amplitude, thus 4 Vpp, then the expected output amplitude would be 10 x 2 Vp = 20 Vp, thus 40 Vpp. However, the OPAMP cannot produce a voltage beyond the supply voltages, \(\pm\) 15V, thus a maximum range of 30 V. The resulting output signal will look like a 20Vp sine, but clipped at (slightly below) \(\pm\) 15 V.

7.4. OPAMP Circuits in Practice (with Complex Impedances in the Feedback)#

Up to now we have seen circuits with resistors in the feedback path. These resistors could be replaced with other components as well, indicated as an impedance. In practice it could be a capacitor, an inductor or a resistor. As capacitors and inductors have a frequency dependent impedance, the resulting circuit will show frequency dependent behavior. In Fig. 7.13 we see a generic circuit, an inverting amplifier topology, where the resistors are replaced with generic impedances.

../_images/ideal-inverting-op-amp_impedance.svg

Fig. 7.13 OPAMP circuit with generic impedances in the feedback.#

The transfer function of this circuit is similar to an inverting amplifier with resistors. Instead of Ri and Rf we can write Zi and Zf.

Thus:

\[ G = \frac{U_{out}}{U_{in}} = -\frac{Z_f}{ Z_i} \]

When calculating the transfer, the Zf and Zi should be replaced with the appropriate complex function.

Thus:

  • for a capacitor: \(Z_i\) or \(Z_f\) = \(\frac{1}{j \omega C}\)

  • for an inductor: \(Z_i\) or \(Z_f\) = \(j \omega L\)

  • for a resistor: \(Z_i\) or \(Z_f\) = R

Depending on which components are selected the circuit will have different time-dependent and frequency-dependent behavior.

7.4.1. the Differentiator#

When we choose for \(Z_i\) a capacitor and for \(Z_f\) a resistor we get a circuit which is known as a differentiator. The resulting circuit can be seen in Fig. 7.14.

../_images/opamp35.svg

Fig. 7.14 Differentiator circuit with an OPAMP.#

This circuit can be analyzed in two different ways, one way of looking at the circuit is in the frequency domain, the other way is in the time domain. Hopefully you see an analogy with the passive RC-circuit (differentiator or high-pass filter).

7.4.1.1. the OPAMP Differentiator in the Frequency Domain#

For a start, let’s have a look at the behavior in the frequency domain. The transfer of the circuit is determined by the components in the feedback circuit, thus the resistor and the capacitor. When looking at the configuration we see that the structure is similar to an inverting amplifier. The transfer will be:

(7.20)#\[ G = \frac{U_{out}}{U_{in}} = -\frac{Z_f}{Z_i} = -\frac{R_f}{\frac{1}{j \omega C}} = -j \omega C \cdot R_f \]

When we have a look at this formula we see that the gain for DC (\(\omega\)=0) is zero, so the circuit will not pass any DC. For very high frequencies (\(\omega\) = \(\infty\)) the gain should be infinite.

Will the gain become infinite in reality as well? In practice the OPAMP has a limited gain, still high (~100.000x), but not infinite. The gain has to come from the OPAMP, thus this will impose a practical limit on the gain. Furthermore the signal-bandwidth of an OPAMP is not infinite, thus the signal will not be amplified anymore beyond certain frequencies. There the differentiator will stop functioning.

When further looking at equation (7.20) we see that the gain will increase linearly with frequency. For every octave (doubling of the frequency) the gain will increase by a factor of two, thus 6dB/octave. For every decade (10 times the frequency) the gain will increase by a factor of ten, so 20dB/decade.

What is the meaning of the RC value? The RC-value determines the “cut-off” frequency. As the circuit behaves as a high-pass it determines the point from which the gain will be above 1 (=0 dB).

What is the meaning of the “- j” in the formula? The “- j” indicates the phase behavior. Note that this phase behavior is coming from the inverting action of the OPAMP topology (-180º, or -\(\pi\)) and from the capacitor. The capacitor adds a +j, which means +\(\frac{\pi}{2}\). The resulting phase shift will be -\(\frac{\pi}{2}\).

This behavior is shown in Fig. 7.15.

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# =======================
#       Plotting
# =======================

fig, ax = plt.subplots(figsize=(10, 6))

# Coordinate system just for drawing (not physical units)
ax.set_xlim(0, 1.2)
ax.set_ylim(-0.4, 1.1)

# Turn off standard axes
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])

# Colours
gain_color = 'darkblue'
phase_color = 'red'

# Positions (normalized coordinates)
x_left = 0.1
x_right = 0.9
x_phase_axis = 0.8
y_bottom = -0.35
y_top = 1.0
y_zero_dB = 0.4
y_phase_const = 0

# -----------------------
# Gain axis (left, blue)
# -----------------------
ax.annotate( '', xy=(x_left, y_top), xytext=(x_left, y_bottom), arrowprops=dict(arrowstyle='->', linewidth=1.5, color=gain_color))
ax.text(x_left, y_top + 0.05, 'Gain (dB)', ha='center', va='bottom', color=gain_color, fontsize=14)

# 0 dB line (blue, horizontal)
ax.hlines(y_zero_dB, x_left, x_phase_axis, colors=gain_color, linewidth=1)
ax.text(x_left - 0.02, y_zero_dB, '0 dB', ha='right', va='center', color=gain_color)

# Frequency (log) axis as arrow (blue)
ax.annotate('', xy=(x_phase_axis, y_zero_dB), xytext=(x_left, y_zero_dB), arrowprops=dict(arrowstyle='->', linewidth=1.5, color=gain_color))
ax.text(x_phase_axis + 0.02, y_zero_dB, 'Frequency (log)', ha='left', va='center', color=gain_color, fontsize=14)

# Gain line (Bode magnitude ~ 20 dB/dec) - just a straight line here
ax.plot([x_left, x_phase_axis], [y_bottom + 0.05, y_top - 0.1], color=gain_color, linewidth=2)

# Mark corner frequency
x_fc = 0.5
ax.text(x_fc, y_zero_dB - 0.06, '$\\frac{1}{2\\pi RC}$', ha='center', va='top', color=gain_color, fontsize=16)

# -----------------------
# Phase axis (right, red)
# -----------------------
ax.annotate('', xy=(x_phase_axis, y_top), xytext=(x_phase_axis, y_bottom), arrowprops=dict(arrowstyle='->', linewidth=1.5, color=phase_color))
ax.text(x_phase_axis, y_top + 0.05, 'Phase (rad)', ha='center', va='bottom', color=phase_color, fontsize=14)

# Constant phase line (red)
ax.hlines(y_phase_const, x_left, x_phase_axis, colors=phase_color, linewidth=1.5)
ax.text(x_phase_axis + 0.02, y_phase_const, '$-\\frac{\\pi}{2}$', ha='left', va='center', color=phase_color, fontsize=16)

plt.tight_layout()
plt.show()
../_images/1c71dd68182f175fc87340ced93a13ce9486d98520a50987eb041ce648e780cb.png

Fig. 7.15 Phase and gain behavior of the OPAMP differentiator.#

7.4.1.2. the OPAMP Differentiator in the Time Domain#

Another way of looking at the circuit is in the time-domain. The capacitor will add a time dependent factor to the circuit when it is being charged or discharged.

For analyzing the circuit this way, we make use of the “Golden rules” aka the zero conditions.

At the input of the circuit we have an input voltage \(U_{in}\). This voltage is connected to one side of the capacitor and between GND. The other side of the capacitor is connected to the inverting input of the OPAMP, as discussed before, this point will behave as a virtual ground-point.
Result: As the inverting input behaves as virtual ground, the full input voltage is over the capacitor. Note: The circuit does not contain a resistor that limits the capacitor’s current. The current through the capacitor is determined by the rate of change of the input voltage. For an ideal voltage step, this would result in an infinitely large current. Practical circuits contain mechanisms to limit the current.

The side connected to the virtual ground point has to pass the current, as no current will flow into the OPAMP, this current has to be supplied through Rf. Which means that the current through the voltage will be converted into a voltage at the output of the OPAMP. Remember Ohm’s Law, when a current passes through a resistor, there will be a (proportional) voltage drop over the resistor.

The current through the capacitor is given by: \(I_{cap} = C \frac{dU_{in}}{dt}\)

As said, the current through the resistor Rf equals the current through the capacitor, thus \(I_f = I_{cap}\).

The output voltage of the circuit is \(U_o = -I_f \cdot R_f\)

Which gives a total transfer of:

(7.21)#\[ U_o = -R_f \cdot C \frac{dU_{in}}{dt} \]

The minus sign in front of the transfer function, will give an opposite result, compared to what one would expect from the mathematical differentiating action.

This formula in itself is maybe not very clear. Let’s look at some examples of input voltages and resulting output voltages.

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from scipy import signal

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# ----------------------------------------
# Ideal numerical differentiator
# ----------------------------------------
def ideal_differentiator(x, dt):
    y = np.zeros_like(x)
    y[1:] = np.diff(x) / dt
    y[0] = y[1]             # copy first valid value
    return y

# ----------------------------------------
# 1st-order RC low-pass: y[n] = alpha*y[n-1] + (1-alpha)*x[n]
# ----------------------------------------
def rc_lowpass(x, dt, tau_lp):
    alpha = tau_lp / (tau_lp + dt)
    y = np.zeros_like(x)
    for n in range(1, len(x)):
        y[n] = alpha * y[n-1] + (1 - alpha) * x[n]
    return y

# ----------------------------------------
# Active differentiator model followed by RC low-pass
# ----------------------------------------
def active_differentiator(x, t, T, tau_lp):
    dt = t[1] - t[0]
    omega = 2 * np.pi / T
    K = -1.0 / omega            # so sine -> -cos with same amplitude
    v_diff = K * ideal_differentiator(x, dt)
    v_out = rc_lowpass(v_diff, dt, tau_lp)
    return v_out

# ==========================================================
# Global settings
# ==========================================================
T = 2 * np.pi          # "period" used on the x-axis
points_per_period = 1000
P = points_per_period

N_burn_in = 5          # periods to reach steady state

# time constant of the "practical" differentiator
tau_lp = T / 50       # small compared to period -> good differentiator

# π-based ticks
xticks_pi_sine = np.array([0, np.pi, 2*np.pi])
xtick_labels_sine = [r"$0$", r"$\pi$", r"$2\pi$"]

xticks_pi_square = np.array([0, np.pi, 2*np.pi, 3*np.pi, 4*np.pi])
xtick_labels_square = [r"$0$", r"$\pi$", r"$2\pi$", r"$3\pi$", r"$4\pi$"]

# ==========================================================
# SINE CASE (1 period plot)
# ==========================================================
N_plot_sine = 1
N_periods_total_sine = N_burn_in + N_plot_sine
N_samples_sine = N_periods_total_sine * P + 1

t_full_sine = np.linspace(0, N_periods_total_sine * T, N_samples_sine)

vin_sine_full = np.sin(2 * np.pi * t_full_sine / T)
vout_sine_full = active_differentiator(vin_sine_full, t_full_sine, T, tau_lp)

start_sine = N_burn_in * P
end_sine = (N_burn_in + N_plot_sine) * P

t_sine = t_full_sine[start_sine:end_sine+1] - t_full_sine[start_sine]
vin_sine = vin_sine_full[start_sine:end_sine+1]
vout_sine = vout_sine_full[start_sine:end_sine+1]

# ==========================================================
# SQUARE CASE (2 periods plot)
# ==========================================================
N_plot_square = 2
N_periods_total_square = N_burn_in + N_plot_square
N_samples_square = N_periods_total_square * P + 1

t_full_square = np.linspace(0, N_periods_total_square * T, N_samples_square)

vin_square_full = np.sign(np.sin(2 * np.pi * t_full_square / T))
vout_square_full = active_differentiator(vin_square_full, t_full_square, T, tau_lp)

start_square = N_burn_in * P
end_square = (N_burn_in + N_plot_square) * P

t_square = t_full_square[start_square:end_square+1] - t_full_square[start_square]
vin_square = vin_square_full[start_square:end_square+1]
vout_square = vout_square_full[start_square:end_square+1]

# ==========================================================
# TRIANGULAR CASE (2 periods plot)
# ==========================================================
N_plot_triangle = 2
N_periods_total_triangle = N_burn_in + N_plot_triangle
N_samples_triangle = N_periods_total_triangle * P + 1

t_full_triangle = np.linspace(0, N_periods_total_triangle * T, N_samples_triangle)

# Generate triangular wave using sawtooth
vin_triangle_full = signal.sawtooth(2 * np.pi * t_full_triangle / T, width=0.5)
vout_triangle_full = active_differentiator(vin_triangle_full, t_full_triangle, T, tau_lp)

start_triangle = N_burn_in * P
end_triangle = (N_burn_in + N_plot_triangle) * P

t_triangle = t_full_triangle[start_triangle:end_triangle+1] - t_full_triangle[start_triangle]
vin_triangle = vin_triangle_full[start_triangle:end_triangle+1]
vout_triangle = vout_triangle_full[start_triangle:end_triangle+1]

xticks_pi_triangle = np.array([0, np.pi, 2*np.pi, 3*np.pi, 4*np.pi])
xtick_labels_triangle = [r"$0$", r"$\pi$", r"$2\pi$", r"$3\pi$", r"$4\pi$"]

# ==========================================================
# Plotting (3x2 grid: outputs right, inputs left)
# ==========================================================
fig, axs = plt.subplots(3, 2, figsize=(12, 10))

# (row, col)

# --- Sine IN (left) ---
axs[0, 0].plot(t_sine, vin_sine, 'b', linewidth=2)
axs[0, 0].set_title("Input voltage (sine wave)")
axs[0, 0].set_ylabel(r"$U_{in}$")
axs[0, 0].grid(True, alpha=0.25)
axs[0, 0].set_xticks(xticks_pi_sine)
axs[0, 0].set_xticklabels(xtick_labels_sine)

mask = vin_sine >= 0
axs[0, 0].fill_between(t_sine, vin_sine, 0, where=mask, color='blue', alpha=0.15)
axs[0, 0].fill_between(t_sine, vin_sine, 0, where=~mask, color='blue', alpha=0.15)

axs[0, 0].set_xticks(xticks_pi_sine)
axs[0, 0].set_xticklabels(xtick_labels_sine)

# --- Sine OUT (right) ---
axs[0, 1].plot(t_sine, vout_sine, 'r', linewidth=2)
axs[0, 1].set_title("Output voltage (differentiated sine wave)")
axs[0, 1].set_ylabel(r"$U_{out}$")
axs[0, 1].grid(True, alpha=0.25)
axs[0, 1].set_xticks(xticks_pi_sine)
axs[0, 1].set_xticklabels(xtick_labels_sine)

mask = vout_sine >= 0
axs[0, 1].fill_between(t_sine, vout_sine, 0, where=mask, color='red', alpha=0.15)
axs[0, 1].fill_between(t_sine, vout_sine, 0, where=~mask, color='red', alpha=0.15)

axs[0, 1].set_xticks(xticks_pi_sine)
axs[0, 1].set_xticklabels(xtick_labels_sine)

# --- Square IN ---
axs[1, 0].plot(t_square, vin_square, 'b', linewidth=2)
axs[1, 0].set_title("Input voltage (square wave)")
axs[1, 0].set_ylabel(r"$U_{in}$")
axs[1, 0].grid(True, alpha=0.25)
axs[1, 0].set_xticks(xticks_pi_square)
axs[1, 0].set_xticklabels(xtick_labels_square)

# --- Square OUT ---
axs[1, 1].plot(t_square, vout_square, 'r', linewidth=2)
axs[1, 1].set_title("Output voltage (differentiated square wave)")
axs[1, 1].set_ylabel(r"$U_{out}$")
axs[1, 1].grid(True, alpha=0.25)
axs[1, 1].set_xticks(xticks_pi_square)
axs[1, 1].set_xticklabels(xtick_labels_square)

mask = vout_square >= 0
axs[1, 1].fill_between(t_square, vout_square, 0, where=mask, color='red', alpha=0.15)
axs[1, 1].fill_between(t_square, vout_square, 0, where=~mask, color='red', alpha=0.15)

axs[1, 1].set_xticks(xticks_pi_square)
axs[1, 1].set_xticklabels(xtick_labels_square)

# --- Triangle IN ---
axs[2, 0].plot(t_triangle, vin_triangle, 'b', linewidth=2)
axs[2, 0].set_title("Input voltage (triangular wave)")
axs[2, 0].set_xlabel("t")
axs[2, 0].set_ylabel(r"$U_{in}$")
axs[2, 0].grid(True, alpha=0.25)
axs[2, 0].set_xticks(xticks_pi_triangle)
axs[2, 0].set_xticklabels(xtick_labels_triangle)

# --- Triangle OUT ---
axs[2, 1].plot(t_triangle, vout_triangle, 'r', linewidth=2)
axs[2, 1].set_title("Output voltage (differentiated triangular wave)")
axs[2, 1].set_xlabel("t")
axs[2, 1].set_ylabel(r"$U_{out}$")
axs[2, 1].grid(True, alpha=0.25)
axs[2, 1].set_xticks(xticks_pi_triangle)
axs[2, 1].set_xticklabels(xtick_labels_triangle)

mask = vout_triangle >= 0
axs[2, 1].fill_between(t_triangle, vout_triangle, 0, where=mask, color='red', alpha=0.15)
axs[2, 1].fill_between(t_triangle, vout_triangle, 0, where=~mask, color='red', alpha=0.15)

plt.tight_layout()
plt.show()
../_images/7242749e991622554dfe68901af06f67d76b3f1d48c05fa5b266849edc730f7c.png

Fig. 7.16 In this figure we can observe some signals in the time domain. Note the inverting action of the circuit.#

In Fig. 7.16 we see that a sinewave on the input does not give a cosine (the mathematicalo differentiation), but, due to the inverting action of the OPAMP, it will give an inverted cosine.When a square-wave or step function is applied, the circuit will only react on the slope of the square-wave or step-function. The output of the circuit will give (inverted) sharp spikes in phase with the transitions of the square wave. The response to a triangle-wave on the input will be a square wave: a constant (positive or negative) voltage at the output depending on the (decreasing or increasing) slope of the triangle.

7.4.2. the Integrator#

When a capacitor is placed in the feedback path and a resistor at the input of the inverting amplifier, a circuit is created which is referred to as the “integrator”. More correctly, it is an inverting integrator, due to the inverting action of the OPAMP circuit. The basic configuration is shown in Fig. 7.17 .

../_images/opamp26.svg

Fig. 7.17 Basic integrator circuit with an OPAMP.#

Compared to the differentiator the resistor and capacitor swapped their position. Similar to the differentiator this circuit can be analyzed in the time-domain and in the frequency-domain. Let’s start with the frequency domain.

7.4.2.1. the OPAMP Integrator in the Frequency Domain#

This circuit is an inverting amplifier configuration with a complex impedance (capacitor) in its feedback path. This will yield a transfer function as shown below, equation (7.22).

(7.22)#\[\begin{split} \begin{aligned} G &= \frac{U_{\text{out}}}{U_{\text{in}}} \\ &= -\frac{Z_f}{Z_i} \\ &= -\frac{\frac{1}{j \omega C}}{R_i} \\ &= -\frac{1}{j \omega C R_i} \end{aligned} \end{split}\]

When analyzing the formula, we can see that for DC (ω = 0) the gain of the circuit would be infinite. While this is true in theory, the gain of the circuit will be limited by the OPAMP in real life. For very high frequencies (\(\omega = \infty\)) the denominator of the transfer function will be very high, resulting in a transfer very close to zero.

What else can we tell from the formula? We can see a linear behavior of the gain with the frequency. When the frequency (\(\omega\)) will double (octave), the gain will be halved. This results in a linear slope of 6dB/oct. Similar, when the frequency is increased ten times (decade), the gain will be reduced by a factor of ten, which can be expressed as 20dB/dec.

What will happen to the phase of the signal? We can see that there will be an inversion (-180º phase shift) due to inverting amplifier circuit. Furthermore, the capacitor is responsible for another -90º shift in phase, this totals -270º. With continuous signals, this phase shift will look like an effective +90º phase shift, thus \(\frac{\pi}{2}\).

This can be seen from mathematical point as well: Integrating a SIN gives a -COS. In this case the signal will be inverted as well, thus the -COS is multiplied by -1, giving +COS. Which is π/2 ahead of the sinewave.

The resulting gain characteristic is shown in Fig. 7.18 .

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

fig, ax = plt.subplots(figsize=(10, 6))

# Coordinate system (not physical units)
ax.set_xlim(0, 1.2)
ax.set_ylim(-0.4, 1.1)

# Remove axes
for spine in ax.spines.values():
    spine.set_visible(False)
ax.set_xticks([])
ax.set_yticks([])

gain_color = 'darkblue'
phase_color = 'red'

# Positions
x_left = 0.1
x_phase_axis = 0.8
y_bottom = -0.35
y_top = 1.0
y_zero_dB = 0.4
y_phase_const = 0.8

# -----------------------
# Gain axis
# -----------------------
ax.annotate('', xy=(x_left, y_top), xytext=(x_left, y_bottom), arrowprops=dict(arrowstyle='->', linewidth=1.5, color=gain_color))
ax.text(x_left, y_top + 0.05, 'Gain (dB)', ha='center', va='bottom', color=gain_color, fontsize=14)

# 0 dB line
ax.hlines(y_zero_dB, x_left, x_phase_axis, colors=gain_color, linewidth=1)
ax.text(x_left - 0.02, y_zero_dB, '0 dB', ha='right', va='center', color=gain_color)

# Frequency axis
ax.annotate('', xy=(x_phase_axis, y_zero_dB), xytext=(x_left, y_zero_dB), arrowprops=dict(arrowstyle='->', linewidth=1.5, color=gain_color))
ax.text(x_phase_axis + 0.02, y_zero_dB, 'Frequency (log)', ha='left', va='center', color=gain_color, fontsize=14)

# -----------------------
# DIAGONAL LINE
# -----------------------
# ends BELOW 0 dB at the phase axis
ax.plot([x_left, x_phase_axis], [y_top - 0.1, y_zero_dB - 0.3], color=gain_color, linewidth=2)

# Corner frequency label (still at the 0 dB crossing)
x_fc = 0.55
ax.text(x_fc - 0.02, y_zero_dB - 0.02, r'$\frac{1}{2\pi RC}$', ha='center', va='top', color=gain_color, fontsize=16)

# -----------------------
# Phase axis
# -----------------------
ax.annotate('', xy=(x_phase_axis, y_top), xytext=(x_phase_axis, y_bottom), arrowprops=dict(arrowstyle='->', linewidth=1.5, color=phase_color))
ax.text(x_phase_axis, y_top + 0.05, 'Phase (rad)', ha='center', va='bottom', color=phase_color, fontsize=14)

# +pi/2 phase line
ax.hlines(y_phase_const, x_left, x_phase_axis, colors=phase_color, linewidth=1.5)
ax.text(x_phase_axis + 0.02, y_phase_const, r'$+\frac{\pi}{2}$', ha='left', va='center', color=phase_color, fontsize=16)

plt.tight_layout()
plt.show()
../_images/477a2b2f10d13337e11c4a251f3c0b1b0c2451ec14f84384aeb87cd808650b8a.png

Fig. 7.18 Gain characteristic of the integrator. Note that both the horizontal and vertical axis are logarithmic. Thus the frequency on the left side will never reach 0 Hz (DC).#

7.4.2.2. The OPAMP Integration in the Time Domain#

The integrator circuit can be analyzed in the time domain as well. The capacitor will take care of the integrating action, by either storing or releasing energy (charging/discharging). For analyzing the circuit we will rely on the Golden rules, known as the zero-conditions.

The input voltage \(U_{in}\) is connected between GND and the left side of the resistor \(R_i\). The right side of the resistor is connected to the virtual ground point. Which means that the input voltage is converted to a current by the resistor, \(I_f = \frac{U_{in}}{R_i}\). This current will not flow into the OPAMP (zero-condition!) so all this current has to pass through the capacitor to the output. The current will be integrated into the capacitor. Remember, the charge on a capacitor can be described as:

\( Q = C \cdot U_c\)

Written in a different way:

\(U_c = \frac{Q}{C} \)

When we are looking at changing charges we can write:

\(\frac{dU_c}{dt} = \frac{1}{C} \cdot \frac {dQ}{dt} \)

Where \(\frac {dQ}{dt} \) is equal to the current flowing. Remember: 1 Ampere = 1 Coulomb / second

The current flowing can be described with: \(I = \frac{U_{in}}{R_i}\)

Current through the capacitor is equal to the current through the resistor \(R_i\), thus:

\[ I_{R_i} = I_f = \frac{U_{in}}{ R_i} = \frac{dU_c C}{dt} \]

Remember the inverting action of the OPAMP, this finally yields:

\[ U_{out} = -\frac{1}{R_{in}C} \int_{0}^{t} U_{in} \, dt +constant= -\int_{0}^{t} \frac{U_{in}}{R_{in}C} \, dt +U_{out}(t=0) \]

The approach given above is generic. A special situation occurs when the input of the integrator is fed with a constant voltage for a certain time. Then you can integrate the above equation and obtain:

\[ U_{out} = \frac{-U_{in} t}{R_{in}C} +U_{out}(t=0) \]

This shows that the output will change in a linear fashion when a constant voltage is applied to the input. Remember that the charge over a capacitor will increase linearly when supplied with a constant current. In this case the constant current is generated by the OPAMP. In a RC circuit without OPAMP the current is not constant, resulting in exponential charging of the capacitor. The output is nicely illustrated by the time plots of the input and output signal of the integrator in Fig. 7.19.

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from scipy import signal

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# ----------------------------------------
# Ideal numerical integrator
# y[n] = y[n-1] + K * x[n] * dt
# ----------------------------------------
def ideal_integrator(x, dt, K=-1.0):
    """
    K = -1.0 -> inverting op-amp integrator: Uout = -∫ Uin dt
    For Uin = sin(ωt), this gives Vout ∝ +cos(ωt) (after removing DC).
    """
    y = np.zeros_like(x)
    for n in range(1, len(x)):
        y[n] = y[n-1] + K * x[n] * dt
    return y

# ==========================================================
# Settings: 1 period from 0 to 2π
# ==========================================================
T = 2 * np.pi
points_per_period = 1000
P = points_per_period

t = np.linspace(0, T, P + 1)
dt = t[1] - t[0]

# Inputs
Uin_sine   = np.sin(2 * np.pi * t / T)
Uin_square = signal.square(2 * np.pi * t / T)
Uin_triangle = signal.sawtooth(2 * np.pi * t / T, width=0.5)

# Outputs (numerical integration)
Uout_sine_raw   = ideal_integrator(Uin_sine,   dt, K=-1.0)
Uout_square_raw = ideal_integrator(Uin_square, dt, K=-1.0)
Uout_triangle_raw = ideal_integrator(Uin_triangle, dt, K=-1.0)

# Remove DC offset so they look like pure cosine / triangle
Uout_sine   = Uout_sine_raw   - np.mean(Uout_sine_raw)
Uout_square = Uout_square_raw - np.mean(Uout_square_raw)
Uout_triangle = Uout_triangle_raw - np.mean(Uout_triangle_raw)

# π-based ticks
xticks_pi = np.array([0, np.pi, 2*np.pi])
xtick_labels = [r"$0$", r"$\pi$", r"$2\pi$"]

# ==========================================================
# Plotting (3×2 grid): rows = sine, square, triangle
# ==========================================================
fig, axs = plt.subplots(3, 2, figsize=(12, 10))

# --- Sine Input ---
axs[0, 0].plot(t, Uin_sine, 'b', linewidth=2)
axs[0, 0].set_title("Input voltage (sine wave)")
axs[0, 0].set_ylabel(r"$U_{in}$")
axs[0, 0].grid(True, alpha=0.25)

mask = Uin_sine >= 0
axs[0, 0].fill_between(t, Uin_sine, 0, where=mask, color='blue', alpha=0.15)
axs[0, 0].fill_between(t, Uin_sine, 0, where=~mask, color='blue', alpha=0.15)

axs[0, 0].set_xticks(xticks_pi)
axs[0, 0].set_xticklabels(xtick_labels)

# --- Sine Output (Integrator) ---
axs[0, 1].plot(t, Uout_sine, 'r', linewidth=2)
axs[0, 1].set_title("Output voltage (integrated sine wave)")
axs[0, 1].set_xlabel("t")
axs[0, 1].set_ylabel(r"$U_{out}$")
axs[0, 1].grid(True, alpha=0.25)

mask = Uout_sine >= 0
axs[0, 1].fill_between(t, Uout_sine, 0, where=mask, color='red', alpha=0.15)
axs[0, 1].fill_between(t, Uout_sine, 0, where=~mask, color='red', alpha=0.15)

axs[0, 1].set_xticks(xticks_pi)
axs[0, 1].set_xticklabels(xtick_labels)

# --- Square Input ---
axs[1, 0].plot(t, Uin_square, 'b', linewidth=2)
axs[1, 0].set_title("Input voltage (square wave)")
axs[1, 0].set_ylabel(r"$U_{in}$")
axs[1, 0].grid(True, alpha=0.25)

axs[1, 0].set_xticks(xticks_pi)
axs[1, 0].set_xticklabels(xtick_labels)

# --- Square Output (Integrator) ---
axs[1, 1].plot(t, Uout_square, 'r', linewidth=2)
axs[1, 1].set_title("Output voltage (integrated square wave)")
axs[1, 1].set_xlabel("t")
axs[1, 1].set_ylabel(r"$U_{out}$")
axs[1, 1].grid(True, alpha=0.25)

mask = Uout_square >= 0
axs[1, 1].fill_between(t, Uout_square, 0, where=mask, color='red', alpha=0.15)
axs[1, 1].fill_between(t, Uout_square, 0, where=~mask, color='red', alpha=0.15)

axs[1, 1].set_xticks(xticks_pi)
axs[1, 1].set_xticklabels(xtick_labels)

# --- Triangle Input ---
axs[2, 0].plot(t, Uin_triangle, 'b', linewidth=2)
axs[2, 0].set_title("Input voltage (triangular wave)")
axs[2, 0].set_ylabel(r"$U_{in}$")
axs[2, 0].grid(True, alpha=0.25)
axs[2, 0].set_xticks(xticks_pi)
axs[2, 0].set_xticklabels(xtick_labels)

# --- Triangle Output (Integrator) ---
axs[2, 1].plot(t, Uout_triangle, 'r', linewidth=2)
axs[2, 1].set_title("Output voltage (integrated triangular wave)")
axs[2, 1].set_xlabel("t")
axs[2, 1].set_ylabel(r"$U_{out}$")
axs[2, 1].grid(True, alpha=0.25)
mask = Uout_triangle >= 0
axs[2, 1].fill_between(t, Uout_triangle, 0, where=mask, color='red', alpha=0.15)
axs[2, 1].fill_between(t, Uout_triangle, 0, where=~mask, color='red', alpha=0.15)
axs[2, 1].set_xticks(xticks_pi)
axs[2, 1].set_xticklabels(xtick_labels)

plt.tight_layout()
plt.show()
../_images/89d7f89d09935d2cdaf527a1573d4a7646df8d4598e65d25a95e2051bfe2d7f8.png

Fig. 7.19 Input and output waveforms of the OPAMP-integrator. Note that the output of the triangle is a parabolic, and not a sine.#

7.4.2.3. Taming a OPAMP Integrator#

When there is a constant voltage, no matter how small, there will be a resulting net current flowing in the capacitor. As the output voltage of the OPAMP is limited by its power-supplies, the output voltage of the integrator will be limited by the OPAMP’s power supply voltage. In this situation it is clear where the “slow drift” of the output is coming from (the small offset on the input). However, when this offset is not present, a similar effect could occur. The reason for this is the small current the OPAMP draws on its input (as will be discussed in the next chapter). Based on the zero-condition we stated that no current flows into the inputs of the OPAMP. Roughly speaking this is true, but in practice a small current will flow, we call this current the bias-current. The bias current ranges from a few pA to a few nA. Normally speaking, we can neglect this, but in the integrator this current will cause some problems.

Is there a solution to this problem? Luckily there is! By adding an extra resistor (\(R_2\)), a path, parallel to the capacitor can be created for the bias-current, this is shown in Fig. 7.20 . This resistor will have influence on the behavior of the integrator. However, the influence is small, so it’s a small price which has to be paid for having a practically usable circuit.

../_images/opamp-opamp34.svg

Fig. 7.20 ‘Tamed’ Integrator with extra resistor added, to mitigate the influence of the small current (bias-current) flowing into the OPAMP.#

The resistor \(R_2\) can have a high value, in the order of mega-\(\Omega\)s. In the transfer function, the influence of the extra resistor is clearly indicated.

The gain for low frequencies, close to DC is limited to the ratio of R2 and R1.

This gain can be described by: \( G_{dc} = -\frac{R_2}{R_1} \)

This can be further clarified by comparing the impedance of the capacitor to the value of the resistance. For DC the impedance of the capacitor will be infinite, the resistor R2 in parallel, with the capacitor will then mainly determine the impedance.

In the frequency characteristic we can see two specific points. The low pass cut-off frequency, determined by \(C\) and \(R_2\) and the point where the gain will be equal to one (0 dB), determined by \(C\) and \(R_1\).

Remember that the complete formulas will be:

Low pass cut off frequency: \( f = \frac{1}{2 \pi C R_2} \)

Unity gain frequency: \( f = \frac{\sqrt{R_2^2 - R_1^2}}{2\pi R_1 R_2 C}\), which only for \(R_2\)>>\(R_1\) will approximate \( f = \frac{1}{2 \pi C R_1} \)

The slope of the gain will be equal compared to the ideal integrator.

7.5. OPAMP Circuits in Practice (with positive Feedback): Comparator with an OPAMP#

Up till now we have been looking at linear circuits. The output voltage is a linear function of the input voltage. For these circuits the Golden rules do apply. However, there are circuits which make use of the high open loop gain of the OPAMP which are not linear. An example of such a circuit is the comparator.

The comparator is used when two different voltages should be compared. Before we jump into analyzing these circuits, it should be noted that comparators can be made with OPAMPs, but there are specialized integrated circuits which are called (surprisingly) “comparators”. An integrated circuit (IC) is an electronic circuit that contain multiple integrated onto a single semiconductor chip and packaged as a single component. In practice, general-purpose OPAMPs are often not well suited for comparator applications, because their internal amplifier stages can saturate, resulting in relatively slow switching and recovery times. Dedicated comparator ICs are designed to avoid these limitations. However, here we will focus on the circuits based on OPAMPs.

7.5.1. Basic Comparator#

The basic comparator consists of just an OPAMP, no other components are needed. On one connection a reference voltage is connected, on the other connection the voltage to be measured (compared). The output of the OPAMP is the output of the comparator. This is shown in Fig. 7.21 .

../_images/simple_opamp_comparator.svg

Fig. 7.21 Basic comparator with an OPAMP.#

In this situation we make use of the high open-loop gain of the amplifier. Basically the OPAMP amplifies the voltage difference between the inverting and non-inverting input. When the output signal (amplified input voltage difference) reaches the power supply voltage, the output voltage will be limited to the supply voltage (the output is clipping). When \(U_+\) is (slightly) higher compared to \(U_-\), the resulting input voltage is positive and the output will clip at its positive supply voltage. When U+ is slightly lower than U- the output voltage will clip at its negative supply. A very small region, where the voltage difference is just a few microvolts, the output can give a voltage in between its power supply voltages. However, this is such a small region, that the change seems instantaneous. In the situation in Fig. 7.21, the \(U_-\) is the reference, thus when \(U_+\) is above the reference voltage the output is positive. When \(U_+\) is below \(U_-\), the output voltage will be negative. When the reference is connected to U+ and the input signal to \(U_-\), the circuit will work in the opposite (inverted) way. When the input voltage is above the reference, the output will be negative. When the input is below the reference, the output is positive. We call this an “inverting comparator”.

In real life signals will carry some noise (small random fluctuations). This noise can cause some erroneous behavior. Imagine we use the comparator in a counter, which counts when the voltage was above a certain reference value. Each time the comparator gives a high signal, an event is counted in an incremental counter. When the counter is close to its switching point, the noise of the input signal (and/or reference signal) will cause a “bouncing” effect of the comparator output, creating a fast train of pulses. This is shown in Fig. 7.22. All these pulses will be counted as well, giving an error in the reading of this measurement system.

Nothing

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# Set random seed for reproducibility
np.random.seed(43)

# Time parameters
dt = 0.1e-9  # 0.1 ns time step
t_total = 10e-6  # 10 microseconds
t = np.arange(0, t_total, dt)
n_points = len(t)

# Comparator parameters
T_PD = 50e-9  # Propagation delay: 50 ns (gives ~10 MHz oscillation)
period = 2 * T_PD  # Oscillation period ~100 ns
freq = 1 / period  # ~10 MHz

# Time when oscillation starts and ends
osc_start = 4.8e-6
osc_end = 6.8e-6

# Output signal
U_out = np.ones(n_points) * 0.90  # Start high

# During oscillation period, create square wave at ~10 MHz
osc_mask = (t >= osc_start) & (t <= osc_end)
t_osc = t[osc_mask] - osc_start
square_wave = (np.sin(2 * np.pi * freq * t_osc) > 0).astype(float)
U_out[osc_mask] = 0.05 + 0.85 * square_wave

# After oscillation, stay low
U_out[t > osc_end] = 0.05

# Add tiny noise to all regions
U_out += 0.004 * np.random.randn(n_points)

# Input signal (IN+) - mostly flat with noise, stays below threshold
U_IN_plus = 0.01 + 0.006 * np.random.randn(n_points)

shift = 0.2

# Downsample for plotting
downsample = 100
t_plot = t[::downsample]
U_out_plot = U_out[::downsample] - shift
U_IN_plus_plot = U_IN_plus[::downsample] - shift - 0.1


# =============
#   Plotting
# =============

fig, ax = plt.subplots(figsize=(14, 8))

ax.plot(t_plot * 1e6, U_out_plot, 'g-', linewidth=0.8, label='$U_{out}$')
ax.plot(t_plot * 1e6, U_IN_plus_plot, 'b-', linewidth=0.5, label='$U_{IN+}$')

ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.set_xlim(0, 10)

# Main grid
ax.grid(True, alpha=0.5, linewidth=0.5)

ax.legend(loc='upper right')

# Add minor ticks + minor grid
ax.minorticks_on()
ax.grid(True, which='minor', alpha=0.4, linewidth=0.3)

# Get current ticks
yticks = ax.get_yticks()

# Convert tick locations into labels: show '0' only
ylabels = [ '0' if t == 0 else '' for t in yticks ]

ax.set_yticks(yticks)
ax.set_xticklabels([])
ax.set_yticklabels(ylabels)

plt.tight_layout()
plt.show()
../_images/49228fc5eb522427fd080ca5d898b04da841db9f527137d26427a42520638dc6.png

Fig. 7.22 Scope image of bouncing at the output. Output-signal is upper trace, input signal, with noise, is the lower trace.#

The higher the peak-to-peak amplitude of the noise on the signal, the higher the error will be in the system. There is an effective solution for this problem, which is referred to as “hysteresis”.

7.5.2. Comparator with Hysteresis, or Schmitt-trigger#

A comparator which has hysteresis is less sensitive to noise; such type of circuit is also referred to as “Schmitt-trigger”. What does hysteresis mean?
The switching levels (thresholds) have moved apart. The result of adding hysteresis to a comparator, is that the output of the comparator will change its state from negative to positive at a different input voltage level, compared to the voltage level when the output changes from positive to negative. This is illustrated in Fig. 7.23.

../_images/comparator_hysteresis.svg

Fig. 7.23 Behavior of a comparator with hysteresis. The black triangle-wave is the input signal. When above \(U_{trip+}\) the output will become positive and remain positive, till the input signal has passed the \(U_{trip-}\) level.#

In Fig. 7.23 the thresholds are shown as \(U_{trip+}\) and \(U_{trip-}\). The output signal remains at its state till the signal has passed above \(U_{trip+}\) or below \(U_{trip-}\). Noise on the signal will not affect the output state (unless the noise causing the signal to pass a threshold). The difference between Utrip+ and Utrip- should be higher than the expected noise on the signal.

How do we create this behavior in an OPAMP-circuit? In order to get this behavior we will be using positive feedback (also called feedforward). This is the opposite of the negative feedback we saw for the linear amplifier circuits. Part of the output signal is fed back to the inputs of the OPAMP, however, not to the inverting (-) input, but to the non-inverting (+) input.

The diagram of a non-inverting comparator with hysteresis is shown in Fig. 7.24.

../_images/comp_hyst_circuit.svg

Fig. 7.24 Non-inverting comparator with hysteresis.#

The switching levels (\(U_{trip+}\) and \(U_{trip-}\)) are determined by the reference voltage (which could be 0, thus GND), the output voltage of the OPAMP (power supply voltage) and the ratio of the resistors.

In general it can be said that the output of the comparator will change at the moment that the inverting-input and non-inverting-input have the same potential. But note, that due to the resistors the non-inverting-input voltage is not equal to the input voltage of the comparator-circuit!

The following equations can be derived starting with \(U_{out} = \pm U_{supply}\) and the corresponding \(U_{in}\) levels:

\[ U_{TH+} = \frac{R_I}{R_{FB}} \cdot (U_{REF} - U_{OL}) + U_{REF} \]
\[ U_{TH-} = \frac{R_I}{R_{FB}} \cdot (U_{REF} - U_{OH}) + U_{REF} \]

The behavior of the circuit can be studied in the time-domain, as shown in Fig. 7.23. Another way of visualizing the behavior of the circuit is by creating a plot in which the output voltage of the circuit is shown as a function of the input voltage. This is shown in Fig. 7.25. Similarities can be seen with the hysteresis curve which might be known from studying magnetism.

../_images/comp_hyst_output.svg

Fig. 7.25 Output signal of the comparator as function of the input signal. The arrows show the transitions.#

In order to understand what is happening we will have a closer look at the diagram. Let’s start at the bottom left. The input voltage \(U_{in}\), will travel along the horizontal line at the bottom. As long as the input voltage does not pass \(U_{th+}\) (upper threshold) the output voltage will be \(U_{ol}\). When the input voltage passes \(U_{th+}\), the output will “switch” to its high level (\(U_{oh}\)). The output will remain at this level, as long as \(U_{in}\) remains above \(U_{th-}\). As soon as the input voltage drops below \(U_{th-}\) the output will switch to the low-level (\(U_{ol}\)). The width of the hysteresis curve shows the separation of the low and the high threshold voltage.

The description above is for the non-inverting comparator. It is possible to construct an inverting comparator with hysteresis as well. The diagram is shown in Fig. 7.26, together with its input-output curve.

../_images/comp_hyst_output_inverting.svg

Fig. 7.26 Inverting comparator with hysteresis and the accompanying input-output curve.#

Advantage of this circuit is that the input signal is connected to an OPAMP input. This input has a very high impedance, thus the source \(U_{in}\) is not loaded by the comparator circuit.

For the switching levels the following formulas can be derived:

\[ U_{TH+} = U_{REF} + (U_{OH} - U_{REF}) \cdot \left( \frac{R_I}{R_I + R_F} \right) \]
\[ U_{TH-} = U_{REF} - (-U_{OL} + U_{REF}) \cdot \left( \frac{R_I}{R_I + R_F} \right) \]

Just like with the non-inverting comparator the reference voltage \(U_{ref}\) can be equal to zero. Giving a symmetrical hysteresis curve around GND.

7.5.3. Control Loops#

With the introduction of the OPAMP we made a comparison with the control or regulation loop for a heating system. With the theory of this chapter in the back of our mind we can revisit this topic.

The easiest regulation loop can be made with a comparator without hysteresis. However, such a regulator will be switching on and off a lot when, e.g. the temperature, is around its setpoint. Things can improve when by adding some hysteresis. This will prevent the quick switching on and off around the setpoint at the expense of fluctuations around the setpoint (due to the high and low setpoint).

The regulators based on the comparators have a crude on/off behavior. In practice one wants a smoother regulation loop based on more linear elements. While the theory behind regulation loops is a study on its own, we would like to mention some of these regulators here.

The easiest is the P (proportional)-regulator, which is actually a linear amplifier. The behavior is such that when the difference between the set-value and the real value is small it will give a low output voltage, which equals the control voltage. When the difference is large, a higher control voltage will be given.

A lot of different control systems do exist. Each with their own specific characteristics and requirements. For some applications, where temperature is controlled, overshoot of the temperature cannot be allowed, e.g. when working with proteins, or when heating up a microscope objective. Then a more complicated control is used, This could be a combination of Proportional regulation, combined with an integrator and even a differentiator (to speed up the control process). These types of regulators are named Proportional Integrating regulator (PI-regulator) or Proportional Integrating Differentiating regulator (PID-regulator).

These regulators can be constructed using the basic circuits described in this chapter. So it could consist of an OPAMP amplifier, an OPAMP based differentiator and an OPAMP based integrator. The inputs of these circuits will be connected to the sensor of the system. The outputs are combined in an OPAMP summing amplifier. The output of this amplifier will control the actuator of the regulation loop.

../_images/PID_regulator.svg

Fig. 7.27 Principle of a control loop based on OPAMPs. The subtraction point where the set-value and measured value are subtracted is not shown (but similar to Fig. 7.1), the output of this subtractor is the input signal for this system.#

7.6. OPAMP Applications#

7.6.1. Application Example - the Photo Diode Amplifier#

Light-intensity measurements are used a lot in (bio)chemical experiments or other measurement systems. Very often a linear measurement of the intensity is necessary, as the intensity relates to e.g. the concentration of a certain molecule or enzyme. Photodiodes make good and sensitive photodetectors. The (blocking) current through the photodiode has a good linear relationship with the light-intensity.

In order to have the photo-diode in the current mode (or photoconductive mode, where the photodiode acts as a current source, and the photocurrent is proportional to the incident light), it should be in zero-bias (0 Volt drop over the diode) or even negatively biased. Negative bias will increase the size of the depletion region, which results in a lower PN-junction capacitance, which increases the bandwidth (speed) of the photo-detection. In Fig. 7.28 and Fig. 7.29 we see both situations, only difference is the potential of the anode of the photo-diode, either GND or a negative voltage.

../_images/photo_diode_readout_circuit.svg

Fig. 7.28 Photo-diode readout circuit using an OPAMP. with zero-bias,#

../_images/media_180_1809b762-4904-470c-bd14-4488a29af069_image.svg

Fig. 7.29 Photo-diode readout circuit using an OPAMP. with negative bias.#

The OPAMP is used to convert the current into a voltage and to keep the bias-voltage over the diode constant. The cathode of the photo-diode is connected to the virtual ground point, inverting input of the amplifier. This point remains at GND level, while the anode of the diode is connected to another point with a fixed potential, GND or a negative bias.

When light hits the photodiode a reverse current will flow. This current cannot be supplied by the OPAMPs input, thus has to come from the output through the feedback resistor Rf. One side of the resistor is at GND-potential (virtual ground point), so any current flowing through the resistor will develop a voltage over the resistor (Ohm’s Law) which will result in a positive voltage at the output of the OPAMP.

Of course it is possible to use the photo-diode in photovoltaic mode (voltage mode) as well. However, the relation between light intensity and output voltage is generally less linear compared to the photocurrent. As a result, this type of circuit is often less suitable for accurate intensity measurements.

7.6.2. Analog Computing#

Nowadays digital systems are all around use. This is made possible because of the silicon chips, which allow integration of a lot of components in a small space. Before the silicon chips, the systems had to be made with electronic vacuum tubes or electromechanical relays. These systems became bulky! Building a micro-computer with these elements was possible, however it would take a whole building to build just that computer…not very practical. In that era it was more practical to solve things the analog way. It is possible to build a (mathematical) computer with analog electronics. The formulas could be converted to amplifiers (multiplication!), differentiators, integrators, adders and subtractors. By wiring these circuits a (complex) mathematical problem could “programmed” and solved. The input variables and the outputs were represented by voltages. These computers were capable of solving complex mathematical problems (or models) in a quick way. It is possible to build such a computer with OPAMP-circuits as well. Using this analog processing could be worth considering in specific situations (like high-speed control systems).

../_images/THAT_compu.jpg

Fig. 7.30 Example of a modern analog computer, mainly used for demonstrations.
Created by Jwdietrich2, under CC BY 4.0, original file
#

7.7. OPAMP Exercises#

Exercise 7.1 (Computer based temperature measurement)

A computer based system measures the temperature of its chemical reaction chamber. Inside the chamber there is a temperature sensor (type LM35). The temperature sensor gives an output voltage of 10mV/°C. The output of the sensor is 0mV at 0°C. The measurement range of the computer is 0 to 12.8Volt.

../_images/opamp_temp_meas.svg

Fig. 7.31 amplification of the signal from a LM35 temperature measurement to a computer.#

a) Given that the temperature we want to measure is 40°C at its maximum. Which gain is necessary for the amplifier to fully use the measurement range of the computer? Express your answer in dB.

b) Given that Rb is 2kΩ, calculate the value of resistor Ra, to get the gain as calculated in question a.

Exercise 7.2 (Comparator)

In the figure below a comparator is shown. It is used inside the colorimeter for conversion of the light intensity to a frequency varying signal. The maximum output voltage of the OPAMP is +11V, the minimum voltage is -11V. Ra has a value of 3kΩ, Rb has a value of 8kΩ.

../_images/comparator_question_1.svg

Fig. 7.32 amplification of the signal from a LM35 temperature measurement to a computer.#

a) Calculate the switching-levels (both positive and negative).

b) Describe and sketch what is happening when the signal shown below is applied to the input of the circuit. \(U_{max}\) = 8V, \(U_{min}\) =-8V.

../_images/comparator_input.svg

Fig. 7.33 Input signal varies between a negative Umin and positive Umax#

Exercise 7.3 (Integrator)

The circuit shown below is an integrator. In first instance the OPAMP may be assumed to be ideal. \(R_c\) has a value of 200 kΩ, C has a value of 50 nF.

../_images/integrator_question.svg

Fig. 7.34 An integrator circuit, with \(R_c\) and C.#

a) We assume the capacitor is uncharged (Uc = 0V). At t=0 we apply a voltage to the input of +4V. Make a sketch of the output voltage, starting at t=0.

b) Calculate the slope of the output voltage

c) Assume we connect a sine-wave voltage source to the input (frequency is few hundred Hertz, amplitude 50 mV).
The signal source has a small DC offset of 20mV.

Describe what will happen when this signal source is connected to the input of the circuit. You may assume that the capacitor is uncharged at t=0s.

Exercise 7.4 (Temperature measurement 2)

A circuit is made to read the temperature from a sensor. A schematic diagram is shown below.

../_images/opamp_temp_meas2.svg

Fig. 7.35 amplification of the signal from a LM35 temperature measurement to a computer.#

The sensor gives an output voltage of 2.5 mV/°C. At 0 °C the voltage is 0 mV.

a) An amplifier is added as shown in the schematic diagram. The amplification is set, such that Uout changes with 10 mV/°C (absolute value, so either positive or negative coefficient). R2 has the value of 12 k\(\Omega\). Calculate the value of R1.

b) What will the current flowing to R1 when the temperature of the sensor is 30 °C? You may assume the OPAMP to be ideal.

Next the circuit is modified, an extra OPAMP is added. See schematic below

../_images/opamp_temp_meas2a.svg

Fig. 7.36 amplification of the signal from a LM35 temperature measurement to a computer. With additional amplifiction with a second OPAMP and some resistors.#

c) Assume that the voltage at Uout1 changes with -20mV/°C. What will be the change per °C at Uout2 when R3 = 20kΩ and R5 = 1kΩ?
You may assume that U1 and R4 have no influence

d) When U1 has a value of -3V and R4 has a value of 91kΩ. What will be the offset at Uout2 due to these two components?

Exercise 7.5 (Building an OPAMP circuit)

The OPAMP U1 may be assumed to be ideal. The output voltage Uout will be within -10…+10 V. a) What kind of circuit is this? What is the drawback of this circuit? The circuit could be modified as shown below.

../_images/what_kind_of_circuit.svg

Fig. 7.37 Simple OPAMP circuit#

The circuit is modified as below.

../_images/comparator_R1R2.svg

Fig. 7.38 Adapted circuit with feedback.#

b) Calculate the switching levels, draw a diagram in which you show Uin on the horizontal axis and Uout on the vertical. Describe the way this circuits works when the voltage Uin is being varied.

Exercise 7.6 (Photodiode readout)

The circuit below shows a system for photodiode readout

../_images/photodiode_readout.svg

Fig. 7.40 A photodiode readout with a coax-cable and an OPAMP circuit.#

a) D1 is a photodiode, what are the names of the connections 1 and 2?

A photodiode can be used in two ways, one way is to measure the voltage which is generated by the photodiode (similar to a solar-cell), another way is to measure the generated photodiode current.

First we will have a look at the situation when the diode behaves like a voltage source. Connection 2 of D1 will be the positive side, connection 1 the negative side.
Given the following: Voltage over the photodiode = 350 mV, R1 = 100 kΩ, R2 = 2 MΩ

b) Calculate the voltage of Uout

Next the circuit is modified, R1 is shorted, so it has a value of 0 \(\Omega\)

c) What will be the voltage drop over the photodiode?

d) When the photodiode generates a photocurrent of 100nA, direction of the current is from 1 to 2. What will be the voltage at Uout?

Exercise 7.7 (Adapting voltages with an OPAMP)

You need to convert an input voltage range between 0 to 2V, to an output voltage range of 0 to -3V. For this you will use the following circuit, in which \(U_{in}\) gets converted into \(U_{out}\) with an inverting amplifier.

../_images/opamp_1.svg

Fig. 7.41 OPAMP circuit, for adapting the voltage from Uin to Uout#

a) Calculate the value of Ra when you know Rb = 10 kΩ.

Now assume that the (Uout) voltage range should be between -4.5 V and +1.5V . The amplifier circuit is modified with an offset voltage, see diagram below.

../_images/opamp1a.svg

Fig. 7.42 OPAMP circuit, for adapting the voltage from Uin to Uout, with an additional Uoffset
Rb = 10kΩ, Rc = 20kΩ.
#

b) Uin still varies from +2V to 0 V.
Calculate the value of Uoffset and Ra, such that the input voltage is converted to an output voltage of -4,5…+1.5V.

Exercise 7.8 (What kind of amplifier?)

../_images/opamp_whatkind.svg

Fig. 7.43 Some sort of amplifier Ra=2k\(\Omega\), Rb= 800 \(\Omega\), Rf= 4 k\(\Omega\). Ua= 5V, Ub=-3V, Udc=±15V#

a) What is the name of the above circuit

b) Derive the value of \(U_{out}\)

Exercise 7.9 (OPAMP with RC)

Given the circuit below. The input signal is a square wave symmetrical around 0, duty cycle = 50%, amplitude is 10 Vpp, period = 1ms, R = 10 kΩ, C = 100nF

../_images/opamp2RC.svg

Fig. 7.44 OPAMP circuit, with feedback Capacitor.#

a) Derive the numerical values for the voltage over the capacitor

b) Explain how the circuit works, and make an accurate drawing (showing the proper amplitude!) of the output signal, starting t=0s, when the waveform starts

Exercise 7.10 (OPAMP with RC 2)

Given the following OPAMP circuit

../_images/opampRC2.svg

Fig. 7.46 OPAMP circuit, with feedback Capacitor.
Given that R1 = 250 kOhm, C1 = 100 nF.
#

a) Assume the voltage of \(U_{IN}\) is +2V, the OPAMP is ideal, OPAMP power supply is +/-10 V and the capacitor holds no charge on t = 0ms.
What will be the voltage on Uo on t=10ms?

Exercise 7.11 (comparator)

A comparator is made, give the circuit diagram below.

../_images/comparator_q.svg

Fig. 7.47 Comparator circuit with hysteresis#

a) Given that the OPAMP’s maximum output voltage is +12V and the minimum -12V. Resistor R1 = 6 kOhm, R2 = 18 kOhm. What will be the switching thresholds for this comparator?

b) Now assume, the switching thresholds are +/- 4.5V (not the right answer to the previous question!). When the input voltage is 2.5V, what will be the output voltage?
I) The input voltage is within the linear region, thus it will be amplified 4x, thus 10 V.
II) The output voltage will be +12V.
III) The output voltage will be -12V.
IV) This cannot be said, it could either be +12V or -12V

Exercise 7.12 (Summing amplifier)

../_images/opamp_summer.svg

Fig. 7.48 Summing amplifier with two voltage inputs.
R1=5k\(\Omega\), R2= 10 k\(\Omega\), Rf= 25 k\(\Omega\). U1= 0.5V, U2=1 V
#

a) Derive the value for Uout

Exercise 7.13 (Complex transfer function)

../_images/complex_transfer.svg

Fig. 7.49 OPAMP circuit with complex transfer; R1=1 k\(\Omega\), R2=9 k\(\Omega\), C1=10 \(\mu\)F#

a) Derive the asymptotic values for the transfer function \( A(\omega) = \frac{U_{out}}{U_{in}}\)

b) Sketch bode-diagram

c) Calculate the corner frequencies where asymptotes change?

Exercise 7.14 (Inverting comparator)

../_images/comp_hyst_circuitQ.svg

Fig. 7.50 Comparator circuit, with two voltage sources.
\(U_{sup}\)=10 V; \(R_1\)=1 k\(\Omega\); \(R_2\)=9 k\(\Omega\)
#

a) Evaluate switching points when \(U_{ref}\)=0V

b) Evaluate switching point when \(U_{ref}\)= +2V