Pole and zero calculator

This calculator can be used to determine the poles, zeros, and transfer function of a passive linear filter circuit (i.e. a filter consisting of only inductors, capacitors, and resistors). I will also describe how the calculator works.

Calculator

Paste in the text file of the circuit from https://www.falstad.com/afilter/circuitjs.html (go to File > Export as Text):

Frequency units:
Format:
Decimal places:
Pole
Zero
Transfer function:
TermCoefficient
Numerator
Denominator

Inductance, capacitance, and resistance matrices

Consider the following circuit:
This circuit has 5 nodes (\(V_i\), \(V_g\), \(V_1\), \(V_2\), and \(V_3\)) and 5 components. Recall that the impedance of an inductor is \(j\omega L\) and the impedance of a capacitor is \(\frac{1}{j\omega C}\). Thus, for example, the current through \(L_1\) is \(\frac{V_i - V_3}{j\omega L}\). For nodes \(V_1\), \(V_2\), and \(V_3\), we want to calculate the total current flowing into the node. By Kirchoff's current law (KCL), the total currents flowing into each node must be zero (i.e. what comes in must come out). Thus, we get the following equations: $$ I_i = \frac{V_3 - V_i}{j\omega L_1} $$ $$ I_g = \frac{V_1 - V_g}{j\omega L_2} + \left(V_1 - V_g\right)\left(j\omega C_2\right) $$ $$ I_1 = \frac{V_g - V_1}{j\omega L_2} + \left(V_g - V_1\right)\left(j\omega C_2\right) + \left(V_2 - V_1\right)\left(j\omega C_1\right) $$ $$ I_2 = \frac{V_3 - V_2}{R} + \left(V_1 - V_2\right)\left(j\omega C_1\right) $$ $$ I_3 = \frac{V_i - V_3}{j\omega L_1} + \frac{V_2 - V_3}{R} $$ These can be rewritten as a matrix equation: $$ \begin{bmatrix} I_i \\ I_g \\ I_1 \\ I_2 \\ I_3 \end{bmatrix} = \begin{bmatrix} -\frac{1}{j\omega L_1} & 0 & 0 & 0 & \frac{1}{j\omega L_1} \\ 0 & -\frac{1}{j\omega L_2} - j\omega C_2 & \frac{1}{j\omega L_2} + j\omega C_2 & 0 & 0 \\ 0 & \frac{1}{j\omega L_2} + j\omega C_2 & -\frac{1}{j\omega L_2} - j\omega C_2 - j\omega C_1 & j\omega C_1 & 0 \\ 0 & 0 & j\omega C_1 & -j\omega C_1 - \frac{1}{R} & \frac{1}{R} \\ \frac{1}{j\omega L_1} & 0 & 0 & \frac{1}{R} & -\frac{1}{R}-\frac{1}{j\omega L_1} \end{bmatrix} \begin{bmatrix} V_i \\ V_g \\ V_1 \\ V_2 \\ V_3 \end{bmatrix} $$ This can be expanded as: $$ \begin{bmatrix} I_i \\ I_g \\ I_1 \\ I_2 \\ I_3 \end{bmatrix} = \left(\frac{1}{j\omega} \begin{bmatrix} -\frac{1}{L_1} & 0 & 0 & 0 & \frac{1}{L_1} \\ 0 & -\frac{1}{L_2} & \frac{1}{L_2} & 0 & 0 \\ 0 & \frac{1}{L_2} & -\frac{1}{L_2} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ \frac{1}{L_1} & 0 & 0 & 0 & -\frac{1}{L_1} \end{bmatrix} + \begin{bmatrix} 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & -\frac{1}{R} & \frac{1}{R} \\ 0 & 0 & 0 & \frac{1}{R} & -\frac{1}{R} \end{bmatrix} + j\omega\begin{bmatrix} 0 & 0 & 0 & 0 & 0 \\ 0 & -C_2 & C_2 & 0 & 0 \\ 0 & C_2 & -C_2-C_1 & C_1 & 0 \\ 0 & 0 & C_1 & -C_1 & 0 \\ 0 & 0 & 0 & 0 & 0 \end{bmatrix}\right)\begin{bmatrix} V_i \\ V_g \\ V_1 \\ V_2 \\ V_3 \end{bmatrix} $$ By KCL, \(I_1 = I_2 = I_3 = 0\). However, \(I_i\) and \(I_g\) are not necessarily zero, as these nodes are fed by sources, and the currents from thouse sources are not accounted for. Thus, the rows corresponding to \(I_i\) and \(I_g\) can be removed. The voltage at \(V_g\) (ground) is also known to be zero and the voltage at \(V_i\) is defined to be 1. The columns in the matrices corresponding to \(V_i\) can be moved to the other side. $$ -\frac{1}{j\omega}\begin{bmatrix} 0 \\ 0 \\ \frac{1}{L_1} \end{bmatrix} = \left(\frac{1}{j\omega} \begin{bmatrix} -\frac{1}{L_2} & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & -\frac{1}{L_1} \end{bmatrix} + \begin{bmatrix} 0 & 0 & 0 \\ 0 & -\frac{1}{R} & \frac{1}{R} \\ 0 & \frac{1}{R} & -\frac{1}{R} \end{bmatrix} + j\omega\begin{bmatrix} -C_2-C_1 & C_1 & 0 \\ C_1 & -C_1 & 0 \\ 0 & 0 & 0 \end{bmatrix}\right)\begin{bmatrix} V_1 \\ V_2 \\ V_3 \end{bmatrix} = \left(\frac{1}{j\omega}\boldsymbol{L} + \boldsymbol{R} + j\omega\boldsymbol{C}\right)\begin{bmatrix} V_1 \\ V_2 \\ V_3 \end{bmatrix}$$ For the rest of this article, I will use \(s\) instead of \(j\omega\) to somewhat simplify the formulas. Mutliply through by \(s\): $$ \begin{bmatrix} 0 \\ 0 \\ \frac{1}{L_1} \end{bmatrix} = \left(\boldsymbol{L} + s\boldsymbol{R} + s^2\boldsymbol{C}\right)\begin{bmatrix} V_1 \\ V_2 \\ V_3 \end{bmatrix} $$ Notice that each of the matrices \(\boldsymbol{L}\), \(\boldsymbol{R}\), and \(\boldsymbol{C}\) can be written as the sum of constant matrices times a component value. For example, \(\boldsymbol{C}\) can be decomposed as: $$ \boldsymbol{C} = C_1 \begin{bmatrix} -1 & 1 & 0 \\ 1 & -1 & 0 \\ 0 & 0 & 0 \end{bmatrix} + C_2 \begin{bmatrix} -1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix} $$ In general, the circuit matrix of a circuit consisting of \(k\) components can be written as: $$ \boldsymbol{M} = \boldsymbol{L} + s\boldsymbol{R} + s^2\boldsymbol{C} = \sum_{i=1}^k K_i\boldsymbol{D}_i s^{P_i} $$ where \(\boldsymbol{D}_i\) is a constant matrix as described above, \(K_i\) is the corresponding component value (either 1/resistance, 1/inductance, or capacitance), and \(P_i\) is the power of \(s\) corresponding to that component (0 for inductors, 1 for resistors, and 2 for capacitors). For this example, I will use \(K_1=\frac{1}{L_1}\), \(K_2=\frac{1}{R}\), \(K_3=C_2\), \(K_4=\frac{1}{L_2}\), \(K_5=C_2\).

