ahkab.ac¶
This module contains the methods required to perform an AC analysis.
Note
Typically, the user does not need to call the functions in this module
directly, instead, we recommend defining an AC analysis object through the
convenience method ahkab.ahkab.new_ac()
and then running it calling
ahkab.ahkab.run()
.
Overview of AC simulations¶
The AC simulation problem¶
Our AC analysis problem can be written as:
We need:
 the Modified Nodal Analysis matrix \(MNA\),
 the \(AC\) matrix, holding the frequency dependent parts,
 \(J\), the Jacobian matrix from the linearized nonlinear elements,
 \(N_{ac}\), the AC sources contribution.
An Operating Point (OP) has to be computed first if there is any nonlinear device in the circuit to perform the linearization.
When all the matrices are available, it is possible to solve the system for the frequency values specified by the user, providing the resulting matrix is not singular (and possibly well conditioned).
Building the AC matrix¶
It’s easy to set up the voltage lines, since line 2 refers to node 2, etc...
A capacitor between two example nodes n1
and n2
introduces the
following elements:
Inductors generate, together with voltage sources, CurrentControlled Voltage sources (CCVS), VoltageControlled Voltage Sources (VCVS), an additional line in the \(MNA\) matrix, and hence in \(AC\) too. In fact, the current flowing through the device gets added to the unknowns vector, \(x\).
For example, in the case of an inductors, we have:
To understand on which line is the KVL line for an inductor, we use the
order of the elements in ahkab.circuit
:
 first are assembled all the voltage rows,
 then the current rows, in the same order in which the elements that introduce
them are found in
ahkab.circuit.Circuit
.
Solving¶
For each angular frequency \(\omega\), the simulator solves the matrix equation described.
Since the equation is linear, solving is performed with a single matrix inversion and multiplication for each step.
Module reference¶

ac_analysis
(circ, start, points, stop, sweep_type=None, x0=None, mna=None, AC=None, Nac=None, J=None, outfile=u'stdout', verbose=3)[source]¶ Performs an AC analysis.
Parameters:
 circ : Circuit instance
 The circuit to be simulated.
 start : float
 The start frequency for the AC analysis, in Hz.
 points : float,
 The number of points to be used to discretize the
[start, stop]
interval.  stop : float
 The stop frequency, in Hz.
 sweep_type : string, optional
 Either
options.ac_log_step
(ie'LOG'
) oroptions.ac_lin_step
(ie'LIN'
), defaults tooptions.ac_log_step
, resulting in a logarithmic sweep.  x0 : OP results instance, optional
 The linearization point. If not set, it will be computed running an OP analysis.
 mna, AC, Nax, J : ndarrays, optional
 The matrices to perform the analysis. They will be computed if not supplied.
 outfile : string, optional
 The name of the file where the results will be written.
The suffix
'.ac'
is automatically added at the end of the string to prevent different analyses from overwriting eachother’s results. Set to'stdout'
to write to the standard output. If unset, or set toNone
, defaults to the standard output.  verbose : int, optional
 The verbosity level, from 0 (silent) to 6 (debug).
Returns:
 ACresult : AC solution
 The AC analysis results.
Raises:  ValueError – if the parameters are out of their valid range.
 RuntimeError – if the circuit is nonlinear and can’t be linearized.