%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

import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from ipywidgets import interact, FloatSlider, FloatLogSlider

%matplotlib inline
%config InlineBackend.figure_formats = ['svg']
import matplotlib
if not hasattr(matplotlib.RcParams, "_get"):
    matplotlib.RcParams._get = dict.get

3. Capacitors, complex impedances and Bode diagrams#

A capacitor is a component which stores electric energy. It consists of two plates which are insulated from each other. A passive filter, which reduces the amplitude of certain signal frequencies, can be constructed with only one capacitor and one resistor.

3.1. the Physics behind Capacitors#

Opposite charges attract each other, but what if they cannot reach each other because an insulating material in between? Then the electric charge is stored, in a capacitor.

Example 3.1 (Leiden jar)

The Leiden jar was invented in 1745, by van Mussenbroek and von Kleist. It consists of metal foil inside and outside a glass bottle filled with water. A metal pin is mounted through an insulating jar lid, and is submerged in the water, which can conduct current to and from the inner foil. The early Leiden jar could be charged to 20 to 60 kV .

../_images/Leyden_jar_showing_construction.png

Fig. 3.1 Leiden jar construction Author unknown, in Public Domain, original link.#

3.1.1. Capacitor as plates at certain distance#

A capacitor consists of two conducting materials, often plates, with an insulating material in between.

For any capacitor, the relationship between applied voltage \(U\) and charge \(Q\) is the capacitance \(C\):

(3.1)#\[ C=\frac{Q}{U} \]

For a parallel plate capacitor the amount of charge a capacitor holds, depends on the plate size, their separation, and the material between them. A bigger plate means more room for more charge, and the distance and dielectric determine the amount of insulation between the two plates.

With area \(A\), distance \(d\), and permittivity \(\epsilon\) which is a measure for the polarizability of a material, the capacitance of a parallel plate capacitor is:

(3.2)#\[ C=\frac{\epsilon A}{d} \]

The absolute permittivity \(\epsilon\) is a multiplication of the vacuum permittivity \(\epsilon _0\) and the relative permittivity \(\epsilon_r\):

\[ \epsilon= \epsilon _0 * \epsilon_r \]

\(\epsilon _0 \approx 8.8 10^-12 \frac{F}{m}\) is a natural constant, and the dimensionless \(\epsilon_r\) is material-dependent (1 for vacuum, 7 for salt, 80 for water).

../_images/Capacitor_schematic_with_dielectric.png

Fig. 3.2 A capacitor consists of two conductive plates with insulating material in between. It can store electric charge.
Created by Papa November, under CC BY-SA 3.0, original link
#

Opposite charge can accumulate on the two plates, this process is called charging. The initial charging current is determined by the series resistance and the applied voltage. When charge accumulate, the voltage across the capacitor increases, reducing the voltage across the resistor, causing a reduced charging current. The charging rate will progressively decrease during charging, until the capacitor voltage is equal to the supply voltage. Then there is no more current flow and the capacitor is fully charged.

While direct discharging between charged plates is inhibited by the insulation, one could connect both sides of the capacitor with a conducting wire. At connection, the many charges repel each other, and therefore the charge on a plate will decrease rapidly. When there is hardly any charge left, the repelling force is much less, so also the change in charge, i.e. current, will be much less.

Following this reasoning, the capacitor’s behavior varies over time, and therefore so does the current and voltage.

Nothing

Hide code cell source

def plot_rc_charge_discharge1(tau=2.0):
    t = np.linspace(0, 15, 1000)
    t_0 = 2
    U_in = 5
    R = 2

    U_in_charge = U_in * np.heaviside(t - t_0, 0.5)
    U_in_discharge = U_in * np.heaviside(-(t - t_0), 0.5)

    U_charge = U_in * (1 - np.exp(-(t - t_0) / tau)) * np.heaviside(t - t_0, 0.5)
    I_charge = (U_in - U_charge) / R * np.heaviside(t - t_0, 0.5)
    U_R_charge = (U_in - U_charge) * np.heaviside(t - t_0, 0.5)
    U_discharge = U_in * np.exp(-(t - t_0) / tau) * np.heaviside(t - t_0, 0.5)
    I_discharge = -U_discharge / R * np.heaviside(t - t_0, 0.5)
    U_R_discharge = -U_discharge

    fig, axs = plt.subplots(2, 2, figsize=(8, 7), sharey=True)
    ax1, ax2, ax3, ax4 = axs.flatten()

    ax1.plot(t, U_in_charge, label=r'$U_{in,\ charge}(t)$', color='blue', linewidth=2, linestyle='-')
    ax1.plot(t, U_charge, label='$U_c(t)$ (charging)', color='red', linewidth=2, linestyle='--')
    ax1.set_title('Charging Phase')
    ax1.set_xlabel('Time (t)')
    ax1.set_ylabel('Voltage')
    ax1.grid(True)
    ax1.legend()
    ax1.set_ylim(-4, 6)

    ax2.plot(t, U_in_discharge, label=r'$U_{in,\ discharge}(t)$', color='blue', linewidth=2, linestyle='-')
    ax2.plot(t, U_discharge, label='$U_c(t)$ (discharging)', color='red', linewidth=2, linestyle='--')
    ax2.set_title('Discharging Phase - Voltage Across Resistor')
    ax2.set_xlabel('Time (t)')
    ax2.set_ylabel('Voltage')
    ax2.grid(True)
    ax2.legend()
   
    #ax3.plot(t, U_charge, label=r'$U_{in,\ charge}(t)$', color='black', linewidth=2)
    ax3.plot(t, I_charge, label='$I(t)$ (charging)', color='blue', linewidth=2)
    ax3.set_title('Charging Phase')
    ax3.set_xlabel('Time (t)')
    ax3.set_ylabel('Current')
    ax3.grid(True)
    ax3.legend()
    ax3.set_ylim(-4, 6)

    #ax4.plot(t, U_in_discharge, label=r'$U_{in,\ discharge}(t)$', color='black', linewidth=2)
    ax4.plot(t, I_discharge, label='$I(t)$ (discharging)', color='blue', linewidth=2)
    ax4.set_title('Discharging Phase - Voltage Across Resistor')
    ax4.set_xlabel('Time (t)')
    ax4.set_ylabel('Current')
    ax4.grid(True)
    ax4.legend()
   

    fig.tight_layout()
    plt.show()

interact(plot_rc_charge_discharge1, tau=FloatSlider(value=2.0, min=0.2, max=5.0, step=0.1, description='RC'))
<function __main__.plot_rc_charge_discharge1(tau=2.0)>

Fig. 3.3 interactive plot:
a) A capacitor starts charging when a voltage is applied. At that moment (thin arrow), the current will be high (lots of changing charge). At the same moment, since there is so much charge left, hence also the voltage hardly changes. Later on, when the plates are more charged, it is much harder to add more charge (thick arrow), and therefore the current is low, and the voltage is high.
b) When the voltage drops, a large current will flow, but in opposite direction from the charging. The voltage initially hardly changes (thin arrow) and does not follow the sudden change in input voltage. However after some discharge time, most of the charge moved away from the capacitor, hence both the current (change in current) and the voltage over the capacitor have decreased (thick arrow).
#

The fact that current is the change of charge over time, can be combined with equation (3.1), leading to the following equation:

(3.3)#\[ I(t)=\frac{dQ}{dt} = C\frac{dU}{dt} \]

While the equation contains a linear differential relation (the operator \(d/dt\) is linear), there is no simple proportional relationship between \(I\) and \(U\) as there is for a resistor (\(U=IR\)). Because the current is proportional to the change in voltage, a constant voltage results in zero current. For an AC, sinusoidal input voltage, the current and voltage will be 90 degrees out of phase: the current leads the voltage, or equivalently the voltage lags the current.

You could rewrite the above equiation in integral form, which better aligns with physical intuition on which quantity leads and which lags. Since the voltage \(U\) depends on the integral of current \(I\), the voltage lags the current:

(3.4)#\[ U(t) = \frac{1}{C}\int I(t)\,dt + U(t_0) \]

