# Circuit Analysis¶

## Introduction¶

Lcapy can only analyse linear time invariant (LTI) circuits, this includes both passive and active circuits. Time invariance means that the circuit parameters cannot change with time; i.e., capacitors cannot change value with time. It also means that the circuit configuration cannot change with time, i.e., contain switches (although switching problems can be analysed, see Switching analysis).

Linearity means that superposition applies—if you double the voltage of a source, the current (anywhere in the circuit) due to that source will also double. This restriction rules out components such as diodes and transistors that have a non-linear relationship between current and voltage (except in circumstances where the relationship can be approximated as linear around some constant value—small signal analysis). Linearity also rules out capacitors where the capacitance varies with voltage and inductors with hysteresis.

## Networks and netlists¶

Lcapy circuits can be created using a netlist specification (see Netlists) or by combinations of components (see Networks). For example, here are two ways to create the same circuit:

>>> cct1 = (Vstep(10) + R(1)) | C(2)

>>> cct2 = Circuit()
>>> cct2.add('V 1 0 step 10')


The two approaches have many attributes and methods in common. For example,

>>> cct1.is_causal
True
>>> cct2.is_causal
True
>>> cct1.is_dc
False
>>> cct2.is_dc
False


However, there are subtle differences. For example,

>>> cct1.Voc
5
──────
2   s
s  + ─
2

>>> cct2.Voc(2, 0)
5
──────
2   s
s  + ─
2


Notice, the second example requires specific nodes to determine the open-circuit voltage across.

## Linear circuit analysis¶

There is no universal analytical technique to determine the voltages and currents in an LTI circuit. Instead there are a number of methods that all try to side step having to solve simultaneous integro-differential equations. These methods include DC analysis, AC analysis, and Laplace analysis. Lcapy uses all three and the principle of superposition. Superposition allows a circuit to be analysed by considering the effect of each independent current and voltage source in isolation and summing the results.

If reactive components are found to have initial conditions, then the circuit is analysed as an initial value problem using Laplace methods. In this case, the sources are ignored for $$t<0$$ and the result is ony known for $$t\ge 0$$.

If the circuit has no initial conditions, Lcapy analyses all the independent sources and splits them into DC, AC, transient, and noise categories. The circuit is then analysed separately for each category and the results are combined.

### DC analysis¶

The simplest special case is for a DC independent source. DC is an idealised concept—it impossible to generate—but is a good approximation for very slowly changing sources. With a DC independent source the dependent sources are also DC and thus no voltages or currents change. Thus capacitors can be replaced with open-circuits and inductors can be replaced with short-circuits. Note, each node must have a DC path to ground otherwise the circuit cannot be solved.

### AC analysis¶

AC, like DC, is an idealised concept. It allows circuits to be analysed using phasors and impedances. The use of impedances avoids solving integro-differential equations in the time domain.

### Laplace analysis¶

The response due to a transient excitation from an independent source can be analysed using Laplace analysis. This is what Lcapy was originally designed for. Since the unilateral transform is not unique (it ignores the circuit behaviour for $$t < 0$$), the response can only be determined for $$t \ge 0$$.

If the independent sources are known to be causal (a causal signal is zero for $$t < 0$$ analogous to a causal impulse response) and the initial conditions (i.e., the voltages across capacitors and currents through inductors) are zero, then the response is 0 for $$t < 0$$. Thus in this case, the response can be specified for all $$t$$.

The response due to a general non-causal excitation is hard to determine using Laplace analysis. One strategy is to use circuit analysis techniques to determine the response for $$t < 0$$, compute the pre-initial conditions, and then use Laplace analysis to determine the response for $$t \ge 0$$. Note, the pre-initial conditions at $$t = 0_{-}$$ are required. These differ from the initial conditions at $$t = 0_{-}$$ whenever a Dirac delta (or its derivative) excitation is considered. Determining the initial conditions is not straightforward for arbitrary excitations and at the moment Lcapy expects you to do this!

The use of pre-initial conditions also allows switching circuits to be considered (see Switching analysis). In this case the independent sources are ignored for $$t < 0$$ and the result is only known for $$t \ge 0$$.

Note if any of the pre-initial conditions are non-zero and the independent sources are causal then either we have an initial value problem or a mistake has been made. Lcapy assumes that if all the inductors and capacitors have explicit initial conditions, then the circuit is to be analysed as an initial value problem with the independent sources ignored for $$t \ge 0$$. In this case a DC source is not DC since it is considered to switch on at $$t = 0$$.

### Switching analysis¶

Whenever a circuit has a switch it is time variant. The opening or closing of switch changes the circuit and can produce transients. While a switch violates the LTI requirements for linear circuit analysis, the circuit prior to the switch changing can be analysed and used to determine the initial conditions for the circuit after the switched changed. Lcapy requires that you do this! The independent sources are ignored for $$t < 0$$ and the result is only known for $$t \ge 0$$.

### Noise analysis¶

Noise sources are assumed to be uncorrelated and so they are summed in quadrature (on a power basis). Lcapy analyses the circuit for each source independently and then combines the results.

Each resistor in a circuit can be converted into a series combination of an ideal resistor and a noise voltage source using the noise_model method.