23. Op-amps as mathematical operators


In the previous lesson, we learned how we can use op-amps for inverting and noninverting amplification and for signal stabilization with an op-amp as an emitter follower.

This lesson, we present.

  • Summing and differential (subtracting)

  • Integrating

  • Differentiating

In future lessons, we will also investigate using op-amps in sample-and-hold circuits, active filters, transimpedence amplifiers (converting current to voltage) and in instrumentation amplifiers (using multiple op-amps to more stably amplify the difference between two voltages).

Summing amplifiers

When designing circuits, we often want to add voltages. A common example is when we use a high pass filter applied to a signal and the DC signal is attenuated to close to zero so that the filtered signal dips into negative voltages. If we have a detector that can only read nonnegative voltages (such as the built-in ADC of Arduino Uno), we will not be able to read our filtered signal. So, we may wish to add an offset voltage to the filtered signal to bring it above zero (e.g., if the variation of the signal is what we are interested in).

The circuit below is a non-inverting summing amplifier. With the example of adding voltages for use with a detector that can only read nonnegative voltages in mind, \(V_1\) may be high pass-filtered signal and \(V_2\) may be an offset voltage we wish to add to it.

Noninverting summing amplifier circuit

The idea is the same as the non-inverting amplifier described in the previous lesson. Here, we simply bring in two (or more) input signals into the noninverting input of the op-amp. By Millman’s theorem, the input voltage is

\begin{align} V_\mathrm{in} = \frac{V_1/R_1 + V_2/R_2}{R_1^{-1} + R_2^{-1}}. \end{align}

We then apply the result derived in the previous lesson for the amplification, giving

\begin{align} V_\mathrm{out} = \left(1 + \frac{R_3}{R_4}\right)\frac{V_1/R_1 + V_2/R_2}{R_1^{-1} + R_2^{-1}}. \end{align}

The resistances \(R_1\) and \(R_2\) may be tuned to give a weighted sum of the input voltages \(V_1\) and \(V_2\), and the resistances \(R_3\) and \(R_4\) may be tuned to give the gain of the amplifier. In the case where \(R_1 = R_2\) and \(R_3 = R_4\), we get \(V_\mathrm{out} = V_1 + V_2\).

Differential amplifiers

When making measurements with scientific instruments, we often want to compare two voltages. For example, we may wish to compare the potential across one electrode to that of a reference electrode. We therefore want to subtract one voltage from another. This is accomplished using a differential amplifier. The schematic below shows such an amplifier.

differential amplifier circuit

The output voltage is related to the input voltage by

\begin{align} V_\mathrm{out} = \frac{R_3}{R_1}\,V_1 - \frac{R_4}{R_2 + R_4}\left(1 + \frac{R_3}{R_1}\right)V_2. \end{align}

Thinking exercise 10: Differential amplifier transfer function

Derive the above result.


One can weight the two terms in the difference by tuning of the resistances. Specifically, if \(R_1 = R_2\) and \(R_3 = R_4\), the difference between the input voltages \(V_2\) and \(V_1\) is amplified by a factor of \(R_3/R_1\) such that

\begin{align} V_\mathrm{out} = \frac{R_3}{R_1}\left(V_1 - V_2\right). \end{align}

Hence, this is a differential amplifier.

Integration amplifier

So far, we have seen that op-amps can add and subtract voltages. They can also serve to integrate and differentiate time-varying input voltage. First, we consider an integrating amplifier, shown in the schematic below.

integrating amplifier circuit

Because the positive input is connected to ground, the input voltage is zero. It is therefore also zero at the negative input by the op-amp rule that the input voltages are equal. Therefore, the potential difference across the capacitor is \(-V_\mathrm{out}\). We know that the potential difference across a capacitor is \(Q/C\), where \(Q\) is the accumulated charge. So, we have

\begin{align} V_\mathrm{out} = -\frac{Q}{C}. \end{align}

The potential difference across the resistor is \(V_\mathrm{in}\), since the voltage at the negative input to the op-amp is zero. Thus, the current flowing through the resistor is \(I = V_\mathrm{in}/R\). Because effectively no current is flowing through the op-amp, the current through the resistor is equal to that of the current flowing into the capacitor. The current flowing into the capacitor serves to change the accumulated charge, such that