3.1.1.1. Capacitors parallel and in series#

Like resistors, capacitors can also be placed in series and in parallel. When placed in parallel, the area (equation (3.2)) of the overall capacitor becomes larger, hence:

(3.5)#\[ C_{parallel}=C_1+C_2 \]

When placed in series, the distance between the outer plates becomes larger.

Using equation (3.2) leads to:

(3.6)#\[ \frac{d_1}{\epsilon A_1}+\frac{d_2}{\epsilon A_2}=\frac{d_{tot}}{\epsilon A_{tot}} = \frac{1}{C_1} +\frac{1}{C_2}=\frac{1}{C_{series}} \]

So, resistors and capacitors behave differently when placed in series or parallel. Resistors in series are summed, and capacitors are summed in parallel. While resistors add up inversely or reciprocally when in parallel, capacitors are summed inversely in series.

3.1.2. Electric field in a capacitor#

When there is a voltage difference \(U\) between two locations, separated by a distance \(d\), there will be an electric field \(E\):

(3.7)#\[ E=\frac{U}{d} \]

When a capacitor is charged, a voltage difference and therefore an electric field is stored inside the capacitor.

Example 3.2 (Radio antenna)

The working of Radio antennas is based on the same formula (EUd). When a varying electric field is received by an antenna, there will be a corresponding voltage difference, which is measured by the receiver. When sending a signal, a voltage difference is applied, and a radio wave is generated.

../_images/Dipole_receiving_antenna_animation_6_300ms.gif

Fig. 3.4 The working of an antenna, a fluctuating electric field induces a voltage difference in the antenna. The reverse happens at generating a radio wave: a time-varying voltage is applied and radio waves are sent out.
Created by Chetcorno, under CC0, original link
#

3.1.3. Energy storage in component#

Already knowing that \(P=U I\), allows to derive the power stored inside a capacitor. Then take into account that \(P=\frac{dE}{dt}\), \(E\) being the energy, and integrate over the voltage:

(3.8)#\[ P=U I = C U \frac{dU}{dt} =\frac{dE}{dt} \]

Leads to:

(3.9)#\[ E = \frac{1}{2} C U^2 \]

Disregarding possible small leakages, one could store the energy for a long time and put a loaded capacitor on the shelf.

3.1.4. Capacitor versus battery#

Although both a battery and a charged capacitor can supply voltages, and can be regarded as voltage sources, their behaviour and also output is quite different. A capacitor stores electrical energy, while a battery stores chemical energy which is converted to electrical energy upon usage.

The voltage output of a battery is constant, for example 1.5 V for an AA battery, until the battery is depleted. The voltage ‘supplied’ by a capacitor is not constant over time, and will deplete with every electron delivered. The discharging of the capacitor depends on the circuit, which most often contains a resistor which limits the maximum current of this circuit.

3.2. the Electronics behind Capacitors#

3.2.1. Single step time domain#

From equation (3.3) it is known that the current depends on the time-derivative of the voltage. Now let’s look at how it behaves in a circuit.

3.2.1.1. Measure the voltage over the capacitor#

../_images/RCcircuit.svg

Fig. 3.5 Circuit with two resistors, two switches, a voltage source and a capacitor. If \(Sw_1\) closes the capacitor starts charging with current through \(R_1\). When at the same time \(Sw_1\) opens and \(Sw_2\) closes, the charged capacitor will discharge via \(R_2\)#

In this circuit there are two switches \(Sw_1\) and \(Sw_2\), each in series with resistors \(R_1\) and \(R_2\). These resistors are required to limit the maximum current when closing either one of the switches. At the start both switches are open, then only \(Sw_1\) is closed, and later only \(Sw_2\) is closed, after which both open again. Assume that initially the capacitor is not charged.

When closing \(Sw_1\) the capacitor starts charging. Then

(3.10)#\[ U_C(t=0) = 0 \]
(3.11)#\[ I_C(t=0)= I_{R_1}=U_{in}/R_1 \]

Combining equation (3.3) with Ohm’s law (equation (2.1)), eventually results in:

(3.12)#\[ I(t)_{charge}= I(0) e^{-\frac{t}{RC}} \]

The corresponding discharging current becomes:

(3.13)#\[ I(t)_{discharge}= -I(0) e^{-\frac{t}{RC}} \]

Note the minus sign, which reflects the change in direction of the current.

The voltage behaves oppositely, also with an exponential behavior, but with a more gradual transition:

(3.14)#\[ U(t)_{charge}= U_{in} (1 - e^{-\frac{t}{RC}} ) \]
(3.15)#\[ U(t)_{discharge}= U_{in} e^{-\frac{t}{RC}} \]

At \(t=\tau=R C\) the exponential changes with \(e^{-1}\). This \(\tau\) is a characteristic time for the circuit.

Nothing

Hide code cell source

def plot_rc_charge_discharge2(tau=2.0):
    t = np.linspace(0, 15, 1000)
    t_0 = 2
    U_in = 5
    R = 2

    U_in_charge = U_in * np.heaviside(t - t_0, 0.5)
    U_in_discharge = U_in * np.heaviside(-(t - t_0), 0.5)

    U_charge = U_in * (1 - np.exp(-(t - t_0) / tau)) * np.heaviside(t - t_0, 0.5)
    I_charge = (U_in - U_charge) / R * np.heaviside(t - t_0, 0.5)
    U_R_charge = (U_in - U_charge) * np.heaviside(t - t_0, 0.5)
    U_discharge = U_in * np.exp(-(t - t_0) / tau) * np.heaviside(t - t_0, 0.5)
    I_discharge = -U_discharge / R * np.heaviside(t - t_0, 0.5)
    U_R_discharge = -U_discharge

    fig, axs = plt.subplots(2, 1, figsize=(8, 7), sharey=True)
    ax1, ax2 = axs.flatten()

    ax1.plot(t, U_in_charge, label=r'$U_{in,\ charge}(t)$', color='blue', linewidth=2, linestyle='-')
    ax1.plot(t, U_charge, label='$U_c(t)$ (charging)', color='red', linewidth=2, linestyle='--')
    ax1.set_title('Charging Phase')
    ax1.set_xlabel('Time (t)')
    ax1.set_ylabel('Voltage')
    ax1.grid(True)
    ax1.legend()
    ax1.set_ylim(-6, 6)

    ax2.plot(t, U_in_discharge, label=r'$U_{in,\ discharge}(t)$', color='blue', linewidth=2, linestyle='-')
    ax2.plot(t, U_discharge, label='$U_c(t)$ (discharging)', color='red', linewidth=2, linestyle='--')
    ax2.set_title('Discharging Phase')
    ax2.set_xlabel('Time (t)')
    ax2.set_ylabel('Voltage')
    ax2.grid(True)
    ax2.legend()
    ax2.set_ylim(-6, 6)

    fig.tight_layout()
    plt.show()

interact(plot_rc_charge_discharge2, tau=FloatSlider(value=2.0, min=0.2, max=5.0, step=0.1, description='RC'))
<function __main__.plot_rc_charge_discharge2(tau=2.0)>

Fig. 3.6 interactive plot: The input voltage \(U_{in}\) and output voltage \(U_C\) plotted versus time for a charge or discharge of a capacitor.#

3.2.1.2. Measure the voltage over the resistor#

In a setup with first the capacitor, and then the resistor, the behavior will be different from the above setup where the voltage over the capacitor is measured.

The voltage the source supplies is constant, so the sum of the voltage over the capacitor and over the resistor must be constant. This results in the following figure.

Nothing

Hide code cell source

