Skip to main content

Section 3.8 Using Python in AC circuits

Just as with DC circuits, we can let Python do most of the mathematical manipulation for us when determining circuit behavior. As an example, we’ll examine the behavior of voltage gain and phase \(\phi=\phi_\text{out}-\phi_\text{in}\) for the circuit in Figure 3.8.1.
Figure 3.8.1. Bandgap RLC Circuit.
Using Kirchhoff’s laws and the branch method, we find the following equations
\begin{align*} \tilde{I}_1 - \tilde{I}_2 - \tilde{I}_3 \amp = 0 \\ \tilde{V}_\text{in} - \frac{1}{i \omega C} \tilde{I}_2 - R \tilde{I}_1 \amp = 0 \\ \tilde{V}_\text{in} - i\omega L \tilde{I}_3 - R \tilde{I}_1 \amp = 0 \text{.} \end{align*}
Rearranging these equations into
\begin{align*} \tilde{I}_1 - \tilde{I}_2 - \tilde{I}_3 \amp = 0 \\ R \tilde{I}_1 - \frac{i}{\omega C} \tilde{I}_2 \amp = \tilde{V}_\text{in} \\ R \tilde{I}_1 + i\omega L \tilde{I}_3 \amp = \tilde{V}_\text{in} \end{align*}
facilitates efforts to recast this system of equations as a matrix equation
\begin{equation*} \begin{pmatrix} 1 \amp - 1 \amp - 1 \\ R_1 \amp -\frac{i}{\omega C} \amp 0 \\ R_1 \amp 0 \amp i\omega L \end{pmatrix} \begin{pmatrix} \tilde{I}_1 \\ \tilde{I}_2 \\ \tilde{I}_3 \end{pmatrix} = \begin{pmatrix} 0 \\ \tilde{V}_\text{in} \\ \tilde{V}_\text{in} \end{pmatrix} \end{equation*}
which can be solved using Python:
Here, we have made use of the abs function in NumPy to find the voltage gain by measuring the magnitude of \(\tilde{V}_\text{out}/\tilde{V}_\text{in}\text{,}\) and we have used the angle function from Numpy to find the phase of \(V_\text{out}\) at an instant in time when \(V_\text{in}\) is purely real.
Examining the results of our analysis, we see that this circuit has \(G_v=1\) and \(\phi=0\) at both high and low frequencies. There is a frequency at [PROVIDE EQUATION] at which \(G_v=0\) and \(\phi=\pm\pi/2\text{.}\) This circuit is called an RLC bandgap filter as it allows signals at most frequencies through unchanged, but has a band (defined by values of L and C) where frequency components are cut out. This can be especially useful if there is a source of noise with a single well-defined frequency contaminating a signal.