\begin{align} I = \frac{V_\mathrm{in}}{R} = \frac{\mathrm{d}Q}{\mathrm{d}t}. \end{align}

Because \(V_\mathrm{out} = Q/C\),

\begin{align} \frac{\mathrm{d}Q}{\mathrm{d}t} = - \frac{\mathrm{d}\,C V_\mathrm{out}}{\mathrm{d}t}, \end{align}

such that

\begin{align} \frac{V_\mathrm{in}}{R} = - \frac{\mathrm{d}\,C V_\mathrm{out}}{\mathrm{d}t}. \end{align}

Multiplying both sides be R and integrating yields

\begin{align} \int_0^t\mathrm{d}t'\,V_\mathrm{in} = -\int_0^t\mathrm{d}t'\,R\,\frac{\mathrm{d}\,C V_\mathrm{out}}{\mathrm{d}t'}. \end{align}

For constant \(R\) and \(C\), we can easily sovle for \(V_\mathrm{out}\) to give

\begin{align} V_\mathrm{out} = -\frac{1}{RC}\int_0^t\mathrm{d}t\,V_\mathrm{in}. \end{align}

Thus, the output voltage is given by a time integral over the input voltage. We can think of this as an integral over dimensionless time, where time is rescaled by \(RC\).

Differentiating amplifier

Like the integration amplifier integrates a time-varying voltage over time, a differentiator operator (not to be confuse with the differential amplifier) gives the derivative. This is accomplished by swapping the resistor and capacitor of the integration amplifier, as shown below.

differentiating amplifier circuit

Demonstrating that this circuit serves to differentiate the input signal follows along similar arguments as for the integration amplifier. The potential difference across the resistor in this case is \(-V_\mathrm{out}\). The potential difference across the capacitor is \(V_\mathrm{in}\), since the voltage at the negative input of the op-amp is zero because that at the negative input is zero. Therefore, the charge accumulated in the capacitor is \(Q = C V_\mathrm{in}\). The current flowing through the resistor is the rate of discharge of the capacitor (since essentially no current flows through the op-amp), so that

\begin{align} I = \frac{\mathrm{d}Q}{\mathrm{d}t} = \frac{\mathrm{d}C V_\mathrm{in}}{\mathrm{d}t} = -\frac{V_\mathrm{out}}{R}. \end{align}

We can solve for \(V_\mathrm{out}\) to give

\begin{align} V_\mathrm{out} = -R\,\frac{\mathrm{d}C V_\mathrm{in}}{\mathrm{d}t}, \end{align}

which for constant \(C\) gives

\begin{align} V_\mathrm{out} = -RC\,\frac{\mathrm{d}V_\mathrm{in}}{\mathrm{d}t}. \end{align}

So, the output of the circuit gives the derivative of the input voltage signal with respect to time, where time is in units of \(RC\).

Differentiator operators are seldom used, however. Because it is giving the slope of a signal, it is highly susceptible to noise; the noise will be amplified in the output. Furthermore, at high frequencies of input, the circuit can have an oscillatory instability, though this can be mitigated by placing a small capacitor in parallel to the resistor.


Answer to differential amplifier thinking exercise

Referring to the schematic for a differential amplifier, we use two of the rules about op-amps. First, the inputs draw very little current. Therefore the current flowing through resister R₁ is the same as that flowing through R₃, since effectively none goes through the op-amp. Therefore

\begin{align} I_1 = \frac{V_1 - V_a}{R_1} = I_3 = \frac{V_a - V_\mathrm{out}}{R_3}. \end{align}

Second, the input voltages to the op-amp are equal, such that V_a = V_b. We use the expression we derived for voltage dividers in Lesson 19 to write

\begin{align} V_a = V_b = \frac{R_4}{R_2 + R_4}\,V_2. \end{align}

Substituting this expression for \(V_a\) into the expression for the equality of currents through R₁ and R₃ gives use an expression containing only the resistances and the voltages \(V_1\), \(V_2\), and \(V_\mathrm{out}\). Solving for \(V_\mathrm{out}\) gives the desired result of

\begin{align} V_\mathrm{out} = \frac{R_3}{R_1}\,V_1 - \frac{R_4}{R_2 + R_4}\left(1 + \frac{R_3}{R_1}\right)V_2. \end{align}