def plot_rc_charge_discharge3(tau=2.0):
    t = np.linspace(0, 15, 1000)
    t_0 = 2
    U_in = 5
    R = 2

    U_in_charge = U_in * np.heaviside(t - t_0, 0.5)
    U_in_discharge = U_in * np.heaviside(-(t - t_0), 0.5)

    U_charge = U_in * (1 - np.exp(-(t - t_0) / tau)) * np.heaviside(t - t_0, 0.5)
    I_charge = (U_in - U_charge) / R * np.heaviside(t - t_0, 0.5)
    U_R_charge = (U_in - U_charge) * np.heaviside(t - t_0, 0.5)
    U_discharge = U_in * np.exp(-(t - t_0) / tau) * np.heaviside(t - t_0, 0.5)
    I_discharge = -U_discharge / R * np.heaviside(t - t_0, 0.5)
    U_R_discharge = -U_discharge

    fig, axs = plt.subplots(2,1, figsize=(8, 7), sharey=True)
    ax1, ax2 = axs.flatten()

    ax1.plot(t, U_in_charge, label=r'$U_{in,\ charge}(t)$', color='black', linewidth=2, linestyle='-')
    ax1.plot(t, U_charge, label='$U_C(t)$ (charging)', color='red', linewidth=2, linestyle='--')
    ax1.plot(t, U_R_charge, label='$U_R(t)$ (charging)', color='blue', linewidth=2, linestyle='-.')
    ax1.set_title('Charging Phase')
    ax1.set_xlabel('Time (t)')
    ax1.set_ylabel('Voltage')
    ax1.grid(True)
    ax1.legend()
    ax1.set_ylim(-6, 6)

    ax2.plot(t, U_in_discharge, label=r'$U_{in,\ discharge}(t)$', color='black', linewidth=2, linestyle='-')
    ax2.plot(t, U_discharge, label='$U_c(t)$ (discharging)', color='red', linewidth=2, linestyle='--')
    ax2.plot(t, U_R_discharge, label='$U_R(t)$ (discharging)', color='blue', linewidth=2, linestyle='-.')
    ax2.set_title('Discharging Phase')
    ax2.set_xlabel('Time (t)')
    ax2.set_ylabel('Voltage')
    ax2.grid(True)
    ax2.legend()
    ax2.set_ylim(-6, 6)

    fig.tight_layout()
    plt.show()

interact(plot_rc_charge_discharge3, tau=FloatSlider(value=2.0, min=0.2, max=5.0, step=0.1, description='RC'))
<function __main__.plot_rc_charge_discharge3(tau=2.0)>

Fig. 3.7 interactive plot: The input voltage \(U_{in}\) and voltages \(U_R\) and \(U_C\) plotted versus time for charging or discharging of both the resistor and capacitor.#

3.2.2. Complex impedances#

In the previous section the response to a sudden change, a step response, was covered. How would the response to an AC signal look?

Sine as (complex) exponential

Sines and cosines are the sum of (complex) exponentials (Euler’s formula):

\[ e^{j \phi} = cos(\phi) + j sin(\phi) \]

which allows the sine and cosine to be written as a sum of exponentials:

\[ cos(\phi)=\frac{e^{j\phi}+e^{-j \phi}}{2} \]
\[ sin(\phi)= \frac{e^{j\phi}-e^{-j\phi}}{2j} \]

Let’s replace \(\phi\) by \(\omega t\), with \(\omega = 2 \pi f\), with frequency \(f\) and angular frequency \(\omega\).

Rather then working with a sine or cosine, it is convenient to represent a sinusoidal signal as complex exponential. A physical voltage is the real part of this complex value:

\[ U(t)=\Re\left\{U_0 e^{j\omega t}\right\}=U_0 \cos(\omega t) \]

The complex exponential simplifies the mathematics, using \(U(t)=U_0 e^{j \omega t}\) combined with equation (3.3) one gets:

\[ I= C \frac{dU}{dt} = C \frac{U_0 e^{j \omega t}}{dt} = j \omega C U \]

The ratio of voltage to current defines the impedance \(Z_C\), which is a complex value unlike of a real resistance, is given by:

\[ Z_C= \frac{U}{I}=\frac{1}{j \omega C} \]

The factor \(j\) means the current and voltage are 90 degrees out of phase.

Let’s look at the complex behavior in the following example.

Example 3.3 (Low pass Circuit)

Consider the most basic RC circuit, with an AC source with amplitude \(U_0\) and frequency \(f_0\), and the resistor \(R\) and capacitor \(C\) in series. Then the voltage over the capacitor can be calculated in a similar way as for the voltage divider:

\[ U_C= U_{in} \frac{Z_C}{Z_C+R} \]

Then the transfer becomes:

\[ \frac{U_C}{U_{in}}= \frac{\frac{1}{j \omega C}}{\frac{1}{j \omega C} +R} = \frac{1}{1+j \omega R C} \]

Multiplying by its complex conjugate in both the numerator and denominator gives:

\[ \frac{U_C}{U_{in}}= \frac{1}{1+j \omega R C} \frac{1-j \omega R C}{1-j \omega R C} = \frac{1-j \omega R C}{1+\omega^2 R^2 C^2} \]

This can be split in the real \(Re()\) and imaginary \(Im()\) part, given that a complex number is the sum of \(Re() + j Im()\):

\[\begin{split} Re\left(\frac{U_C}{U_{in}}\right) = \frac{1}{1+\omega^2 R^2 C^2} \\ \end{split}\]
\[ Im\left(\frac{U_C}{U_{in}}\right) = \frac{-\omega R C}{1+\omega^2 R^2 C^2} \]

Or it can be rewritten in polar coordinates:

\[ \frac{1}{1+j \omega R C} = |z|({cos(\phi)+j sin(\phi)}) \]

with

\[\begin{split} |z| = \sqrt{\left(\frac{1}{1+j \omega R C}\right) \left(\frac{1}{1-j \omega R C} \right)}= \sqrt{\frac{1}{1+\omega^2 R^2 C^2}} \\ \end{split}\]
\[ \phi= arctan{\left( \frac{ Im(\frac{1}{1+j \omega R C} ) } {Re(\frac{1}{1+j \omega R C} ) } \right)}=arctan(-\omega R C)\]

Since \(\phi\) is non-zero, the peaks of \(U_{in}\) and \(U_C\) are not in sync anymore. Due to the minus sign, the peak in \(U_C\) will lag behind the peak of \(U_{in}\)

When using numerical values, with R=1 k\(\Omega\), C=100 nF, and f=10 kHz, the amplitude of \(U_C\) is:

\[ |z| = \sqrt{\frac{1}{1+\omega^2 R^2 C^2}} =\sqrt{\frac{1}{1+(2 \pi \cdot 10 kHz)^2 (1k\Omega) ^2 (100 nF)^2}} = 0.16 \]

The phase is:

\[ arctan(-\omega R C) = arctan (- 2 \pi \cdot 10k Hz \cdot 1 k\Omega\cdot 100 nF) = -1.41 rad = -81 ^o \]

Visually the input and output signals look as follows:

Nothing

Hide code cell source

def plot_lowpass(R=1e3):
    U0 = 1.0        # input amplitude [V]
    C = 100e-9      # capacitance [F]
    f = 10e3        # frequency [Hz]
    w = 2 * np.pi * f
    t = np.linspace(0, 700e-6, 2000)
    U_in = U0 * np.sin(w * t)

    wRC = w * R * C

    gain = 1 / np.sqrt(1 + wRC**2)   # |z|
    phi = -np.arctan(wRC)            # phase lag [rad]
    U_out = U0 * gain * np.sin(w * t + phi)

    fig, ax = plt.subplots(figsize=(8, 6))
    ax.plot(t * 1e6, U_in, color='blue', linewidth=2, linestyle='-', label=r'$U_{in}$')
    ax.plot(t * 1e6, U_out, color='red', linewidth=2, linestyle='--', label=r'$U_C$')

    ax.set_xlim(0, 700)
    ax.set_ylim(-1.0, 1.0)
    ax.set_xlabel(r'Time ($\mu$s)')
    ax.set_ylabel('Voltage (V)')
    # ax.set_title(rf'R = {R/1e3:.2f} k$\Omega$    |z| = {gain:.3f}    $\varphi$ = {np.degrees(phi):.1f}°')
    ax.set_xticks(np.arange(0, 701, 140))
    ax.set_yticks(np.arange(-1.0, 1.01, 0.2))
    ax.grid(True, color='lightgray')
    ax.legend()
    plt.show()

