Saturday, May 14, 2022

Two port parameters

This post describes the calculation of two port parameters derived from the circuit's netlist. A Two-port network is a circuit that has two pairs of ports or terminals and the circuit is characterized by the currents and voltages at the ports by a 2 by 2 matrix. From a two port matrix the response of the network to signals applied to the ports to be calculated easily, without solving for all the internal voltages and currents in the network. For example filters, matching networks, transmission lines, and transistors are characterized by two port parameters.

The first circuit is an attenuator, which could be easily analyzed by hand with a pencil, paper and a calculator, but here I'm using python to step through the calculations. These same steps can be applied to larger, more complex circuits which would be difficult to analyze by hand. The Sympy and SciPy libraries can be used to obtain symbolic and numerical results, however as is shown below, when the circuit is large, symbolic results are not that useful nor do they provide much insight.

The procedure starts by first drawing a schematic of the circuit with a schematic capture program such as EasyEDA (links to the schematics are provided in the notebook, linked below) then the netlist is generated and exported as a text file. The netlist is used to generate modified nodal equations with the python program described here. The equations are solved for voltages and currents at the port terminals by using SymPy to generate the z-paramters. Z-parameters are also known as open-circuit impedance parameters as they are calculated under open circuit conditions. Once the z-parameters are obtained, these can be converted into other parameters, such as Y, H or S. 

The second circuit is a band pass filter. The filter is designed from a low pass prototype by using normalized values from a filter design handbook.  Z and s-parameters are calculated and the results are plotted using Matplotlib.


To view the notebook click here to open the notebook viewer.

The JupyterLab notebook is located on github, click here to following the link to the repository.


Saturday, May 7, 2022

Source free series circuit

In this post, the Python modules SymPy and SciPy are used to solve for currents and voltages in a series connected circuit with a resistor, inductor and capacitor. The characteristic differential equation for the circuit is derived and solutions are obtained with SymPy and SciPy. 

A source free series RLC circuit consists of a resistor, capacitor and inductor connected in series with some initial energy stored either in the inductor, capacitor or both. Since the circuit is a single loop, the current flowing around the loop is the same current in each component. Both parallel and series connected circuits are usually presented in electrical circuit analysis classes. The two textbooks I used while in college presented the parallel connected circuit in some detail then kind of glossed over the series connect circuit since it is the dual of the other. 

The schematic for the series connected circuit is shown below.

A Jupyter notebook with the python code was used to document the analysis. To view the notebook, click here to open the notebook nbviewer (nbviewer does not execute notebooks, it only renders the inputs and outputs).

The notebook source is located on github, click here to follow the link to the repository.





Saturday, March 5, 2022

Coupled inductor circuits

 Last update: 4 July 2022

This blog post summarizes the results from my Jupyter notebook, which can be viewed here. The notebook is hosted on Github.  

The Jupyter notebook examines coupled inductor circuits. Numeric and symbolic solutions are obtained for the voltages and currents in the circuits. The first circuit specifies the inductor values and the coupling in terms of mutual inductance. The second circuit is of a traditional transformer circuit where the turns ratio is given and the coupling constant is assumed to be 1.  

A coupled inductor has two or more windings that are connected by a magnetic circuit. Coupled inductors transfer energy from one winding to a different winding usually through a common core. The efficiency of the magnetic coupling between both the windings is defined by the coupling factor k or by mutual inductance. The coupling constant and the mutual inductance are related by the equation:

Where k is the coupling coefficient and in spice the value of k can be from -1 to +1 to account negative phase relation. Phase dots are drawn on the schematic to indicate the relative direction of the windings.  In LTspice the phase dots are associated with the negative terminal of the winding.

Coupled inductor circuit 1 is shown below. The circuit was drawn in LTspice and both the schematic and net list were exported. The inductors L1 and L2 are coupled with a mutual inductance of 0.5j. 


Coupled inductor circuit 2 is shown below. This circuit has two independent voltage sources and a transformer. The turn ratio of the transformer is specified as 1:2 and the coupling constant is assumed to be 1.


For both circuits, the solutions obtained with Python were verified with results obtained from LTspice.

Reference: https://en.wikipedia.org/wiki/Inductance#Mutual_inductance





Tuesday, February 22, 2022

Nodal analysis of a RLC circuit with controlled sources

Consider the circuit below, which contains independent and dependent current and voltage sources. The circuit is from [1], Figure 4.8. Circuit analysis is a fundamental part of electrical engineering and this post describes using Python to analyze electrical circuits. The schematic of the circuit was redrawn in LTspice [2].


The zero volt source, V2, was added to the schematic so that the current through R4 could be measured since this current controls H1. The voltages and currents in the circuit were solved for in a Jupyter notebook running Python and using the SymPy and SciPy libraries. The netlist is used to generate modified nodal equations with the python program described here. To view the notebook click here, to open the notebook viewer. The Jupyter notebook is located on github, click here, to follow the link to the repository.

References  

1. Basic Electric Circuit Analysis, D. E. Johnson, J. L. Hilburn, and J. R. Johnson, Prentice-Hall, 1978

2. https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice-simulator.html

Wednesday, February 16, 2022

Thevenin equivalent circuit

The Thevenin equivalent circuit is the reduction of a linear one port circuit to a single source and impedance and is based on Thevenin’s Theorem. This notebook describes solving problem 11.25, given in chapter 11 of [1]. The Python libraries of SimPy and Numpy are used to perform the math in the proposed solution. The problem asks the student to replace the circuit to the left of terminals a-b by its Thevenin equivalent and find V. The schematic was drawn using LTspice [2] and the nodes were numbered. Terminals a-b are across the resistor R3. The circuit given in the textbook does not include a reference node, however the node at the bottom of the schematic was chosen as the reference node, ground.


Having drawn the circuit in LTspice, the netlist was exported as a text file. The solution is worked out in the jupyter notebook which can be viewed here. 

The Jupyter notebook is located on github, click here to follow the link to the repository.


Reference

1. Basic Electric Circuit Analysis, D. E. Johnson, J. L. Hilburn, and J. R. Johnson, Prentice-Hall, 1978

2. LTspice, last accessed on 2/24/2022.