The current vector can be decomposed similarly: $$ \vec{M} = \sum_{i=1}^k K_i\vec{D}_i s^{P_i} $$ Thus, the following general form can be used to represent any circuit with any number of nodes: $$ \vec{M} = \left(\boldsymbol{M}\right)\vec{V} $$ We can now solve for \(\vec{V}\), but the circuit only has one output, \(V_1\). Thus, we can use Cramer's rule to find the voltage at that node only. $$ V_1(s) = \frac{\det\left(\boldsymbol{M'}\right)}{\det\left(\boldsymbol{M}\right)} $$ where \(\boldsymbol{M'}\) is \(\boldsymbol{M}\) with the first column replaced with \(\vec{M}\). This formula now gives the transfer function of the filter circuit. Recall that the poles of this circuit are values of \(s\) such that \(V_1(s) = \pm\infty\) and the zeros are values of \(s\) such that \(V_1(s)=0\). (For now, I will only focus on the poles. The zeros can be calculated in a similar way). Since \(\det\left(\boldsymbol{L} + s\boldsymbol{R} + s^2\boldsymbol{C}\right)\) is the denominator of the transfer function, poles occur when \(\det\left(\boldsymbol{L} + s\boldsymbol{R} + s^2\boldsymbol{C}\right)=0\).

Relation to generalized eigenvalues

Recall that the eigenvalues of a matrix are the roots of the polynomial \(\det\left(\boldsymbol{A} - \lambda\boldsymbol{I}\right)\). This looks similar to \(\det\left(\boldsymbol{L} + s\boldsymbol{R} + s^2\boldsymbol{C}\right)=0\), but we will need a generalized version of this formula if we want to use it to find the poles of a circuit. Generalized eigenvalues are solutions to the polynomial \(\det\left(\boldsymbol{P} - \lambda\boldsymbol{Q}\right)\). We can define $$ \boldsymbol{P} = \begin{bmatrix} \boldsymbol{0} & \boldsymbol{I} \\ \boldsymbol{L} & \boldsymbol{R} \end{bmatrix} $$ and $$ \boldsymbol{Q} = \begin{bmatrix} \boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{-C} \end{bmatrix} $$ Each generalized eigenvalue/eigenvector pair must satisfy $$ \boldsymbol{P}\vec{\phi} = s\boldsymbol{Q}\vec{\phi} $$ We can expand this, replacing \(\vec{\phi}\) with \(\begin{bmatrix} \vec{\phi_1} \\ \vec{\phi_2} \end{bmatrix}\): $$ \begin{bmatrix} \boldsymbol{0} & \boldsymbol{I} \\ \boldsymbol{L} & \boldsymbol{R} \end{bmatrix}\begin{bmatrix} \vec{\phi_1} \\ \vec{\phi_2} \end{bmatrix} = s\begin{bmatrix} \boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{C} \end{bmatrix}\begin{bmatrix} \vec{\phi_1} \\ \vec{\phi_2} \end{bmatrix} $$ $$ \left\{\begin{matrix} \vec{\phi_2} & = & s\vec{\phi_1} \\ \boldsymbol{L}\vec{\phi_1} + \boldsymbol{R}\vec{\phi_2} & = & -s\boldsymbol{C}\vec{\phi_2} \end{matrix}\right. $$ $$ \boldsymbol{L}\vec{\phi_1} + s\boldsymbol{R}\vec{\phi_1} + s^2\boldsymbol{C}\vec{\phi_1} = \vec{0} $$ The eigenvalues of \(\left(\boldsymbol{P},\boldsymbol{Q}\right)\) will then be the poles of the circuit, as they will satisfy \(\det\left(\boldsymbol{L} + s\boldsymbol{R} + s^2\boldsymbol{C}\right)=0\). Generalized eigenvalues are computed using the QZ algorithm (I used the version described in Matrix Computations by Golub and Van Loan). The QZ algorithm runs in O(n3) time and the polynomials are generated in O(n2) time from the poles and zeros. Evaluating the leading coefficients of the polynomials takes O(n3) time since the determinants of the circuit matrices must be calculated.

Comments

Popular posts from this blog

Controlling a ceiling fan and light with an Arduino

Improving and calibrating the capacitive water sensor