interact(plot_lowpass, R=FloatSlider(value=1e3, min=100, max=10e3, step=100, description='R (Ω)'))
<function __main__.plot_lowpass(R=1000.0)>

Fig. 3.8 interactive plot: The input voltage \(U_{in}\) and output voltage \(U_C\) plotted versus time.#

3.2.3. Response to a block wave#

In the previous section there was only a single step, followed by infinite time to revert back to the situation at rest. When encountering a block wave, there might not be enough time to return to rest, before the next step is encountered. Then one has to compare the period of the block wave and the RC time, in order to know whether there is enough time to go to rest.

Assume a 50% duty cycle (half of period high signal, half of period a low signal):

  • If RC << half period: The exponential will be zero long before the next step

  • If RC \(\approx\) half period: The exponential will have reduced to \(e^{-1}\) = 0.37

  • If RC >> half period: Only the first part of the exponential, which can be linearly approximated, occurs before the next step. This behavior is displayed in the figure below, both for a low pass filter (measured over C) and a high pass filter (measured over R).

Nothing

Hide code cell source

def plot_lowpass(RC=0.5):
    U_in = 1
    f = 0.5
    # let the filter settle for ~5 RC (whole periods) before the plot window,
    # so the shown response is the periodic steady state (symmetric charge/discharge)
    t_settle = np.ceil(5 * RC * f) / f
    t = np.linspace(-t_settle, 10, int((t_settle + 10) * 100) + 1)
    square_wave = U_in * signal.square(2 * np.pi * f * t)

    system = signal.lti([1], [RC, 1])
    _, yout, _ = signal.lsim(system, U=square_wave, T=t - t[0])

    shown = t >= 0
    fig, ax = plt.subplots(figsize=(8, 4))
    ax.plot(t[shown], square_wave[shown], label='Input', color='blue', linewidth=2, linestyle='-')
    ax.plot(t[shown], yout[shown], label=f'Output RC={RC:.2f}', color='red', linewidth=2, linestyle='--')
    ax.set_title(f'Low-pass Filter: RC={RC:.2f}')
    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Voltage (V)')
    ax.grid(True)
    ax.legend()
    plt.show()

interact(plot_lowpass, RC=FloatSlider(value=0.5, min=0.05, max=10.0, step=0.05, description='RC'))
<function __main__.plot_lowpass(RC=0.5)>
def plot_highpass(RC=1.0):
    U_in = 1
    f = 0.5
    # let the filter settle for ~5 RC (whole periods) before the plot window,
    # so the shown response is the periodic steady state (symmetric charge/discharge)
    t_settle = np.ceil(5 * RC * f) / f
    t = np.linspace(-t_settle, 10, int((t_settle + 10) * 100) + 1)
    square_wave = U_in * signal.square(2 * np.pi * f * t)

    system = signal.lti([RC, 0], [RC, 1])
    _, yout, _ = signal.lsim(system, U=square_wave, T=t - t[0])

    shown = t >= 0
    fig, ax = plt.subplots(figsize=(8, 4))
    ax.plot(t[shown], square_wave[shown], label='Input', color='blue', linewidth=2, linestyle='-')
    ax.plot(t[shown], yout[shown], label=f'Output RC={RC:.2f}', color='red', linewidth=2, linestyle='--')
    ax.set_title(f'High-pass Filter: RC={RC:.2f}')
    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Voltage (V)')
    ax.grid(True)
    ax.legend()
    plt.show()

interact(plot_highpass, RC=FloatSlider(value=1.0, min=0.05, max=10.0, step=0.05, description='RC'))
<function __main__.plot_highpass(RC=1.0)>

Fig. 3.9 interactive plot: Depending on the comparison between RC time and (half) period of a block wave, the \(U_{out}\) will resemble \(U_{in}\) or not. Explore values of RC= 0.05, RC=0.5, and RC=5.#

3.2.4. Filters in frequency domain#

3.2.4.1. Low pass filter#

The capacitor’s impedance is frequency dependent, and therefore both the phase and the amplitude of the output voltage of an RC circuit depend on the frequency. The plot of amplitude and phase versus frequency is called a Bode plot.

To get a sense of such a plot, let’s evaluate the transfer at the extreme values of \(\omega\) for the RC circuit in Fig. 3.10. The extreme values are \(\omega \downarrow 0\) and \(\omega \uparrow \inf\).

../_images/ex2.svg

Fig. 3.10 Low pass filter.#

\[ \frac{U_{out}}{U_{in}} _{\omega \downarrow 0} = \frac {1}{1+j \omega R C} _{\omega \downarrow 0} =\frac{1}{1+0}= 1 \]
\[ \frac{U_{out}}{U_{in}} _{\omega \uparrow \infty} = \frac {1}{1+j \omega R C} _{\omega \uparrow \infty} =\frac{1}{1+\infty}= 0 \]

A high transfer for low frequency signals, and low transfer for high frequency signals implies a low pass filter.

At \(\omega _{cutoff} = \frac{1}{RC}\) the transfer dropped to the \(\frac{1}{1+j}\), of which the absolute value is \(\frac {1}{\sqrt (2)}\). This is the point where two approximating lines intersect: at lower frequencies the amplitude versus frequency is constant, after the \(\omega _{cutoff}\) the amplitude decreases with -20 dB/ decade or -6dB/ octave.

To complete the Bode plot, also the phase behavior needs to be investigated. For the low pass RC filter, the phase is equal to \(arctan(-\omega R C)\). When approximating the arctan with straight lines, the largest change in the two decades around \(\omega_{\text{cutoff}}\), with a phase of \(45^\circ\); so from \(0.1\,\omega_{\text{cutoff}}\) to \(10\,\omega_{\text{cutoff}}\). Below \(0.1\,\omega_{\text{cutoff}}\) the phase can be approximated with 0, and above \(10\,\omega_{\text{cutoff}}\) the phase can be approximated with \(-90^\circ\) or \(-\frac{\pi}{2}\).

Combining the frequency and phase behavior, and plotting the frequency and magnitude (amplitude) in logarithmic, or dB scale, the Bode plot for a low pass filter looks as follows.

Nothing

Hide code cell source

# ------------------------------------------------------------
# Slider range / default
# ------------------------------------------------------------
F_MIN = 10.0       # Hz
F_MAX = 1e6        # Hz
f_cutoff = 1.0 / (2 * np.pi * 1e3 * 100e-9)   # ~1.59 kHz


