zero.analysis.ac.base module

Base AC analysis tools

class zero.analysis.ac.base.BaseAcAnalysis(*args, **kwargs)[source]

Bases: zero.analysis.base.BaseAnalysis

Small signal circuit analysis

abstract calculate()[source]

Calculate solution.

circuit_equation_display(frequency=1)[source]

Get circuit equations

Parameters

frequency (float, optional) – Frequency to display circuit equations for.

circuit_matrix(frequency)[source]

Calculate and return matrix used to solve for circuit transfer functions for a given frequency

This constructs a sparse matrix containing the voltage and current equations for each component and node.

Parameters

frequency (Numpy scalar, float) – frequency at which to calculate circuit impedances

Returns

scipy.sparse.spmatrix – circuit matrix

Raises

ValueError – if an invalid coefficient type is encountered

circuit_matrix_display(frequency=1)[source]

Get circuit matrix

Parameters

frequency (float, optional) – Frequency to display circuit equations for.

component_equation(component)[source]

Equation representing circuit component

The component equation represents the component in the circuit matrix. It maps input or noise sources to voltages across nodes and currents through components in terms of their impedance and voltage coefficients.

Note that special behaviour is applied to op-amp voltage outputs if they are configured as voltage followers.

Returns

ComponentEquation – Component equation containing coefficients.

property component_equations

Linear equations representing circuit components

Yields

ComponentEquation – component equation

component_index(component)[source]

Get component serial number.

Parameters

component (Component) – component

Returns

int – component serial number

Raises

ValueError – if component not found

component_matrix_index(component)[source]

Circuit matrix index corresponding to a component

Parameters

component (Component) – component to get index for

Returns

int – component index

property dim_size

Circuit matrix dimension size

Returns

int – number of rows/columns in circuit matrix

property element_headers

Headers corresponding to circuit’s matrix elements.

Yields

str – column header

property element_names

Names of elements (components and nodes) within the circuit.

Yields

str – matrix element names

property elements

Matrix elements.

Returns a sequence of elements - either components or nodes - in the order in which they appear in the matrix

Yields

Component, Node – matrix elements

format_element(element)[source]

Format matrix element for pretty printing.

Determines if the specified element refers to a component current or a voltage node and prints information accordingly.

Parameters

element (Component, Node) – element to format

Returns

str – formatted element

Raises

ValueError – if element is invalid

get_empty_results_matrix(*depth)[source]

Get empty matrix of specified size

The results matrix always has n rows, where n is the number of components and nodes in the circuit. The column size, and the size of any additional dimensions, can be specified with subsequent depth parameters.

Parameters

depth (int) – size of index 1…x

Returns

mixed – empty results matrix

property mean_resistance

Average circuit resistance

property n_freqs
node_equation(node)[source]

Equation representing circuit node

This should be called after set_up_sources_and_sinks().

property node_equations

Linear equations representing circuit nodes

Yields

NodeEquation – sequence of node equations

node_index(node)[source]

Get node serial number.

This does not include the ground node, so the first non-ground node has serial number 0.

Parameters

node (Node) – node

Returns

int – node serial number

Raises

ValueError – if ground node is specified or specified node is not found

node_matrix_index(node)[source]

Circuit matrix index corresponding to a node

Parameters

node (Node) – node to get index for

Returns

int – node index

reset()[source]

Reset state of the analysis

reset_sources_and_sinks()[source]

Reset circuit’s sources and sinks

right_hand_side()[source]

Circuit signal excitation vector.

This creates a vector of size nx1, where n is the number of elements in the circuit, with all elements zero except for the excitation component, which is set to 1.

Returns

np.ndarray – The circuit’s excitation vector.

abstract property right_hand_side_index

Right hand side excitation component index

set_up_sources_and_sinks()[source]

Set up circuit’s sources and sinks

This inspects the circuit’s components and informs the circuit’s nodes about current inputs and outputs. Nodes cannot generate their own equations unless they know about

property solution
solve()[source]

Solve the circuit.

Solves matrix equation Ax = b, where A is the circuit matrix and b is the right hand side.

Returns

ndarray – The inverse of the circuit matrix.

validate_circuit()[source]

Validate circuit

class zero.analysis.ac.base.BaseCoefficient(value)[source]

Bases: object

Represents a coefficient.

Parameters

value (float) – Coefficient value.

TYPE = ''
class zero.analysis.ac.base.BaseEquation(coefficients)[source]

Bases: object

Represents an equation.

Parameters

coefficients (sequence of BaseCoefficient) – Coefficients that make up the equation.

add_coefficient(coefficient)[source]

Add coefficient to equation.

Parameters

coefficient (BaseCoefficient) – Coefficient to add.

class zero.analysis.ac.base.ComponentCoefficient(component, **kwargs)[source]

Bases: zero.analysis.ac.base.BaseCoefficient

Represents a component coefficient.

Parameters

component (Component) – Component this coefficient represents.

class zero.analysis.ac.base.ComponentEquation(component, **kwargs)[source]

Bases: zero.analysis.ac.base.BaseEquation

Represents a component equation.

Parameters

component (Component) – Component associated with the equation.

class zero.analysis.ac.base.CurrentCoefficient(component, **kwargs)[source]

Bases: zero.analysis.ac.base.ComponentCoefficient

Represents an current coefficient.

TYPE = 'current'
class zero.analysis.ac.base.ImpedanceCoefficient(component, **kwargs)[source]

Bases: zero.analysis.ac.base.ComponentCoefficient

Represents an impedance coefficient.

TYPE = 'impedance'
class zero.analysis.ac.base.NodeEquation(node, **kwargs)[source]

Bases: zero.analysis.ac.base.BaseEquation

Represents a node equation.

Parameters

node (Node) – Node associated with the equation.

class zero.analysis.ac.base.VoltageCoefficient(node, **kwargs)[source]

Bases: zero.analysis.ac.base.BaseCoefficient

Represents a voltage coefficient.

Parameters

node (Node) – Node this voltage coefficient represents.

TYPE = 'voltage'