# ------------------------------------------------------------
# Plotting function
# ------------------------------------------------------------
def plot_lowpass(f_Hz):
    R = 1e3       # ohm
    C = 100e-9    # F
    U0 = 1.0      # input amplitude [V]

    # Transfer function: U_out / U_in = 1 / (1 + sRC)
    sys = signal.TransferFunction([1], [R * C, 1])
    ff = np.logspace(np.log10(F_MIN), np.log10(F_MAX), 600)
    _, mag_db, phase_deg = signal.bode(sys, w=2 * np.pi * ff)

    w = 2 * np.pi * f_Hz
    wRC = w * R * C

    # analytic sinusoidal steady state
    gain = 1.0 / np.sqrt(1 + wRC**2)
    phi = -np.arctan(wRC)

    # show 6 periods for the time axis
    n_show = 6
    cycles = np.linspace(0, n_show, 1200)
    Uin = U0 * np.sin(2 * np.pi * cycles)
    Uout = U0 * gain * np.sin(2 * np.pi * cycles + phi)

    mag_at_f = np.interp(np.log10(f_Hz), np.log10(ff), mag_db)

    # --- start: asymptotic approximations ---
    f_c = 1 / (2 * np.pi * R * C)  # corner frequency

    f_phase_start = f_c / 10
    f_phase_end = f_c * 10
   
    # ---------------------------------------

    fig, (ax_b, ax_t) = plt.subplots(1, 2, figsize=(12, 4.5))
    signal_color='blue'
    signal_color_assymptote='blue'# 'mediumblue'
    phase_color='purple'
    phase_color_assymptote = "purple"#"mediumpurple"

    # --------------------------------------------------------
    # Left: Bode plot (magnitude + phase)
    # --------------------------------------------------------

    
    #Exact Mag Response
    ax_b.semilogx(ff, mag_db, color=signal_color, linewidth=2, label="amplitude")
    
    # --------------------------------------------------------
    # Magnitude asymptote
    # --------------------------------------------------------

    # Segment 1: 0 dB before the cutoff frequency
    ax_b.semilogx( [F_MIN, f_c], [0, 0], color=signal_color_assymptote, linewidth=1.5, linestyle=":", label="amplitude asymptote") 

    # Segment 2: -20 dB/decade after the cutoff frequency
    ax_b.semilogx([f_c, F_MAX],[0, -20 * np.log10(F_MAX / f_c)],color=signal_color_assymptote,linestyle=":",linewidth=1.5)

    #----------------------------------------------------------
    ax_b.set_xlabel("Frequency (Hz)")
    ax_b.set_ylabel(r"$|U_{out}/U_{in}|$ (dB)", color=signal_color)
    ax_b.tick_params(axis="y", labelcolor=signal_color)
    ax_b.set_xlim(ff[0], ff[-1])
    ax_b.grid(True, which="both", alpha=0.3)

    ax_p = ax_b.twinx() 
    # Exact phase response
    ax_p.semilogx(ff, phase_deg, color=phase_color, linewidth=1.5, linestyle="-.", label=r"phase")
    
    # --------------------------------------------------------
    # Phase asymptote
    # --------------------------------------------------------

  

    # Segment 1: 0 degrees until fc / 10
    ax_p.semilogx([F_MIN, f_phase_start],[0, 0], color=phase_color_assymptote, linewidth=1.5,linestyle=":", label="phase asymptote")

    # Segment 2: straight line from 0 to -90 degrees
    ax_p.semilogx([f_phase_start, f_phase_end],[0, -90],color=phase_color_assymptote,linewidth=1.5,linestyle=":",alpha=0.8,)

    # Segment 3: -90 degrees after 10 fc
    ax_p.semilogx([f_phase_end, F_MAX],[-90, -90],color=phase_color_assymptote,linewidth=1.5,linestyle=":",alpha=0.8,)

    #---------------------------------------------------------------

   
    ax_p.set_ylabel("phase (deg)", color=phase_color)
    ax_p.tick_params(axis="y", labelcolor=phase_color)
    ax_p.set_ylim(-100, 10)
    ax_p.set_yticks([-90,-75,-60,-45,-30,-15,0])

    ax_b.axvline(f_Hz, color="red", linestyle="--", linewidth=1.2)
    ax_b.plot(f_Hz, mag_at_f, "o", color="red", markersize=6)
    ax_b.set_title("Bode overview")
    ax_b.set_ylim(-60,5)

    #combined legends
    # get handles and labels from both axes
    handles_b, labels_b = ax_b.get_legend_handles_labels()
    handles_p, labels_p = ax_p.get_legend_handles_labels()

    # create one combined legend on ax_b
    ax_b.legend(
    handles_b + handles_p,
    labels_b + labels_p,
    loc="upper right",
    frameon=True    )
# ``
#     ax_b.legend(loc="upper right", frameon=True)
#     ax_p.legend(loc="right", frameon=True)
    # --------------------------------------------------------
    # Right: time response (sinusoidal steady state)
    # --------------------------------------------------------
    ax_t.plot(cycles, Uin, color="blue", linewidth=1.5, linestyle="-", label=r"$U_{in}$")
    ax_t.plot(cycles, Uout, color="red", linewidth=2, linestyle="--", label=r"$U_{out}$")
    ax_t.axhline(0, color="black", linewidth=0.6)
    ax_t.set_xlabel("Time (periods)")
    ax_t.set_ylabel("Voltage (V)")
    ax_t.set_xlim(0, n_show)
    ax_t.set_ylim(-1.2 * U0, 1.2 * U0)
    ax_t.grid(True, alpha=0.3)
    ax_t.set_title(f"f = {f_Hz:.0f} Hz")
    ax_t.legend(loc="lower right", frameon=True)

    fig.tight_layout()
    plt.show()


# ------------------------------------------------------------
# Continuous (log) frequency slider
# ------------------------------------------------------------
interact(
    plot_lowpass,
    f_Hz=FloatLogSlider(
        value=f_cutoff,
        base=10,
        min=np.log10(F_MIN),
        max=np.log10(F_MAX),
        step=0.02,
        description="f (Hz)",
        continuous_update=False,
    ),
)
<function __main__.plot_lowpass(f_Hz)>

Fig. 3.11 interactive plot: Bode plot plus time domain of a Low Pass circuit. Check out \(U_{out}\) behaves in both time and frequency domain. Try to find the situation with phase 0, 45 and 90 degrees.#

3.2.4.2. High pass filter#

Similar to a low pass filter, a high pass filter can be created by switching the order of the resistor and capacitor in series.

../_images/ex3.svg

Fig. 3.12 High pass filter.#

Then the transfer becomes:

\[ \frac{U_{out}}{U_{in}}= \frac{j \omega RC}{j \omega RC +1} \]

Which then eventually leads to the following behavior in time domain (\(U_{out}\) has peaks before \(U_{in}\)), and the corresponding Bode plot.

Nothing

Hide code cell source

def plot_highpass(R=1e3):
    U0 = 1.0        # input amplitude [V]
    C = 10e-9       # capacitance [F]
    f = 10e3        # frequency [Hz]
    w = 2 * np.pi * f
    t = np.linspace(0, 700e-6, 2000)
    U_in = U0 * np.sin(w * t)

    wRC = w * R * C

    gain = wRC / np.sqrt(1 + wRC**2)   # |z|
    phi = np.pi / 2 - np.arctan(wRC)   # phase lead [rad]
    U_out = U0 * gain * np.sin(w * t + phi)

    fig, ax = plt.subplots(figsize=(8, 6))
    ax.plot(t * 1e6, U_in, color='blue', linewidth=2, linestyle='-', label=r'$U_{in}$')
    ax.plot(t * 1e6, U_out, color='red', linewidth=2, linestyle='--', label=r'$U_R$')

    ax.set_xlim(0, 700)
    ax.set_ylim(-1.0, 1.0)
    ax.set_xlabel('Time (µs)')
    ax.set_ylabel('Voltage (V)')
    ax.set_xticks(np.arange(0, 701, 140))
    ax.set_yticks(np.arange(-1.0, 1.01, 0.2))
    ax.grid(True, color='lightgray')
    ax.legend()
    plt.show()

interact(plot_highpass, R=FloatSlider(value=1e3, min=100, max=10e3, step=100, description='R (Ω)'))
<function __main__.plot_highpass(R=1000.0)>

Fig. 3.13 interactive plot: The input voltage \(U_{in}\) and output voltage \(U_R\) plotted versus time, with R= 1k \(\Omega\), C=10 nF, f=10 kHz.#

Nothing

Hide code cell source

# ------------------------------------------------------------
# Slider range / default
# ------------------------------------------------------------
F_MIN = 10.0       # Hz
F_MAX = 1e6        # Hz
f_cutoff = 1.0 / (2 * np.pi * 1e3 * 10e-9)   # ~15.9 kHz


# ------------------------------------------------------------
# Plotting function. All circuit/Bode data is computed INSIDE the
# function: in a shared kernel (the built book) a later cell would
# otherwise overwrite module-level globals (mag_db, C, ...) and this
# plot would silently render the wrong data.
# ------------------------------------------------------------
def plot_highpass(f_Hz):
    R = 1e3       # ohm
    C = 10e-9     # F
    U0 = 1.0      # input amplitude [V]

    # Transfer function: U_out / U_in = sRC / (1 + sRC)
    sys = signal.TransferFunction([R * C, 0], [R * C, 1])
    ff = np.logspace(np.log10(F_MIN), np.log10(F_MAX), 600)
    _, mag_db, phase_deg = signal.bode(sys, w=2 * np.pi * ff)

    w = 2 * np.pi * f_Hz
    wRC = w * R * C

    # analytic sinusoidal steady state
    gain = wRC / np.sqrt(1 + wRC**2)
    phi = np.pi / 2 - np.arctan(wRC)   # phase lead

    # show 6 periods in the time axis
    n_show = 6
    cycles = np.linspace(0, n_show, 1200)
    Uin = U0 * np.sin(2 * np.pi * cycles)
    Uout = U0 * gain * np.sin(2 * np.pi * cycles + phi)

    mag_at_f = np.interp(np.log10(f_Hz), np.log10(ff), mag_db)
    # --- start: asymptotic approximations ---
    f_c = 1 / (2 * np.pi * R * C)  # corner frequency

    f_phase_start = f_c / 10
    f_phase_end = f_c * 10


    fig, (ax_b, ax_t) = plt.subplots(1, 2, figsize=(12, 4.5))
    signal_color='blue'
    signal_color_assymptote='blue'# 'mediumblue'
    phase_color='purple'
    phase_color_assymptote = "purple"#"mediumpurple"
    # --------------------------------------------------------
    # Left: Bode plot (magnitude + phase)
    # --------------------------------------------------------
    ax_b.semilogx(ff, mag_db, color=signal_color, linewidth=2, label="amplitude")

    # --------------------------------------------------------
    # Magnitude asymptote
    # --------------------------------------------------------

    # Segment 1: 0 dB before the cutoff frequency
    ax_b.semilogx( [F_MIN, f_c], [20 * np.log10(F_MIN / f_c),0], color=signal_color_assymptote, linewidth=1.5, linestyle=":", label="amplitude asymptote") 

    # Segment 2: -20 dB/decade after the cutoff frequency
    ax_b.semilogx([f_c, F_MAX],[0, 0],color=signal_color_assymptote,linestyle=":",linewidth=1.5)

    #----------------------------------------------------------
    ax_b.set_xlabel("Frequency (Hz)")
    ax_b.set_ylabel(r"$|U_{out}/U_{in}|$ (dB)", color=signal_color)
    ax_b.tick_params(axis="y", labelcolor=signal_color)
    ax_b.set_xlim(ff[0], ff[-1])
    ax_b.grid(True, which="both", alpha=0.3)

    ax_p = ax_b.twinx()
    # Exact phase response
    ax_p.semilogx(ff, phase_deg, color=phase_color, linewidth=1.5, linestyle="-.", label="phase")

    # --------------------------------------------------------
    # Phase asymptote
    # --------------------------------------------------------

      # Segment 1: 0 degrees until fc / 10
    ax_p.semilogx([F_MIN, f_phase_start],[90, 90], color=phase_color_assymptote, linewidth=1.5,linestyle=":", label="phase asymptote")

    # Segment 2: straight line from 0 to -90 degrees
    ax_p.semilogx([f_phase_start, f_phase_end],[90, 0],color=phase_color_assymptote,linewidth=1.5,linestyle=":",alpha=0.8,)

    # Segment 3: -90 degrees after 10 fc
    ax_p.semilogx([f_phase_end, F_MAX],[0,0],color=phase_color_assymptote,linewidth=1.5,linestyle=":",alpha=0.8,)

    #---------------------------------------------------------------

    ax_p.set_ylabel("phase (deg)", color=phase_color)
    ax_p.tick_params(axis="y", labelcolor=phase_color)
    ax_p.set_ylim(-10, 100)
    ax_p.set_yticks([90,75,60,45,30,15,0])

    ax_b.axvline(f_Hz, color="red", linestyle="--", linewidth=1.2)
    ax_b.plot(f_Hz, mag_at_f, "o", color="red", markersize=6)
    ax_b.set_title("Bode overview")
    ax_b.set_ylim(-60,5)

    #combined legends
    # get handles and labels from both axes
    handles_b, labels_b = ax_b.get_legend_handles_labels()
    handles_p, labels_p = ax_p.get_legend_handles_labels()

    # create one combined legend on ax_b
    ax_b.legend(
    handles_b + handles_p,
    labels_b + labels_p,
    loc="right",
    frameon=True    )

    # --------------------------------------------------------
    # Right: time response (sinusoidal steady state)
    # --------------------------------------------------------
    ax_t.plot(cycles, Uin, color="blue", linewidth=1.5, linestyle="-", label=r"$U_{in}$")
    ax_t.plot(cycles, Uout, color="red", linewidth=2, linestyle="--", label=r"$U_{out}$")
    ax_t.axhline(0, color="black", linewidth=0.6)
    ax_t.set_xlabel("Time (periods)")
    ax_t.set_ylabel("Voltage (V)")
    ax_t.set_xlim(0, n_show)
    ax_t.set_ylim(-1.2 * U0, 1.2 * U0)
    ax_t.grid(True, alpha=0.3)
    ax_t.set_title(f"f = {f_Hz:.0f} Hz")
    ax_t.legend(loc="lower right", frameon=True)

    fig.tight_layout()
    plt.show()


# ------------------------------------------------------------
# Continuous (log) frequency slider
# ------------------------------------------------------------
interact(
    plot_highpass,
    f_Hz=FloatLogSlider(
        value=f_cutoff,
        base=10,
        min=np.log10(F_MIN),
        max=np.log10(F_MAX),
        step=0.02,
        description="f (Hz)",
        continuous_update=False,
    ),
)
<function __main__.plot_highpass(f_Hz)>

Fig. 3.14 interactive plot: Bode plot and time plot for an high-pass filter, with R= 1k \(\Omega\), C=10 nF, f=10 kHz. Find and compare the behavior at both plots, at phase 0, 45 and 90 degrees.#

3.3. Hands-on with Capacitors#

3.3.1. Coax cable#

A coaxial cable (coax in short) is a cable with an inner conductive core, surrounded by isolating material and a conductive shield. The shield is meant to keep signals inside the cable, and external EM fields outside the cable.

../_images/Coaxial_cable_cutaway.svg.png

Fig. 3.15 Coaxial cable.
Created by Tkgd2007, under CC BY 3.0, original link
#

Although not two parallel plates, one can imagine there can be a charge difference between the two conductors (shield, and inner core), leading to a capacitance value. This value is typically 100 pF/m. So, would it be better to use shorter, or longer coax cables?

Connecting coax cables to a circuit will impose (often) a low pass filter, thereby reducing the capability of measuring high frequency signals.

Example 3.4 (Numerical example influence coax cable)

Suppose a coax cable is used to measure the output of a voltage divider. Say the two resistors are 10 k\(\Omega\), the coax capacitance is 200 pF, and the contribution of \(R_{meter}\) is negligible.

../_images/measure_with_coax.svg

Fig. 3.16 The capacitance of the coax cable will be parallel to the bottom resistor.#

The cutoff angular frequency becomes \(\frac{1}{RC}\), and the cutoff frequency is equal to \(\frac{1}{2 \pi RC}\). The cutoff frequency is approximately 160 kHz, while \(R\) =10 k\(\Omega\) and \(C\)=200 pF suggest around 80 kHz.

Where does additional factor of two comes from?

3.3.2. Scope probe#

Since effectively using the coax cable means you lower the maximum frequency of signal you can measure, why not adapt the cable.

This is done by a scope probe, as shown below.

../_images/Test_probe.jpg

Fig. 3.17 The scope probe has a clip for the ground connection and a pin for the signal. It also has a certain attenuation, which can be compensated for by the oscilloscope.
Created by Nmnogueira, under CC BY_SA 2.5, original link: [upload.wikimedia.org/wikipedia/commons/thumb/1/11/Test_probe.jpg/500px-Test_probe.jpg]
#

The goal of a scope probe is to have less influence on the measurement than a coax cable. Two approaches are combined: 1. reduce the amount of capacitance in the cable, 2. increase the amount of resistance in the cable.

The schematic of a scope probe is as follows.

../_images/scope_probe_schematic.svg

Fig. 3.18 Resistors \(R_1\)&\(R_2\) are the resistors in the voltage divider, all the way at the right one finds \(R_{scope}\) of typically 1 M\(\Omega\), and \(C_{scope}\) of 10 pF. The other capacitors and resistors are in the scope probe. \(R_{probe}\) = 9 M\(\Omega\) for a 10x scope probe, and \(C_{probe1}\) is typically also 10 pF. What should be the value of \(C_{probe2}\)?#

In a 10x scope probe, the \(R_{probe}\) is chosen to be 9 M\(\Omega\) to match the 1 M\(\Omega\) \(R_{scope}\).

When looking at the DC behavior, the impedances of the capacitors at low frequency are very high, and can be left outside the consideration. In that case, the voltage over \(R_{scope}\) is 10 times lower than at the node between \(R_1\) and \(R_2\). To avoid distortion, this 10x attenuation should be maintained for higher frequencies as well. This requirement determines the value of \(C_{probe2}\). The derivation of this capacitor value can be done via AC analysis or matching RC times.

For AC analysis one gets:

\[ \frac{U_{scope}}{U_2}= \frac{ \frac{1}{j \omega (C_{probe2}+C_{scope})}} {\frac{1}{j \omega (C_{probe1})}}= \frac{C_{probe1}}{C_{probe2}+C_{scope}} \]

And you can derive that \(C_{probe2}+C_{scope}\) must be 90 pF.

Another way of deriving the correct value for \(C_{probe2}\) is to realize that the RC time of \(R_{probe}\) and \(C_{probe1}\) must match the RC time of \(C_{probe2}\), \(R_{scope}\) and \(C_{scope}\).

If the two RC times do not match, or said otherwise, if the AC and DC behavior does not match, one can get frequency dependent behavior. Such behavior results in distortion of the signal, clearly visible for an input block wave, as shown in the figure below.

Nothing

Hide code cell source

def plot_probe(C_probe2_pF=25.0):
    U_in = 1
    periode = 1e-3
    t = np.linspace(0, 3 * periode, 10000)

    C_probe1 = 10e-12
    C_scope = 45e-12 + 20e-12
    R_probe = 9e6
    R_scope = 1e6

    square_wave = U_in / 2 * (signal.square(2 * np.pi / periode * t) + 1)

    def _out(C_probe2):
        C_2 = C_probe2 + C_scope
        num = [R_scope * R_probe * C_probe1, R_scope]
        den = [R_probe * R_scope * (C_probe1 + C_2), R_probe + R_scope]
        sys = signal.TransferFunction(num, den)
        _, yout, _ = signal.lsim(sys, square_wave, t)
        return yout

    yout_calibrated = _out(25e-12)
    yout = _out(C_probe2_pF * 1e-12)

    fig, ax = plt.subplots(figsize=(8, 4))
    ax.plot(t * 1e3, yout_calibrated, label='Calibrated (25 pF)', color='blue', linewidth=2, linestyle='-')
    ax.plot(t * 1e3, yout, label=f'$C_{{probe2}}$ = {C_probe2_pF:.0f} pF', color='red', linewidth=2, linestyle='--')
    ax.set_title('Probe calibration')
    ax.set_xlabel('Time (ms)')
    ax.set_ylabel('Voltage (V)')
    ax.set_xlim(0, 3 * periode * 1e3)
    ax.grid(True)
    ax.legend()
    plt.show()

interact(plot_probe, C_probe2_pF=FloatSlider(value=50.0, min=1.0, max=100.0, step=1.0, description='C_probe2'))
<function __main__.plot_probe(C_probe2_pF=25.0)>

Fig. 3.19 interactive plot: Only when the scope probe is well calibrated, a block wave in will also give an undistorted block wave out. Vary the Cprobe2 values, try the extremes, and see whether you can find the optimal ‘correct’ capacitance value.#

Example 3.5 (Comparison coax cable and scope probe)

When measuring a voltage divider with two 10 k\(\Omega\) resistors, the RC time is \(\frac{10 k\Omega}{2} 200 pF\). This results in \(f_{cutoff}\)= 160 kHz.

Inside the scope probe the RC time of both parts match: 90 pF & 1 M\(\Omega\), or 10pF &9 M\(\Omega\). However, when measuring on a voltage divider with 10 k\(\Omega\) resistors, the scope probe hardly influences the overall resistance. It however influences the overall capacitance (replacing 10pF and 90 pF in series leads to 9 pF replacement capacitor). The effective \(f_{cutoff}\) becomes 3.5 MHz, improving the bandwidth effectively with a factor 20.

When the resistors in such divider become higher, the bandwidth will reduce further.

3.3.3. Variation in capacitors#

Capacitors can have many forms, sizes, and capacitances

../_images/Verschiedene_Kondensatoren_2.JPG

Fig. 3.20 Different capacitors, variation in size, capacity, and materials.
Created by Elcap, under CC BY-SA 3.0, original link
#

Depending on their material and size, there is a type of capacitor for each application, from V to kV and from pF to MF. Don’t let their size fool you; early Leyden jar of 0.6 liter can have 1 nF capacitance, while the diameter of a modern single layer ceramic capacitor can be around 3 mm, or smaller.

The dielectric capacitors are often named after their type of dielectric, such as polymer, ceramic, or metals.

Those dielectric capacitors are mainly non-polarized, meaning the orientation of the component in a device does not matter.

The principles behind electrolytic capacitors are different form other capacitor types. A very thin insulating oxide layer is electrochemically grown on the anode, and acts as the dielectric. Since the oxide only forms at the anode, this electrolytic capacitor is polarized, with a long (positive/ anode) pin and a short (negative/cathode) pin. Connecting this capacitor in the wrong orientation will degrade the oxide layer, causing a large increase in leakage current. If the current is not limited, the capacitor might get irreversibly damaged.

3.4. Capacitors in action#

3.4.1. Capacitive displacement sensor#

According to equation (3.2), the capacitance scales reciprocally with the distance. Therefore, a capacitor can be used for measurements varying distances between the two plates. For example volumes of water between two plates can be measured through capacitive sensing, but also a touchpad works in a similar way. Capacitive sensors can be also be used to measure the position of a microscope stage down to nanometer scale.

../_images/CapaSensorFig1.svg

Fig. 3.21 A capacitive sensor makes use of the variation of either spacing or area between two plates of the capacitor. According to equation (3.2) the capacitance depends on area \(A\) and distance \(d\). This capacitance value can be measured by placing the capacitor in series with a resistor, and from the step response determine the RC time, and therefore the capacitance value.#

3.4.2. Microphone#

When one of the two plates of a capacitor moves in response to a sound wave, its capacitance changes. Such a capacitor can be uA change in voltage let the plates of the piezo electrsed to convert sound to an electrical signal.

When this capacitor is placed in series with a DC power supply and a resistor and the output is measured across the resistor, similar to Fig. 3.12, changes in capacitance due to changes in sound result in voltage fluctuations. This circuit acts as high pass filter, so only the AC fluctuations reach the output. This type of microphone is therefore called DC-bias condenser microphone.

Another type of microphone uses piezo-electrical elements. When these elements are mechanically deformed, they generate a voltage. The reverse is also true, when applying a voltage, the piezo element slightly deforms. The piezo elements in handheld gas lighters generate such high voltage upon mechanical impact, that a spark can be generated. When the motion of the microphone’s diaphragm is coupled to the motion of piezo electric, then the generated voltage is a direct translation of sound.

../_images/SchemaPiezo.gif

Fig. 3.22 A change in voltage let the plates of the piezo electric element move, or vice versa, upon movement of the piezo electric plates, a voltage is generated.
Created by Tizeff, under CC BY-SA 3.0 , original link
#

3.4.3. Transesophageal probe#

The most commonly used non-invasive tool for cardiac imaging is transthoracic ultrasound. Although ultrasound is nice for imaging soft tissue, ultrasound is highly attenuated by ribs (bones) or lungs (filled with air). Therefore, better images are made when imaging with a transesophagael probe, which reaches much closer to the heart. While an external probe can hold a thick cables, the esophagus limits the size of the cables. Ultrasound is generated and detected with piezo electric elements, which convert electrical energy into motion, and vice versa. In order to reduce the cable to the transesophagael probe, one may use beam steering. With beam steering the transducer array is already pre-aligned to observe a location in space. The pre-alignment is done with help of a delay line, with a series of different capacitors which can be selected remotely.

../_images/transesophagol.svg

Fig. 3.23 A transesophagael probe uses ultrasound closer to the heart, by having a probe in the esophagus. Remotely controlled RC times, pre-steer the ultrasound beam, and reduce the amount of cables from the probe.#

Contains images from:

3.4.4. Membranes and nanopores#

There can be a voltage difference between two sides of a biological membrane. The membrane will act as a capacitor, with different charges on either side of the membrane. Ions can still be transported into a cell, across a membrane, through ion channels. This complex can be modelled as in Fig. 3.24.

../_images/Cell_membrane_equivalent_circuit.svg

Fig. 3.24 A (biological) membrane can be modelled with a capacitor, with variable resistors for the four ion pathways#

When conducting electric measurements on membranes, such as in nanopores, the membrane capacitance and pore resistance will vary per pore. Before analyzing the data, one should remove the capacitive charging currents (around 1 \(\mu\)A) which originate from changes in the applied voltage. Only then the much smaller sequence dependent current (around 100 pA) can be measured [ thesis Thijn Hoekstra].

3.4.5. CCD: charged coupled device#

In a CCD camera, photons are converted into electrons on a semiconductor-oxide interface. These electrons are read out after a single output amplifier. The transfer of the charge on each pixel is done in a sort bucket brigade, or pixel chain. The charge can move to a neighboring spot, by applying voltage to a neighboring capacitor, see Fig. 3.25. Just before reaching the readout, the charge is amplified.

../_images/CCD_charge_transfer_animation.gif

Fig. 3.25 The functioning of a shift register, using capacitors to move charge from one pixel to the next, to eventually the readout: a charge amplifier.
Created by Michael Schmid, under CC BY 2.5, original link
#

In sensitive microscopes electron-multiplying CCDs, or EMCCDs, are used. The number of photons is really small, and therefore need to be multiplied before being readout. EMCCDs often have a storage area, such that a new image can be acquired during the readout of the previous image, which takes around 1 ms. Additionally, the electrons are multiplied between the shift register and the output amplifier. The readout noise, which is a few electrons, is now imposed upon a multiplied number of electrons (few thousand), and therefore can be neglected. Compared to the regular CCD, the EMCCD is thus more sensitive to low photon numbers, and has a reduced readout noise. One might imagine that care has to be taken to not overexpose an EMCCD, since then the pixels become oversaturated, and the excess of charge leaks to neighboring pixels, or (worse) damage the EMCCD.

../_images/330px-EMCCD2_color_en.svg.png

Fig. 3.26 Within an EMCCD the number of electrons are multiplied
Created by Jsanchezd, under CC BY-SA 3.0, original link
#

3.5. Capacitor Exercises#

Exercise 3.1 (combine capacitors 1)

In the following circuit \(C_1\)=5 mF and \(C_2\)=10 mF.

Derive the overall impedance for the two combinations of capacitors.

../_images/ex6.svg

Fig. 3.27 \(C_1\)=5 mF and \(C_2\)=10 mF.#

Exercise 3.2 (combine capacitors 2)

In the following circuit \(C_1\)=20 mF, \(C_2\)=10 mF and \(C_3=40 mF\).

Derive the overall capacitance for the two combinations of three capacitors.

../_images/ex7.svg

Fig. 3.28 \(C_1\)=20 mF, \(C_2\)=10 mF and \(C_3=40 mF\).#

Exercise 3.3 (combine capacitors 3)

In the following circuit \(C_1\)=20 mF, \(C_2\)=10 mF, \(C_3\)=40 mF and \(C_4\)=30 mF.

Derive the overall capacitance for the two combinations of four capacitors.

../_images/ex8.svg

Fig. 3.29 \(C_1\)=20 mF, \(C_2\)=10 mF, \(C_3=40 mF\) and \(C_4=30 mF\)#

Exercise 3.4 (RC circuit switch closes 1)

In the following circuit R=50 \(\Omega\) and C= 5 mF. At t=0 the switch is closed.

a) Define the current \(I_C\) and voltage \(U_C\) directly after the switch is closed

b) Define the current \(I_C\) and voltage \(U_C\) very long time after the switch is closed

c) Write down the formula for \(I_C(t)\), depending on \(I_C(t=0), t, R, C\)

../_images/ex4.svg

Fig. 3.30 Assume R=50 \(\Omega\) and C= 5 mF. At t=0 the switch closes#

Exercise 3.5 (RC circuit switch closes 2)

In the following circuit R=10 \(k\Omega\), C= 5 mF, \(U_{source}\)= 2 V. At t=0 the switch is closed.

a) Write down the formula for \(U_C(t)\).

b) Calculate what \(U_C(t)\) will be at t=10 s

../_images/ex4.svg

Fig. 3.31 Assume R=10 k\(\Omega\) and C= 5.0 mF. At t=0 the switch closes.#

Exercise 3.6 (RC circuit switch opens)

In the following circuit R=50 \(\Omega\) and C= 5 mF. Before t=0, the capacitor is maximally charged. At t=0 the switch opens.

a) Describe qualitatively what will happen with \(U_C\)?

b) In order to discharge the capacitor when the switch opens, you have to adapt the circuit by adding a component. Describe and explain this modification.

c) Discuss the value of the component you add, what are the pros and cons for a high (10k \(\Omega\)) or low (50 \(\Omega\)) value? Take both the charge and possibe discharge into account.

../_images/ex4.svg

Fig. 3.32 Assume R=50 \(\Omega\) and C= 5 mF. At t=0 the capacitor is fully charged, and the switch opens#

Exercise 3.7 (RC filter 1)

In the following circuit R=100 k\(\Omega\) and C= 40 pF.

a) Derive the transfer \(\frac{U_{out}}{U_{in}}\)

b) Draw the frequency characteric (amplitude versus frequency), both axis logarithmically

c) What is the value (in dB) of the transfer \(\frac{U_{out}}{U_{in}}\) at \(\omega=\frac{1}{RC}\)?

../_images/ex2.svg

Fig. 3.33 R=100 k\(\Omega\) and C= 40 pF#

Exercise 3.8 (RC filter 2)

In the following circuit R=10 k\(\Omega\) and C= 40 nF.

a) Derive the transfer \(\frac{U_{out}}{U_{in}}\)

b) Draw the frequency characteric (amplitude versus frequency), both axis logarithmically

c) What is the slope in the frequency characteristic?

../_images/ex3.svg

Fig. 3.34 R=10 k\(\Omega\) and C= 40 nF#

Exercise 3.9 (RC filter 3)

In the following circuit R=1 k\(\Omega\) and both Cs have value 25 \(\mu\) F. When inputting \(U_{in}\) on the left side, and measuring \(U_{out}\) on the right side, explain qualitatively how the circuit behaves for:

a) an AC signal, a sine with amplitude 1V and frequency 1 kHz.

b) an step from 0 to 1 V (initiating DC signal).

../_images/ex1.svg

Fig. 3.35 R=1 k\(\Omega\) and C= 25 \(\mu\)F#

Exercise 3.10 (Marx generator)

Explore how you can build up a high voltage from a low voltage DC voltage supply with a train of capacitors. In this circuit all resistors are placed horizontally, connected by vertical capacitors and diagonal spark gaps.

a) Explain current and charges when the spark gaps are blocking current

b) Explain what happens when the spark gaps break (meaning they are passing currents). Assume that the first spark gap will break down first, due to a trigger. Now what will happen with the other spark gaps?

../_images/ex5.svg

Fig. 3.36 Marx generator#

Exercise 3.11 (Combined filter)

With a resistor and capacitor one can build a low pass and a high pass filter. But what happens if you combine these two?

../_images/ex9.svg

Fig. 3.37 Combined filter, consisting of two filters in series.#

a) Explain which of the two filters (part 1 or part 2) is the low pass filter.

b) Draw the qualitative frequency responses of these two filters (amplitude versus frequency plot) for:

  • \(R_1 C_1\) = \(R_2 C_2\)

  • \(R_1 C_1\) >> \(R_2 C_2\)

  • \(R_1 C_1\) << \(R_2 C_2\)