API Reference

CircuitSim.ACAnalysisType
ACAnalysis(; start, stop, points, sweep_type=LOGARITHMIC, name="AC1")
ACAnalysis(; values, sweep_type=LIST, name="AC1")

AC small-signal frequency sweep analysis.

Computes the small-signal AC response over a frequency range.

Parameters

For LINEAR or LOGARITHMIC sweeps:

  • start::Real: Start frequency in Hz
  • stop::Real: Stop frequency in Hz
  • points::Int: Number of frequency points
  • sweep_type::String: "lin"/"linear" or "log"/"logarithmic" (default: "log")

For LIST sweeps:

  • values::Vector{<:Real}: List of frequency points in Hz
  • sweep_type::String: Must be "list"

For CONSTANT sweeps:

  • values::Real: Single frequency value in Hz
  • sweep_type::String: Must be "const" or "constant"

Common parameters:

  • name::String: Analysis name (default: "AC1")

Example

# Logarithmic sweep from 1Hz to 1MHz with 101 points
analysis = ACAnalysis(start=1.0, stop=1e6, points=101)

# Linear sweep
analysis = ACAnalysis(start=100.0, stop=10e3, points=100, sweep_type="lin")

# List of specific frequencies
analysis = ACAnalysis(values=[1e3, 10e3, 100e3, 1e6], sweep_type="list")

# Single frequency
analysis = ACAnalysis(values=1e6, sweep_type="const")
source
CircuitSim.ACCurrentSourceType
ACCurrentSource <: AbstractACCurrentSource

AC current source with two terminals. Current flows from nminus to nplus (into nplus).

For AC analysis, provides a sinusoidal current source.

  • dc: DC offset (default 0)
  • ac_mag: AC magnitude for small-signal analysis
  • ac_phase: AC phase in degrees (default 0)
  • freq: Frequency in Hz (for transient analysis)

Fields

  • name::String: Component identifier
  • nplus::Int: Positive terminal node number
  • nminus::Int: Negative terminal node number
  • dc::Real: DC offset current
  • ac_mag::Real: AC magnitude in Amperes
  • ac_phase::Real: AC phase in degrees
  • freq::Real: Frequency in Hz

Example

# 1mA AC source at 1kHz
I1 = ACCurrentSource("I1", 0.001, freq=1e3)

# 10mA AC with 5mA DC offset
I2 = ACCurrentSource("I2", 0.01, dc=0.005, freq=50.0)
source
CircuitSim.ACPowerSourceType

AC Power Source component for S-parameter and frequency-domain analysis.

This is a generic power source with specified impedance, used as a port for S-parameter, AC, and harmonic balance analyses. In Qucsator netlists, this becomes a "Pac" component.

source
CircuitSim.ACResultType
ACResult

AC analysis results (frequency sweep).

Fields

  • frequencies_Hz::Vector{Float64}: Frequency points
  • voltages::Dict{String,Vector{ComplexF64}}: Node voltages vs frequency
  • currents::Dict{String,Vector{ComplexF64}}: Branch currents vs frequency
source
CircuitSim.ACVoltageSourceType
ACVoltageSource <: AbstractACVoltageSource

AC voltage source with two terminals.

For AC analysis, provides a sinusoidal voltage source.

  • dc: DC offset (default 0)
  • ac_mag: AC magnitude for small-signal analysis
  • ac_phase: AC phase in degrees (default 0)
  • freq: Frequency in Hz (for transient analysis)

Note: For AC analysis (.AC), only acmag and acphase are used. For transient analysis, all parameters define a sinusoid: V(t) = dc + acmag * sin(2πfreqt + acphase)

Fields

  • name::String: Component identifier
  • nplus::Int: Positive terminal node number
  • nminus::Int: Negative terminal node number
  • dc::Real: DC offset voltage
  • ac_mag::Real: AC magnitude in Volts
  • ac_phase::Real: AC phase in degrees
  • freq::Real: Frequency in Hz

Example

# 1V AC source at 1kHz
V1 = ACVoltageSource("V1", 1.0, freq=1e3)

# 5V AC with 2V DC offset
V2 = ACVoltageSource("V2", 5.0, dc=2.0, freq=1e6)
source
CircuitSim.AmplifierType
Amplifier <: AbstractPowerAmplifier

RF/microwave amplifier with gain and noise figure.

This is a simplified amplifier model suitable for system-level simulations.

Fields

  • name::String: Component identifier
  • input::Int: Input terminal node number
  • output::Int: Output terminal node number
  • gain::Real: Linear voltage gain. For 20 dB gain, use gain=10.0
  • nf::Real: Noise figure (linear). For 3 dB NF, use nf=2.0. Default: 1.0 (noiseless)
  • z_in::Real: Input impedance in Ohms (default: 50)
  • z_out::Real: Output impedance in Ohms (default: 50)
source
CircuitSim.AttenuatorType
Attenuator <: AbstractAttenuator

RF attenuator for signal level control.

An attenuator reduces signal power by a specified amount while maintaining impedance matching.

Fields

  • name::String: Component identifier
  • n1::Int: Input terminal node number
  • n2::Int: Output terminal node number
  • attenuation::Real: Attenuation in linear scale
  • z0::Real: Reference impedance in Ohms (default: 50)
  • temp::Real: Temperature in Celsius (default: 26.85)
source
CircuitSim.BiasTeeType
BiasTee <: AbstractBiasTee

Bias tee for combining DC bias and RF signals.

A bias tee has three ports:

  • RF port: AC coupled (passes RF, blocks DC)
  • DC port: DC coupled (passes DC, blocks RF)
  • Combined port: Both DC and RF

Fields

  • name::String: Component identifier
  • n_rf::Int: RF input port node number
  • n_dc::Int: DC input port node number
  • n_out::Int: Combined output port node number
  • capacitance::Real: DC blocking capacitance (default: 1 μF)
  • inductance::Real: RF choke inductance (default: 1 mH)

Example

using CircuitSim
# Standard bias tee
BT1 = BiasTee("BT1")

# Custom component values
BT2 = BiasTee("BT2", capacitance=10e-6, inductance=10e-3)
source
CircuitSim.BondWireType
BondWire <: AbstractBondWire

A bond wire connection for chip interconnects.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • n2::Int: Node 2 (output)
  • l::Real: Wire length (m)
  • d::Real: Wire diameter (m)
  • h::Real: Wire height above substrate (m)
  • rho::Real: Resistivity relative to copper

Example

wire = BondWire("BW1", l=1e-3, d=25e-6, h=0.3e-3)

Qucs Format

BONDWIRE:Name Node1 Node2 L="length" D="diameter" H="height" rho="resistivity"

source
CircuitSim.CapacitorType
Capacitor <: AbstractCapacitor

Ideal capacitor with two terminals.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number (assigned during circuit analysis)
  • n2::Int: Second terminal node number (assigned during circuit analysis)
  • capacitance::Real: Capacitance in Farads
  • initial_voltage::Real: Initial voltage across the capacitor (default: 0.0)

Example

C1 = Capacitor("C1", capacitance=100e-9)  # 100nF capacitor
C2 = Capacitor("C2", capacitance=10e-6, initial_voltage=5.0)  # 10µF capacitor with 5V initial voltage
source
CircuitSim.CapacitorQType
CapacitorQ <: AbstractCapacitor

Capacitor with quality factor for RF simulations.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number
  • n2::Int: Second terminal node number
  • capacitance::Real: Capacitance in Farads
  • q::Real: Quality factor (Q) at the specified frequency
  • frequency::Real: frequency in Hz where Q is specified (default: 1 GHz)
  • mode::String: Q frequency dependency mode - "Linear", "SquareRoot", or "Constant" (default: "Linear")
  • temp::Real: Temperature in Celsius for noise calculations (default: 26.85°C)

Example

using CircuitSim
C1 = CapacitorQ("C1", capacitance=10e-12, q=50.0)  # 10pF capacitor with Q=50
C2 = CapacitorQ("C2", capacitance=100e-12, q=100.0, frequency=2.4e9, mode="SquareRoot")  # 100pF, Q=100 at 2.4 GHz
source
CircuitSim.CircularLoopType
CircularLoop <: AbstractCircularLoop

A single-turn circular loop inductor.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1
  • n2::Int: Node 2
  • r::Real: Loop radius (m)
  • w::Real: Wire/trace width (m)

Example

loop = CircularLoop("CL1", r=5e-3, w=0.5e-3)

Qucs Format

Approximated using standard inductor with calculated value

source
CircuitSim.CirculatorType
Circulator <: AbstractCirculator

3-port RF circulator.

A circulator routes signals in one direction: port 1→2, 2→3, 3→1. Commonly used for isolating transmitter and receiver sharing an antenna.

Fields

  • name::String: Component identifier
  • n1::Int: Port 1 node number
  • n2::Int: Port 2 node number
  • n3::Int: Port 3 node number
  • insertion_loss::Real: Loss through forward path (dB) (default: 0.5)
  • isolation::Real: Isolation to reverse path (dB) (default: 20)
  • z0::Real: Reference impedance in Ohms (default: 50)

Example

using CircuitSim
# Standard circulator
CIRC1 = Circulator("CIRC1")

# Custom circulator with better isolation
CIRC2 = Circulator("CIRC2", isolation=30.0)
source
CircuitSim.CoaxialLineType
CoaxialLine <: AbstractComponent

Coaxial transmission line with physical parameters.

Fields

  • name::String: Component identifier
  • er::Float64: Relative permittivity (default: 2.3)
  • mur::Float64: Relative permeability (default: 1.0)
  • length_m::Float64: Physical length in meters
  • d_mm::Float64: Inner conductor diameter in mm
  • d_outer_mm::Float64: Outer conductor diameter in mm
  • n1::Int: Input port positive node
  • n2::Int: Input port negative node
  • n3::Int: Output port positive node
  • n4::Int: Output port negative node

Pins

  • :n1, :n2: Input port
  • :n3, :n4: Output port

Example

julia> coax = CoaxialLine("COAX1", er=2.3, length_m=0.1, d_mm=0.5, d_outer_mm=3.0)
CoaxialLine("COAX1", 0, 0, 2.3, 1.0, 0.1, 0.5, 3.0, 0.0004, 2.2e-8)
source
CircuitSim.CouplerType
Coupler <: AbstractCoupler

Directional coupler (4-port device).

A directional coupler splits power with specified coupling factor. Ports: 1=input, 2=through, 3=coupled, 4=isolated

Fields

  • name::String: Component identifier
  • n1::Int: Port 1 (input) node number
  • n2::Int: Port 2 (through) node number
  • n3::Int: Port 3 (coupled) node number
  • n4::Int: Port 4 (isolated) node number
  • coupling::Real: Coupling factor in dB (e.g., 3 for 3 dB coupler, 10 for 10 dB coupler)
  • isolation::Real: Isolation in dB (default: 20)
  • insertion_loss::Real: Insertion loss (through path) in dB (default: 0.5)
  • z0::Real: Reference impedance in Ohms (default: 50)

Example

using CircuitSim
# 3 dB (50/50) directional coupler
DC1 = Coupler("DC1", coupling=3.0)

# 10 dB directional coupler (10% coupling)
DC2 = Coupler("DC2", coupling=10.0)

# 20 dB directional coupler with high isolation
DC3 = Coupler("DC3", coupling=20.0, isolation=30.0)
source
CircuitSim.CurrentControlledCurrentSourceType
CurrentControlledCurrentSource(name::String; g::Real=1.0, t::Real=0.0)

Create a current-controlled current source with 4-port configuration.

Arguments

  • name::String: Component identifier
  • g::Real: Current gain (dimensionless) (default 1.0)
  • t::Real: Time delay in seconds (default 0.0)

Fields

  • n1::Int: Positive input node (where current is sensed)
  • n2::Int: Negative input node (where current is sensed)
  • n3::Int: Positive output node
  • n4::Int: Negative output node
source
CircuitSim.CurrentCurrentNoiseSourceType
CurrentCurrentNoiseSource(name::String; i1::Real=1e-6, i2::Real=1e-6, c_corr::Real=0.0, a::Real=0.0, c::Real=1.0, e::Real=0.0)

Create correlated current-current noise sources with 4-port configuration.

Arguments

  • name::String: Component identifier
  • i1::Real: RMS current of first source in A (default 1e-6)
  • i2::Real: RMS current of second source in A (default 1e-6)
  • c_corr::Real: Correlation coefficient -1 to 1 (default 0.0)
  • a::Real: Flicker noise exponent (default 0.0)
  • c::Real: Flicker noise coefficient (default 1.0)
  • e::Real: Flicker noise frequency exponent (default 0.0)

Fields

  • i1plus::Int: Positive node of first current source
  • i1minus::Int: Negative node of first current source
  • i2plus::Int: Positive node of second current source
  • i2minus::Int: Negative node of second current source
source
CircuitSim.CurrentExponentialSourceType
CurrentExponentialSource <: AbstractCurrentSource

Exponential rise/fall current source for transient analysis.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • i1::Real: Initial current level (A)
  • i2::Real: Final current level (A)
  • t1::Real: Rise delay time (s)
  • t2::Real: Fall delay time (s)
  • tr::Real: Rise time constant (s, optional, default 1ns)
  • tf::Real: Fall time constant (s, optional, default 1ns)

Example

isrc = CurrentExponentialSource("Iexp1", i1=0.0, i2=10e-3, t1=1e-9, t2=10e-9)
source
CircuitSim.CurrentNoiseSourceType
CurrentNoiseSource <: AbstractCurrentSource

Current noise source for noise analysis with frequency-dependent PSD.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • i::Real: Noise power spectral density (A²/Hz)
  • a::Real: Frequency offset parameter (optional, default 0)
  • c::Real: Frequency coefficient (optional, default 1)
  • e::Real: Frequency exponent (optional, default 0)

Noise PSD formula: PSD(f) = i / (a + c * f^e)

Example

isrc = CurrentNoiseSource("Inoise1", i=1e-12, e=0)  # White noise
source
CircuitSim.CurrentProbeType

Current probe for measuring current in AC, DC, and transient analyses.

The probe is inserted in series with a circuit element and measures current. It acts as a short circuit (zero impedance).

source
CircuitSim.CurrentPulseSourceType
CurrentPulseSource <: AbstractSource

Current source with pulse waveform for transient analysis.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • i1::Real: Initial current level (A)
  • i2::Real: Pulsed current level (A)
  • t1::Real: Start time of pulse (s)
  • t2::Real: End time of pulse (s)
  • tr::Real: Rise time (s, optional, default 1ns)
  • tf::Real: Fall time (s, optional, default 1ns)

Example

isrc = CurrentPulseSource("Ipulse1", i1=0.0, i2=10e-3, t1=1e-9, t2=10e-9)
source
CircuitSim.CurrentRectangularSourceType
CurrentRectangularSource <: AbstractCurrentSource

Periodic rectangular pulse current source for transient analysis.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • i::Real: Pulse current level (A)
  • th::Real: High time duration (s)
  • tl::Real: Low time duration (s)
  • tr::Real: Rise time (s, optional, default 1ns)
  • tf::Real: Fall time (s, optional, default 1ns)
  • td::Real: Delay time (s, optional, default 0)

Example

isrc = CurrentRectangularSource("Irect1", i=10e-3, th=1e-6, tl=1e-6)
source
CircuitSim.CurrentVoltageNoiseSourceType
CurrentVoltageNoiseSource(name::String; i1::Real=1e-6, v2::Real=1e-6, c_corr::Real=0.0, a::Real=0.0, c::Real=1.0, e::Real=0.0)

Create correlated current-voltage noise sources with 4-port configuration.

Arguments

  • name::String: Component identifier
  • i1::Real: RMS current in A (default 1e-6)
  • v2::Real: RMS voltage in V (default 1e-6)
  • c_corr::Real: Correlation coefficient -1 to 1 (default 0.0)
  • a::Real: Flicker noise exponent (default 0.0)
  • c::Real: Flicker noise coefficient (default 1.0)
  • e::Real: Flicker noise frequency exponent (default 0.0)

Fields

  • i1plus::Int: Positive node of current source
  • i1minus::Int: Negative node of current source
  • v2plus::Int: Positive node of voltage source
  • v2minus::Int: Negative node of voltage source
source
CircuitSim.DCAnalysisType
DCAnalysis(; save_ops=true, temp=26.85, save_all=false)

DC operating point analysis.

Computes the DC operating point of the circuit.

Parameters

  • save_ops::Bool: Save operating points of nonlinear devices (default: true)
  • temp::Real: Simulation temperature in °C (default: 26.85)
  • save_all::Bool: Save all node voltages and branch currents (default: false)
  • name::String: Analysis name (default: "DC1")

Example

analysis = DCAnalysis()
result = simulate_qucsator(circuit, analysis)

# With custom temperature
analysis = DCAnalysis(temp=85.0)
source
CircuitSim.DCBlockType
DCBlock <: AbstractDCBlock

DC blocking capacitor for RF applications.

This is essentially a large capacitor that passes AC signals while blocking DC. Typically used to isolate DC bias points between stages.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number
  • n2::Int: Second terminal node number
  • capacitance::Real: Capacitance in Farads (default: 1 μF for near-ideal blocking)

Example

using CircuitSim
# Default DC block (1 μF)
DCB1 = DCBlock("DCB1")

# Custom capacitance
DCB2 = DCBlock("DCB2", capacitance=10e-6)  # 10 μF
source
CircuitSim.DCCurrentSourceType
DCCurrentSource <: AbstractDCCurrentSource

DC current source with two terminals. Current flows from nminus to nplus (into nplus).

Fields

  • name::String: Component identifier
  • nplus::Int: Positive terminal node number
  • nminus::Int: Negative terminal node number
  • current::Real: DC current in Amperes

Example

I1 = DCCurrentSource("I1", current=0.001)  # 1mA DC source
source
CircuitSim.DCFeedType
DCFeed <: AbstractDCFeed

DC feed (RF choke) for providing DC bias while blocking RF.

This component passes DC current while presenting high impedance to RF signals. Typically implemented as a large inductor.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number
  • n2::Int: Second terminal node number
  • inductance::Real: Inductance in Henries (default: 1 mH for good RF blocking)

Example

using CircuitSim
# Default DC feed (1 mH)
DCF1 = DCFeed("DCF1")

# Custom inductance
DCF2 = DCFeed("DCF2", inductance=10e-3)  # 10 mH
source
CircuitSim.DCResultType
DCResult

DC operating point results.

Fields

  • voltages::Dict{String,Float64}: Node voltages (node_name => voltage)
  • currents::Dict{String,Float64}: Branch currents (component_name => current)
source
CircuitSim.DCVoltageSourceType
DCVoltageSource <: AbstractDCVoltageSource

DC voltage source with two terminals.

Fields

  • name::String: Component identifier
  • nplus::Int: Positive terminal node number
  • nminus::Int: Negative terminal node number
  • voltage::Real: DC voltage in Volts

Example

V1 = DCVoltageSource("V1", voltage=12.0)  # 12V DC source
source
CircuitSim.DataVectorType
DataVector

Represents a data vector from simulation output.

Fields

  • name::String: Vector name
  • values::Vector{ComplexF64}: Data values
  • dependencies::Vector{String}: Names of independent variables this depends on
  • is_independent::Bool: Whether this is an independent variable
source
CircuitSim.FileCurrentSourceType
FileCurrentSource <: AbstractSource

File-based current source for transient analysis.

This component can operate in two modes:

  1. File mode: Reads current vs. time data from an external file
  2. Vector mode: Accepts Julia vectors and automatically creates temporary file

The data consists of time-current pairs that are interpolated during simulation.

Fields

  • name::String: Component identifier
  • nplus::Int: Positive terminal node number (current flows from nplus to nminus)
  • nminus::Int: Negative terminal node number
  • file::Union{String,Nothing}: Path to data file (nothing for vector mode)
  • time_vector::Union{AbstractVector,Nothing}: Time values for vector mode
  • current_vector::Union{AbstractVector,Nothing}: Current values for vector mode
  • interpolator::String: Interpolation method ("linear", "cubic", or "hold")
  • repeat::Bool: Whether to repeat the waveform
  • gain::Real: Gain factor (multiplier for current values)
  • delay::Real: Time delay in seconds
  • format::Symbol: File format (:csv or :qucs_dataset, default :csv)

Supported File Formats

CSV Format (default, recommended)

Two columns: time, current (comma or semicolon separated) Optional header row with column names

Example:

time,current
0.0,0.0
1e-9,0.001
2e-9,0.001

Qucs Dataset Format

Native qucsator format with indep/dep blocks

Example:

<Qucs Dataset 1.0.0>
<indep time 3>
  0.0
  1e-9
  2e-9
</indep>
<dep I1 3>
  0.0
  0.001
  0.001
</dep>

Example

using CircuitSim

# Vector mode - creates a temporary csv file and passes to qucsator.
time = [0.0, 1e-9, 2e-9, 3e-9, 4e-9]
current = [0.0, 0.001, 0.001, 0.0, 0.0]
I1 = FileCurrentSource("I1", time, current)

# Vector mode with Qucs Dataset format
I2 = FileCurrentSource("I2", time, current, format=:qucs_dataset)

# File mode - read from existing file
I3 = FileCurrentSource("I3", "my_current.csv")

# With cubic interpolation and repeating waveform
I4 = FileCurrentSource("I4", time, current, interpolator="cubic", repeat=true)
source
CircuitSim.FileVoltageSourceType
FileVoltageSource <: AbstractSource

File-based voltage source for transient analysis.

This component can operate in two modes:

  1. File mode: Reads voltage vs. time data from an external file
  2. Vector mode: Accepts Julia vectors and automatically creates temporary file

The data consists of time-voltage pairs that are interpolated during simulation.

Fields

  • name::String: Component identifier
  • nplus::Int: Positive terminal node number
  • nminus::Int: Negative terminal node number
  • file::Union{String,Nothing}: Path to data file (nothing for vector mode)
  • time_vector::Union{AbstractVector,Nothing}: Time values for vector mode
  • voltage_vector::Union{AbstractVector,Nothing}: Voltage values for vector mode
  • interpolator::String: Interpolation method ("linear", "cubic", or "hold")
  • repeat::Bool: Whether to repeat the waveform
  • gain::Real: Gain factor (multiplier for voltage values)
  • delay::Real: Time delay in seconds
  • format::Symbol: File format (:csv or :qucs_dataset, default :csv)

Supported File Formats

CSV Format (default, recommended)

Two columns: time, voltage (comma or semicolon separated) Optional header row with column names

Example:

time,voltage
0.0,0.0
1e-9,1.0
2e-9,0.5

Qucs Dataset Format

Native qucsator format with indep/dep blocks

Example:

<Qucs Dataset 1.0.0>
<indep time 4>
  0.0
  1e-9
  2e-9
  3e-9
</indep>
<dep V1 4>
  0.0
  1.0
  0.5
  0.0
</dep>

Example

using CircuitSim

# Vector mode - creates a temporary csv file and passes to qucsator.
time = [0.0, 1e-9, 2e-9, 3e-9]
voltage = [0.0, 1.0, 1.0, 0.0]
V1 = FileVoltageSource("V1", time, voltage)

# Vector mode with Qucs Dataset format
V2 = FileVoltageSource("V2", time, voltage, format=:qucs_dataset)

# File mode - read from existing file
V3 = FileVoltageSource("V3", "my_waveform.csv")

# With interpolation and gain
V4 = FileVoltageSource("V4", time, voltage, interpolator="cubic", gain=2.0)
source
CircuitSim.GroundType
Ground <: AbstractGround

Ground reference node (single pin). Maps to node 0.

Fields

  • name::String: Component identifier
  • n::Int: Terminal node number (always 0 for ground)

Example

GND = Ground("GND")
source
CircuitSim.GyratorType
Gyrator <: AbstractComponent

Gyrator converts impedance (e.g., capacitor ↔ inductor).

Fields

  • name::String: Component identifier
  • r::Float64: Gyration resistance in Ω (default: 50.0)
  • zref::Float64: Reference impedance in Ω (default: 50.0)
  • n1::Int: Port 1 positive node
  • n2::Int: Port 1 negative node
  • n3::Int: Port 2 positive node
  • n4::Int: Port 2 negative node

Pins

  • :n1, :n2: Port 1
  • :n3, :n4: Port 2

Example

julia> gyr = Gyrator("GYR1", r=100.0)
Gyrator("GYR1", 0, 0, 0, 0, 100.0, 50.0)
source
CircuitSim.HarmonicBalanceAnalysisType
HarmonicBalanceAnalysis(; harmonics, frequency=1e9, name="HB1", iabstol=1e-12, vabstol=1e-6, reltol=1e-3, max_iterations=150)

Harmonic balance analysis for steady-state analysis of nonlinear circuits with periodic excitation.

Parameters

  • harmonics::Int: Number of harmonics to include (required)
  • frequency::Real: Fundamental frequency in Hz (default: 1e9)
  • name::String: Analysis name (default: "HB1")
  • iabstol::Real: Current absolute tolerance (default: 1e-12)
  • vabstol::Real: Voltage absolute tolerance (default: 1e-6)
  • reltol::Real: Relative tolerance (default: 1e-3)
  • max_iterations::Int: Maximum number of iterations (default: 150)

Example

# Harmonic balance at 1GHz with 7 harmonics
analysis = HarmonicBalanceAnalysis(harmonics=7, frequency=1e9)

# RF mixer analysis at 100MHz with custom tolerances
analysis = HarmonicBalanceAnalysis(harmonics=11, frequency=100e6, reltol=1e-4)
source
CircuitSim.HybridType
Hybrid <: AbstractHybridCoupler

Hybrid coupler (90° or 180° 3dB power splitter/combiner).

A hybrid coupler is a specialized 4-port device that splits power equally between two ports with a specific phase relationship.

Fields

  • name::String: Component identifier
  • n1::Int: Port 1 (sum) node number
  • n2::Int: Port 2 (difference/isolated) node number
  • n3::Int: Port 3 (output 1) node number
  • n4::Int: Port 4 (output 2) node number
  • phase::Real: Phase difference in degrees (90 or 180) (default: 90)
  • insertion_loss::Real: Insertion loss in dB (default: 0.5)
  • isolation::Real: Isolation between ports in dB (default: 20)
  • z0::Real: Reference impedance in Ohms (default: 50)

Example

using CircuitSim
# 90 degree hybrid (quadrature hybrid)
HYB1 = Hybrid("HYB1")

# 180 degree hybrid (rat-race, magic-T)
HYB2 = Hybrid("HYB2", phase=180.0)

# Low-loss 90 degree hybrid
HYB3 = Hybrid("HYB3", insertion_loss=0.2, isolation=30.0)
source
CircuitSim.IdealTransformerType
IdealTransformer <: AbstractComponent

Ideal transformer with specified turns ratio.

Fields

  • name::String: Component identifier
  • n1::Int: Primary winding positive node
  • n2::Int: Primary winding negative node
  • n3::Int: Secondary winding positive node
  • n4::Int: Secondary winding negative node
  • t::Float64: Turns ratio N2/N1 (default: 1.0)

Pins

  • :n1, :n2: Primary winding
  • :n3, :n4: Secondary winding

Example

julia> trafo = IdealTransformer("TR1", t=2.0)
IdealTransformer("TR1", 0, 0, 0, 0, 2.0)
source
CircuitSim.InductorType
Inductor <: AbstractInductor

Ideal inductor with two terminals.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number (assigned during circuit analysis)
  • n2::Int: Second terminal node number (assigned during circuit analysis)
  • inductance::Real: Inductance in Henries
  • initial_current::Real: Initial current through the inductor in Amperes (for transient analysis)

Example

L1 = Inductor("L1", inductance=10e-6)  # 10μH inductor
L2 = Inductor("L2", inductance=1e-3, initial_current=0.1)  # 1mH inductor with 100mA initial current
source
CircuitSim.InductorQType
InductorQ <: AbstractInductor

Inductor with quality factor for RF simulations.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number
  • n2::Int: Second terminal node number
  • inductance::Real: Inductance in Henries
  • q::Real: Quality factor (Q) at the specified frequency
  • freq::Real: Frequency in Hz where Q is specified (default: 1 GHz)
  • mode::String: Q frequency dependency mode - "Linear", "SquareRoot", or "Constant" (default: "Linear")
  • temp::Real: Temperature in Celsius for noise calculations (default: 26.85°C)

Example

using CircuitSim
L1 = InductorQ("L1", inductance=10e-9, q=30.0)  # 10nH inductor with Q=30
L2 = InductorQ("L2", inductance=100e-9, q=50.0, freq=2.4e9, mode="SquareRoot")  # 100nH, Q=50 at 2.4 GHz
source
CircuitSim.IsolatorType
Isolator <: AbstractIsolator

RF isolator (unidirectional component).

An isolator allows signals to pass in one direction (forward) while blocking signals in the reverse direction. Commonly used to protect sources from reflections.

Fields

  • name::String: Component identifier
  • n1::Int: Input terminal node number
  • n2::Int: Output terminal node number
  • forward_loss::Real: Insertion loss in forward direction (dB) (default: 0.5)
  • reverse_loss::Real: Isolation in reverse direction (dB) (default: 20)
  • z0::Real: Reference impedance in Ohms (default: 50)

Example

using CircuitSim
# Standard isolator: 0.5 dB forward loss, 20 dB isolation
ISO1 = Isolator("ISO1")

# Custom isolator: 1 dB forward loss, 30 dB isolation
ISO2 = Isolator("ISO2", forward_loss=1.0, reverse_loss=30.0)
source
CircuitSim.MicrostripCornerType
MicrostripCorner <: AbstractMicrostripCorner

A 90° microstrip corner/bend.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • n2::Int: Node 2 (output)
  • substrate::Substrate: Substrate definition reference
  • w::Real: Line width (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
corner = MicrostripCorner("MC1", sub, w=3.0e-3)

Qucs Format

MCORN:Name Node1 Node2 Subst="SubstName" W="width"

source
CircuitSim.MicrostripCoupledType
MicrostripCoupled <: AbstractMicrostripCoupled

A pair of microstrip coupled transmission lines (4-port).

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (line 1 input)
  • n2::Int: Node 2 (line 1 output)
  • n3::Int: Node 3 (line 2 input)
  • n4::Int: Node 4 (line 2 output)
  • substrate::Substrate: Substrate definition reference
  • w::Real: Line width (m)
  • l::Real: Line length (m)
  • s::Real: Line spacing (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
coupled = MicrostripCoupled("MCPL1", sub, w=1.0e-3, l=20e-3, s=0.2e-3)

Qucs Format

MCOUPLED:Name Node1 Node2 Node3 Node4 Subst="SubstName" W="width" L="length" S="spacing"

source
CircuitSim.MicrostripCrossType
MicrostripCross <: AbstractMicrostripCross

A microstrip cross-junction (4-port).

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (port 1)
  • n2::Int: Node 2 (port 2)
  • n3::Int: Node 3 (port 3)
  • n4::Int: Node 4 (port 4)
  • substrate::Substrate: Substrate definition reference
  • w1::Real: Port 1 width (m)
  • w2::Real: Port 2 width (m)
  • w3::Real: Port 3 width (m)
  • w4::Real: Port 4 width (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
cross = MicrostripCross("MX1", sub, w1=3.0e-3, w2=3.0e-3, w3=3.0e-3, w4=3.0e-3)

Qucs Format

MCROSS:Name Node1 Node2 Node3 Node4 Subst="SubstName" W1="w1" W2="w2" W3="w3" W4="w4"

source
CircuitSim.MicrostripGapType
MicrostripGap <: AbstractMicrostripGap

A microstrip series gap discontinuity providing capacitive coupling.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • n2::Int: Node 2 (output)
  • substrate::Substrate: Substrate definition reference
  • w1::Real: Width at port 1 (m)
  • w2::Real: Width at port 2 (m)
  • s::Real: Gap spacing (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
gap = MicrostripGap("MG1", sub, w1=3.0e-3, w2=3.0e-3, s=0.2e-3)

Qucs Format

MGAP:Name Node1 Node2 Subst="SubstName" W1="width1" W2="width2" S="spacing"

source
CircuitSim.MicrostripLangeType
MicrostripLange <: AbstractMicrostripLange

A Lange coupler - an interdigitated microstrip directional coupler providing tight coupling.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • n2::Int: Node 2 (through)
  • n3::Int: Node 3 (coupled)
  • n4::Int: Node 4 (isolated)
  • substrate::Substrate: Substrate definition reference
  • w::Real: Finger width (m)
  • l::Real: Finger length (m)
  • s::Real: Finger spacing (m)
  • n::Int: Number of fingers

Example

sub = Substrate("RO4003C", er=3.55, h=0.508e-3)
lange = MicrostripLange("LC1", sub, w=0.15e-3, l=10e-3, s=0.1e-3, n=4)

Qucs Format

MLANGE:Name Node1 Node2 Node3 Node4 Subst="SubstName" W="width" L="length" S="spacing" N="fingers"

source
CircuitSim.MicrostripLineType
MicrostripLine <: AbstractMicrostripLine

A microstrip transmission line segment.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • n2::Int: Node 2 (output)
  • substrate::Substrate: Substrate definition reference
  • w::Real: Line width (m)
  • l::Real: Line length (m)
  • model::String: Optional SPICE model name
  • temp::Real: Temperature (K)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
line = MicrostripLine("MS1", sub, w=3.0e-3, l=20e-3)

Qucs Format

MLIN:Name Node1 Node2 Subst="SubstName" W="width" L="length" Temp="temp"

source
CircuitSim.MicrostripMiteredBendType
MicrostripMiteredBend <: AbstractMicrostripMiteredBend

A mitered microstrip 90° bend with corner cut for improved performance.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • n2::Int: Node 2 (output)
  • substrate::Substrate: Substrate definition reference
  • w::Real: Line width (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
bend = MicrostripMiteredBend("MB1", sub, w=3.0e-3)

Qucs Format

MBEND:Name Node1 Node2 Subst="SubstName" W="width"

source
CircuitSim.MicrostripOpenType
MicrostripOpen <: AbstractMicrostripOpen

A microstrip open-circuit termination with end-effect modeling.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input)
  • substrate::Substrate: Substrate definition reference
  • w::Real: Line width (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
open_end = MicrostripOpen("MO1", sub, w=3.0e-3)

Qucs Format

MOPEN:Name Node1 Subst="SubstName" W="width"

source
CircuitSim.MicrostripRadialStubType
MicrostripRadialStub <: AbstractMicrostripRadialStub

A microstrip radial (butterfly) stub for wideband matching.

Fields

  • name::String: Component identifier
  • n1::Int: Node (connection point)
  • substrate::Substrate: Substrate definition reference
  • ri::Real: Inner radius (m)
  • ro::Real: Outer radius (m)
  • wf::Real: Feedline width (m)
  • alpha::Real: Stub angle (degrees)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
stub = MicrostripRadialStub("RS1", sub, ri=0.5e-3, ro=5.0e-3, wf=1.0e-3, alpha=60.0)

Qucs Format

MRSTUB:Name Node1 Subst="SubstName" ri="inner" ro="outer" Wf="width" alpha="angle" EffDimens="OldQucsNoCorrection" Model="OldQucsModel"

source
CircuitSim.MicrostripStepType
MicrostripStep <: AbstractMicrostripStep

A microstrip width step/discontinuity.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (input, wider/narrower side)
  • n2::Int: Node 2 (output, other side)
  • substrate::Substrate: Substrate definition reference
  • w1::Real: Width at port 1 (m)
  • w2::Real: Width at port 2 (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
step = MicrostripStep("MSTEP1", sub, w1=3.0e-3, w2=1.5e-3)

Qucs Format

MSTEP:Name Node1 Node2 Subst="SubstName" W1="width1" W2="width2"

source
CircuitSim.MicrostripTeeType
MicrostripTee <: AbstractMicrostripTee

A microstrip T-junction (3-port).

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (main line input)
  • n2::Int: Node 2 (main line output)
  • n3::Int: Node 3 (branch)
  • substrate::Substrate: Substrate definition reference
  • w1::Real: Main line width (m)
  • w2::Real: Branch width (m)

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
tee = MicrostripTee("MTEE1", sub, w1=3.0e-3, w2=1.5e-3)

Qucs Format

MTEE:Name Node1 Node2 Node3 Subst="SubstName" W1="width1" W2="width2" W3="width3"

source
CircuitSim.MicrostripViaType
MicrostripVia <: AbstractMicrostripVia

A microstrip via hole connecting to ground plane.

Fields

  • name::String: Component identifier
  • n1::Int: Node (top connection)
  • substrate::Substrate: Substrate definition reference
  • d::Real: Via hole diameter (m)
  • t::Real: Metal thickness (m), uses substrate if 0

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
via = MicrostripVia("VIA1", sub, d=0.3e-3)

Qucs Format

MVIA:Name Node1 gnd Subst="SubstName" D="diameter"

source
CircuitSim.MultiAnalysisResultType
MultiAnalysisResult

Results from multiple analyses run simultaneously.

Contains the raw QucsatorDataset plus typed results for each analysis type found.

Fields

  • dataset::QucsatorDataset: Raw parsed dataset with all vectors
  • dc::Union{Nothing,DCResult}: DC analysis results (if DC analysis was run)
  • ac::Union{Nothing,ACResult}: AC analysis results (if AC analysis was run)
  • transient::Union{Nothing,TransientResult}: Transient analysis results (if transient analysis was run)
  • sparameter::Union{Nothing,SParameterResult}: S-parameter results (if S-parameter analysis was run)

Example

# Run DC + S-parameter analysis together
results = simulate_qucsator(circ, [DCAnalysis(), SParameterAnalysis(1e9, 10e9, 101)])

# Access DC results
if !isnothing(results.dc)
    v_node = results.dc.voltages["_net1"]
end

# Access S-parameter results
if !isnothing(results.sparameter)
    s21 = results.sparameter.s_matrix[(2,1)]
end
source
CircuitSim.MultiAnalysisResultMethod
MultiAnalysisResult(dataset::QucsatorDataset, analyses::Vector{<:AbstractAnalysis})

Create a MultiAnalysisResult by extracting typed results for each analysis type.

Arguments

  • dataset::QucsatorDataset: Parsed simulation output
  • analyses::Vector{<:AbstractAnalysis}: List of analyses that were run

Returns

  • MultiAnalysisResult with typed results for each analysis found
source
CircuitSim.MutualInductorType
MutualInductor <: AbstractComponent

Two coupled inductors with mutual inductance.

Fields

  • name::String: Component identifier
  • n1::Int: First inductor node 1
  • n2::Int: First inductor node 2
  • n3::Int: Second inductor node 1
  • n4::Int: Second inductor node 2
  • l1::Float64: Inductance of first coil in H
  • l2::Float64: Inductance of second coil in H
  • k::Float64: Coupling coefficient (0 to 1, default: 0.9)

Pins

  • :n1, :n2: First inductor
  • :n3, :n4: Second inductor

Example

julia> mut = MutualInductor("MUT1", l1=1e-6, l2=1e-6, k=0.95)
MutualInductor("MUT1", 0, 0, 0, 0, 1.0e-6, 1.0e-6, 0.95)
source
CircuitSim.NoiseAnalysisType
NoiseAnalysis(; start, stop, points, output_node, source, sweep_type="log", name="Noise1")

Noise analysis over a frequency range.

Computes noise contributions from all noise sources in the circuit.

Parameters

  • start::Real: Start frequency in Hz (required)
  • stop::Real: Stop frequency in Hz (required)
  • points::Int: Number of frequency points (required)
  • output_node::String: Output node name for noise measurement (required)
  • source::String: Input source name for noise reference (required)
  • sweep_type::String: "lin"/"linear" or "log"/"logarithmic" (default: "log")
  • name::String: Analysis name (default: "Noise1")

Example

# Noise analysis from 10Hz to 100kHz
analysis = NoiseAnalysis(start=10.0, stop=100e3, points=101, output_node="_net1", source="V1")

# Linear frequency sweep for noise
analysis = NoiseAnalysis(start=1e3, stop=10e3, points=100, output_node="_net2", source="V_in", sweep_type="lin")
source
CircuitSim.OpAmpType
OpAmp <: AbstractComponent

Operational amplifier with ideal characteristics.

Fields

  • name::String: Component identifier
  • ninp::Int: Non-inverting input node
  • ninn::Int: Inverting input node
  • nout::Int: Output node
  • g::Float64: Open-loop voltage gain (default: 1e6)
  • umax::Float64: Maximum output voltage (default: 15.0 V)

Pins

  • :ninp: Non-inverting input (+)
  • :ninn: Inverting input (-)
  • :nout: Output

Example

julia> opamp = OpAmp("OP1", g=1e5, umax=12.0)
OpAmp("OP1", 0, 0, 0, 100000.0, 12.0)
source
CircuitSim.OpenType
Open <: AbstractOpenCircuit

Open circuit (infinite resistance between two nodes).

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node
  • n2::Int: Second terminal node

Pins

  • :n1, :n2: Two-terminal open circuit

Example

julia> open_ckt = Open("Open1")
Open("Open1", 0, 0)
source
CircuitSim.ParameterSweepType
ParameterSweep(; param, start, stop, points, inner_analysis, sweep_type="lin", name="SW1")

Parameter sweep analysis.

Sweeps a component parameter and runs an inner analysis at each point.

Parameters

  • param::String: Parameter name to sweep (e.g., "R1.R" for resistor R1's resistance) (required)
  • start::Real: Start value (required)
  • stop::Real: Stop value (required)
  • points::Int: Number of sweep points (required)
  • inner_analysis::AbstractAnalysis: Analysis to run at each sweep point (required)
  • sweep_type::String: "lin"/"linear" or "log"/"logarithmic" (default: "lin")
  • name::String: Analysis name (default: "SW1")

Example

# Sweep R1 from 1kΩ to 10kΩ and run DC analysis at each point
dc = DCAnalysis()
sweep = ParameterSweep(param="R1.R", start=1e3, stop=10e3, points=10, inner_analysis=dc)
result = simulate_qucsator(circuit, sweep)

# Logarithmic parameter sweep with AC inner analysis
ac = ACAnalysis(start=1.0, stop=1e6, points=101)
sweep = ParameterSweep(param="C1.C", start=1e-12, stop=1e-9, points=20, inner_analysis=ac, sweep_type="log")
source
CircuitSim.PhaseShifterType
PhaseShifter <: AbstractPhaseShifter

RF phase shifter.

A phase shifter introduces a specified phase shift to the signal while maintaining amplitude (ideally).

Fields

  • name::String: Component identifier
  • n1::Int: Input terminal node number
  • n2::Int: Output terminal node number
  • phase::Real: Phase shift in degrees
  • z0::Real: Reference impedance in Ohms (default: 50)
  • insertion_loss::Real: Insertion loss in dB (default: 0 for ideal)

Example

using CircuitSim
# 90 degree phase shifter
PS1 = PhaseShifter("PS1", 90.0)

# 180 degree phase shifter with 0.5 dB loss
PS2 = PhaseShifter("PS2", 180.0, insertion_loss=0.5)
source
CircuitSim.PowerProbeType

Power probe for measuring power flow in circuits.

The probe measures power between two differential ports (4 terminals total).

source
CircuitSim.QucsatorDatasetType
QucsatorDataset

Parsed simulation result containing all vectors and metadata.

Fields

  • status::SimulationStatus: Status of the simulation
  • version::String: Qucs dataset version
  • independent_vars::Dict{String,DataVector}: Independent variables (e.g., frequency, time)
  • dependent_vars::Dict{String,DataVector}: Dependent variables (e.g., voltages, currents)
  • errors::Vector{String}: Error messages
  • warnings::Vector{String}: Warning messages
  • raw_output::String: Raw simulator output

Typed Result Extraction

Use extract_dc_result(), extract_ac_result(), extract_transient_result(), or extract_sparameter_result() to get typed data structures.

source
CircuitSim.ResistorType
Resistor <: AbstractResistor

Ideal resistor with two terminals.

Fields

  • name::String: Component identifier
  • n1::Int: First terminal node number (assigned during circuit analysis)
  • n2::Int: Second terminal node number (assigned during circuit analysis)
  • resistance::Real: Resistance in Ohms
  • temp::Real: Operating temperature in Kelvin (default: 26.85)
  • tc1::Real: First order temperature coefficient (default: 0.0)
  • tc2::Real: Second order temperature coefficient (default: 0.0)
  • tnom::Real: Nominal temperature in Kelvin (default: 26.85)

Example

R1 = Resistor("R1", resistance=1000.0)  # 1kΩ resistor
R2 = Resistor("R2", resistance=2200.0, temp=85.0, tc1=0.001, tc2=0.0, tnom=25.0)  # 2.2kΩ resistor with temperature coefficients
source
CircuitSim.SParameterAnalysisType
SParameterAnalysis(; start, stop, points, sweep_type=LOGARITHMIC, name="SP1", z0=50.0, noise=false)
SParameterAnalysis(; values, sweep_type=LIST, name="SP1", z0=50.0, noise=false)

S-parameter frequency sweep analysis.

Computes S-parameters over a frequency range. Optionally compute noise parameters.

Parameters

For LINEAR or LOGARITHMIC sweeps:

  • start::Real: Start frequency in Hz
  • stop::Real: Stop frequency in Hz
  • points::Int: Number of frequency points
  • sweep_type::String: "lin"/"linear" or "log"/"logarithmic" (default: "log")

For LIST sweeps:

  • values::Vector{<:Real}: List of frequency points in Hz
  • sweep_type::String: Must be "list"

For CONSTANT sweeps:

  • values::Real: Single frequency value in Hz
  • sweep_type::String: Must be "const" or "constant"

Common parameters:

  • name::String: Analysis name (default: "SP1")
  • z0::Real: Reference impedance in Ohms (default: 50.0)
  • noise::Bool: Enable noise parameter calculation (default: false)
  • noise_input_port::Int: Input port for noise parameters (default: 1)
  • noise_output_port::Int: Output port for noise parameters (default: 2)

Example

# S-parameter analysis from 1MHz to 1GHz
analysis = SParameterAnalysis(start=1e6, stop=1e9, points=201)

# With 75Ω reference impedance
analysis = SParameterAnalysis(start=1e6, stop=1e9, points=201, z0=75.0)

# With noise parameters (F, Fmin, Sopt, Rn)
analysis = SParameterAnalysis(start=1e6, stop=1e9, points=201, noise=true)

# List of specific frequencies
analysis = SParameterAnalysis(values=[1e6, 10e6, 100e6, 1e9], sweep_type="list")
source
CircuitSim.SParameterResultType
SParameterResult

S-parameter analysis results.

Fields

  • frequencies_Hz::Vector{Float64}: Frequency points
  • num_ports::Int: Number of ports
  • s_matrix::Dict{Tuple{Int,Int},Vector{ComplexF64}}: S[i,j] vs frequency
  • z0_Ohm::Float64: Reference impedance
  • F::Union{Nothing,Vector{Float64}}: Noise figure (linear, not dB) vs frequency (if noise analysis enabled)
  • Fmin::Union{Nothing,Vector{Float64}}: Minimum noise figure (linear) vs frequency (if noise analysis enabled)
  • Sopt::Union{Nothing,Vector{ComplexF64}}: Optimal source reflection coefficient vs frequency (if noise analysis enabled)
  • Rn_Ohm::Union{Nothing,Vector{Float64}}: Equivalent noise resistance in Ohms vs frequency (if noise analysis enabled)
source
CircuitSim.SPfileType
SPfile <: AbstractSParameterFile

S-parameter file (Touchstone format) component.

Loads S-parameters from a Touchstone file and uses them as a black-box frequency-domain model. The number of ports is automatically detected from the file extension.

Port Structure

For an N-port S-parameter file, the component has N+1 nodes:

  • n1, n2, ..., nN: Port terminal nodes
  • ref: Ground reference node (always the last node)

Fields

  • name::String: Component identifier
  • nodes::Vector{Int}: Port terminal nodes (N+1 total: N ports + ground)
  • file::String: Path to Touchstone file
  • num_ports::Int: Number of ports
  • data_format::String: Data format ("rectangular" or "polar")
  • interpolator::String: Interpolation method ("linear" or "cubic")
  • temp::Real: Temperature in Kelvin (default 293.15K = 20°C)
  • during_dc::String: DC behavior ("open", "short", or "unspecified")

Example

# Load a 1-port S-parameter file (antenna)
antenna = SPfile("ANT1", "antenna.s1p")
@connect circ source.nplus antenna.n1
@connect circ antenna.ref ground

# Load a 2-port S-parameter file (amplifier)
amp = SPfile("AMP1", "amplifier.s2p")
@connect circ input.nplus amp.n1
@connect circ output.nplus amp.n2
@connect circ amp.ref ground

# Manually specify port count if filename doesn't follow .sNp convention
custom = SPfile("DEV", "data.txt", num_ports=3)

# Custom options
filter_sp = SPfile("FILT1", "filter.s2p", 
    data_format="polar",
    interpolator="cubic",
    temp=298.15)

Notes

  • File path can be absolute or relative to netlist location
  • Supports Touchstone v1.0, v1.1, v2.0 formats
  • Number of ports detected from .sNp filename (e.g., .s1p = 1-port, .s2p = 2-port)
  • Can be overridden with num_ports parameter
  • Always connect the ref node to circuit ground
source
CircuitSim.SimulationStatusType
SimulationStatus

Result status from a simulation run.

Values:

  • SIM_SUCCESS: Simulation completed successfully
  • SIM_ERROR: Simulation encountered an error
  • SIM_PARSE_ERROR: Output parsing failed
  • SIM_NOT_RUN: Simulation has not been run
source
CircuitSim.SpiralInductorType
SpiralInductor <: AbstractSpiralInductor

A planar spiral inductor on a substrate.

Fields

  • name::String: Component identifier
  • n1::Int: Node 1 (outer terminal)
  • n2::Int: Node 2 (inner terminal)
  • substrate::Substrate: Substrate definition reference
  • geometry::String: Inductor geometry ("Circular", "Square", "Hexagonal", "Octogonal")
  • w::Real: Track width (m)
  • s::Real: Track spacing (m)
  • di::Real: Inner diameter (m)
  • turns::Real: Number of turns

Example

sub = Substrate("FR4", er=4.5, h=1.6e-3)
spiral = SpiralInductor("L1", sub, geometry="Circular", w=0.2e-3, s=0.15e-3, di=1e-3, turns=5.5)
source
CircuitSim.SubstrateType
Substrate

Defines the substrate properties for microstrip and planar components.

Fields

  • name::String: Substrate identifier
  • er::Real: Relative permittivity (dielectric constant)
  • h::Real: Substrate height/thickness in meters
  • t::Real: Metal thickness in meters
  • tand::Real: Loss tangent (tan δ)
  • rho::Real: Metal resistivity in Ω·m (Copper ≈ 0.022e-6)
  • rough::Real: Surface roughness in meters

Example

# Standard FR4 substrate
fr4 = Substrate("FR4", er=4.5, h=1.6e-3, t=35e-6, tand=0.02)

# Rogers RO4003C
ro4003c = Substrate("RO4003C", er=3.55, h=0.508e-3, t=17e-6, tand=0.0027)

# Low-loss Rogers RT/duroid
duroid = Substrate("Duroid", er=2.2, h=0.787e-3, t=35e-6, tand=0.0009)
source
CircuitSim.TransientAnalysisType
TransientAnalysis(; stop, start=0.0, points=nothing, step=nothing, name="TR1", integration_method="trapezoidal", order=2, initial_dc=true, reltol=1e-3, vabstol=1e-6, iabstol=1e-12, maxstep=nothing, minstep=nothing, max_iterations=150)

Time-domain transient analysis.

Simulates the circuit behavior over time.

Parameters

  • stop::Real: Stop time in seconds (required)
  • start::Real: Start time in seconds (default: 0.0)
  • points::Int: Number of time points (specify either points or step)
  • step::Real: Time step in seconds (specify either points or step)
  • name::String: Analysis name (default: "TR1")
  • integration_method::String: Integration method (default: "trapezoidal")
    • "euler" - Backward Euler (order 1)
    • "trapezoidal" - Trapezoidal/Bilinear (order 2)
    • "gear" - Gear (order 1-6)
    • "adamsmoulton" - Adams-Moulton (order 1-6)
  • order::Int: Integration order for Gear and Adams-Moulton (default: 2, range: 1-6)
  • initial_dc::Bool: Compute initial DC operating point (default: true)
  • reltol::Real: Relative tolerance for error control (default: 1e-3)
  • vabstol::Real: Voltage absolute tolerance in V (default: 1e-6)
  • iabstol::Real: Current absolute tolerance in A (default: 1e-12)
  • maxstep::Union{Real,Nothing}: Maximum time step in seconds (default: nothing, auto-calculated)
  • minstep::Union{Real,Nothing}: Minimum time step in seconds (default: nothing, auto-calculated)
  • max_iterations::Int: Maximum Newton-Raphson iterations (default: 150)

Example

# Simulate for 1ms with 1001 points using trapezoidal
analysis = TransientAnalysis(stop=1e-3, points=1001)

# Simulate for 10μs with 10ns step using Gear order 4
analysis = TransientAnalysis(stop=10e-6, step=10e-9, integration_method="gear", order=4)

# Using backward Euler with custom tolerances
analysis = TransientAnalysis(stop=1e-3, points=501, integration_method="euler", reltol=1e-4, vabstol=1e-7)

# With explicit time step control
analysis = TransientAnalysis(stop=1e-3, points=1001, maxstep=1e-6, minstep=1e-12)
source
CircuitSim.TransientResultType
TransientResult

Transient analysis results (time domain).

Fields

  • time_s::Vector{Float64}: Time points
  • voltages::Dict{String,Vector{Float64}}: Node voltages vs time
  • currents::Dict{String,Vector{Float64}}: Branch currents vs time
source
CircuitSim.TransmissionLineType
TransmissionLine <: AbstractComponent

Simple lossless transmission line.

Fields

  • name::String: Component identifier
  • z0::Float64: Characteristic impedance in Ω (default: 50.0)
  • length_m::Float64: Physical length in meters
  • alpha::Float64: Attenuation constant in 1/m (default: 0.0)
  • n1::Int: Input port positive node
  • n2::Int: Input port negative node
  • n3::Int: Output port positive node
  • n4::Int: Output port negative node

Pins

  • :n1, :n2: Input port
  • :n3, :n4: Output port

Example

julia> tline = TransmissionLine("TL1", z0=75.0, length_m=0.1)
TransmissionLine("TL1", 0, 0, 0, 0, 75.0, 0.1, 0.0)
source
CircuitSim.VoltageAMSourceType
VoltageAMSource(name::String; u::Real=1.0, f::Real=1e9, m::Real=1.0, phase::Real=0.0)

Create an amplitude modulated voltage source with 3-port configuration.

Arguments

  • name::String: Component identifier
  • u::Real: Carrier amplitude in Volts (default 1.0)
  • f::Real: Carrier frequency in Hz (default 1e9)
  • m::Real: Modulation index 0 to 1 (default 1.0)
  • phase::Real: Phase in degrees -360 to 360 (default 0.0)

Fields

  • nplus::Int: Positive output node
  • nminus::Int: Negative output node
  • nmod::Int: Modulation input node
source
CircuitSim.VoltageControlledCurrentSourceType
VoltageControlledCurrentSource(name::String; g::Real=1.0, t::Real=0.0)

Create a voltage-controlled current source with 4-port configuration.

Arguments

  • name::String: Component identifier
  • g::Real: Transconductance in Siemens (A/V) (default 1.0)
  • t::Real: Time delay in seconds (default 0.0)

Fields

  • n1::Int: Positive input control node
  • n2::Int: Negative input control node
  • n3::Int: Positive output node
  • n4::Int: Negative output node
source
CircuitSim.VoltageControlledVoltageSourceType
VoltageControlledVoltageSource(name::String; g::Real=1.0, t::Real=0.0)

Create a voltage-controlled voltage source with 4-port configuration.

Arguments

  • name::String: Component identifier
  • g::Real: Voltage gain (default 1.0)
  • t::Real: Time delay in seconds (default 0.0)

Fields

  • n1::Int: Positive input control node
  • n2::Int: Negative input control node
  • n3::Int: Positive output node
  • n4::Int: Negative output node
source
CircuitSim.VoltageExponentialSourceType
VoltageExponentialSource <: AbstractVoltageSource

Exponential rise/fall voltage source for transient analysis.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • u1::Real: Initial voltage level (V)
  • u2::Real: Final voltage level (V)
  • t1::Real: Rise delay time (s)
  • t2::Real: Fall delay time (s)
  • tr::Real: Rise time constant (s, optional, default 1ns)
  • tf::Real: Fall time constant (s, optional, default 1ns)

Example

vsrc = VoltageExponentialSource("Vexp1", u1=0.0, u2=5.0, t1=1e-9, t2=10e-9)
source
CircuitSim.VoltageNoiseSourceType
VoltageNoiseSource <: AbstractVoltageSource

Voltage noise source for noise analysis with frequency-dependent PSD.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • u::Real: Noise power spectral density (V²/Hz)
  • a::Real: Frequency offset parameter (optional, default 0)
  • c::Real: Frequency coefficient (optional, default 1)
  • e::Real: Frequency exponent (optional, default 0)

Noise PSD formula: PSD(f) = u / (a + c * f^e)

Example

vsrc = VoltageNoiseSource("Vnoise1", u=1e-6, e=0)  # White noise
source
CircuitSim.VoltagePMSourceType
VoltagePMSource(name::String; u::Real=1.0, f::Real=1e9, m::Real=1.0, phase::Real=0.0)

Create a phase modulated voltage source with 3-port configuration.

Arguments

  • name::String: Component identifier
  • u::Real: Carrier amplitude in Volts (default 1.0)
  • f::Real: Carrier frequency in Hz (default 1e9)
  • m::Real: Modulation index 0 to 1 (default 1.0)
  • phase::Real: Base phase in degrees -360 to 360 (default 0.0)

Fields

  • nplus::Int: Positive output node
  • nminus::Int: Negative output node
  • nmod::Int: Modulation input node
source
CircuitSim.VoltageProbeType

Voltage probe for measuring voltages in AC, DC, and transient analyses.

The probe connects between two nodes and measures the voltage difference. It has infinite input impedance (does not affect the circuit).

source
CircuitSim.VoltagePulseSourceType
VoltagePulseSource <: AbstractVoltageSource

Voltage source with pulse waveform for transient analysis.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • u1::Real: Initial voltage level (V)
  • u2::Real: Pulsed voltage level (V)
  • t1::Real: Start time of pulse (s)
  • t2::Real: End time of pulse (s)
  • tr::Real: Rise time (s, optional, default 1ns)
  • tf::Real: Fall time (s, optional, default 1ns)

Example

vsrc = VoltagePulseSource("Vpulse1", u1=0.0, u2=5.0, t1=1e-9, t2=10e-9, tr=1e-10, tf=1e-10)
source
CircuitSim.VoltageRectangularSourceType
VoltageRectangularSource <: AbstractVoltageSource

Periodic rectangular pulse voltage source for transient analysis.

Fields

  • name::String: Component identifier
  • n1::Int: Positive terminal node number
  • n2::Int: Negative terminal node number
  • u::Real: Pulse voltage level (V)
  • th::Real: High time duration (s)
  • tl::Real: Low time duration (s)
  • tr::Real: Rise time (s, optional, default 1ns)
  • tf::Real: Fall time (s, optional, default 1ns)
  • td::Real: Delay time (s, optional, default 0)

Example

vsrc = VoltageRectangularSource("Vrect1", u=5.0, th=1e-6, tl=1e-6)

Qucs Format

Vrect:Name Node+ Node- U="u" TH="th" TL="tl" Tr="tr" Tf="tf" Td="td"

source
CircuitSim.VoltageVoltageNoiseSourceType
VoltageVoltageNoiseSource(name::String; v1::Real=1e-6, v2::Real=1e-6, c_corr::Real=0.0, a::Real=0.0, c::Real=1.0, e::Real=0.0)

Create correlated voltage-voltage noise sources with 4-port configuration.

Arguments

  • name::String: Component identifier
  • v1::Real: RMS voltage of first source in V (default 1e-6)
  • v2::Real: RMS voltage of second source in V (default 1e-6)
  • c_corr::Real: Correlation coefficient -1 to 1 (default 0.0)
  • a::Real: Flicker noise exponent (default 0.0)
  • c::Real: Flicker noise coefficient (default 1.0)
  • e::Real: Flicker noise frequency exponent (default 0.0)

Fields

  • v1plus::Int: Positive node of first voltage source
  • v1minus::Int: Negative node of first voltage source
  • v2plus::Int: Positive node of second voltage source
  • v2minus::Int: Negative node of second voltage source
source
CircuitSim.assign_nodes!Method

Walk all components, examine their integer fields (node fields), and assign canonical node numbers (small consecutive integers). Ground is node 0. After calling assign_nodes!, the components' node fields are filled with integers suitable for netlisting.

Node fields are identified by name pattern: n, n1, n2, nplus, nminus, etc. Other Int fields (like port numbers) are left unchanged.

source
CircuitSim.check_ngspiceMethod
check_ngspice() -> (Bool, String, String)

Check if ngspice is installed and available in PATH.

Returns

  • is_installed::Bool: Whether ngspice is available
  • version::String: Version string if available
  • path::String: Path to the executable
source
CircuitSim.check_qucsatorMethod
check_qucsator() -> (Bool, String, String)

Check if qucsator_rf is installed and available in PATH.

Returns

  • is_installed::Bool: Whether qucsator_rf is available
  • version::String: Version string if available
  • path::String: Path to the executable
source
CircuitSim.detect_touchstone_portsMethod
detect_touchstone_ports(filepath::String) -> Int

Detect the number of ports from Touchstone file extension using regex.

Matches filenames ending in .sNp where N is 1 or more digits (e.g., .s1p, .s2p, .s12p).

Throws an error if pattern doesn't match.

Examples

julia> detect_touchstone_ports("antenna.s1p")
1

julia> detect_touchstone_ports("amplifier.s2p")
2

julia> detect_touchstone_ports("complex_device.txt")
ERROR: ArgumentError: Could not detect number of ports from filename 'complex_device.txt'. Expected Touchstone format: .sNp (e.g., .s1p, .s2p). Provide num_ports parameter as override.
source
CircuitSim.extract_ac_resultMethod
extract_ac_result(dataset::QucsatorDataset) -> ACResult

Extract AC analysis results from dataset.

Returns

  • ACResult with frequency sweep data

Example

ac_data = extract_ac_result(dataset)
freqs = ac_data.frequencies_Hz
v_out = ac_data.voltages["_net1"]  # ComplexF64 vector vs frequency
source
CircuitSim.extract_dc_resultMethod
extract_dc_result(dataset::QucsatorDataset) -> DCResult

Extract DC operating point results from dataset.

Returns

  • DCResult with voltages and currents dictionaries

Example

dc_data = extract_dc_result(dataset)
v_out = dc_data.voltages["_net1"]
i_supply = dc_data.currents["V1"]
source
CircuitSim.extract_sparameter_resultMethod
extract_sparameter_result(dataset::QucsatorDataset; z0::Real=50.0) -> SParameterResult

Extract S-parameter analysis results from dataset.

Arguments

  • dataset::QucsatorDataset: Parsed simulation output
  • z0::Real=50.0: Reference impedance in Ohms

Returns

  • SParameterResult with S-parameter matrix data and noise parameters (if noise analysis was enabled)

Example

sp_data = extract_sparameter_result(dataset)
freqs = sp_data.frequencies_Hz
s21 = sp_data.s_matrix[(2,1)]  # Forward transmission vs frequency

# Noise parameters (if available)
if !isnothing(sp_data.F)
    nf_db = 10 * log10.(sp_data.F)  # Convert to dB
    fmin_db = 10 * log10.(sp_data.Fmin)  # Minimum NF in dB
    gamma_opt = sp_data.Sopt  # Optimal source reflection coefficient
    rn = sp_data.Rn_Ohm  # Equivalent noise resistance
end
source
CircuitSim.extract_transient_resultMethod
extract_transient_result(dataset::QucsatorDataset) -> TransientResult

Extract transient analysis results from dataset.

Returns

  • TransientResult with time domain data

Example

tran_data = extract_transient_result(dataset)
times = tran_data.time_s
v_out = tran_data.voltages["_net1"]  # Float64 vector vs time
source
CircuitSim.get_complex_vectorMethod
get_complex_vector(dataset::QucsatorDataset, name::String) -> Vector{ComplexF64}

Get the complex values of a named vector from the dataset.

source
CircuitSim.get_component_currentMethod
get_component_current(result, component_name::String)

Get current through a component from simulation results.

Note: Current direction follows passive sign convention - positive current flows from the first pin (e.g., nplus, n1) to the second pin (e.g., nminus, n2) internally.

Arguments

  • result: DCResult, ACResult, or TransientResult
  • component_name::String: Component name (e.g., "V1", "R1")

Returns

  • For DC: Float64 current
  • For AC: Vector{ComplexF64} current vs frequency
  • For Transient: Vector{Float64} current vs time

Example

dc = simulate_qucsator(circ, DCAnalysis())
i_source = get_component_current(dc, "V1")
source
CircuitSim.get_component_powerMethod
get_component_power(result::DCResult, component, pin_pos::Symbol, pin_neg::Symbol)

Calculate power dissipated in a component for DC analysis (P = V × I).

Arguments

  • result::DCResult: DC analysis result
  • component: Component instance
  • pin_pos::Symbol: Positive pin name
  • pin_neg::Symbol: Negative pin name

Returns

  • Float64: Power in watts (positive = dissipated, negative = generated)

Example

R1 = Resistor("R1", 100.0)
# ... build and simulate circuit ...
dc = simulate_qucsator(circ, DCAnalysis())
power = get_component_power(dc, R1, :n1, :n2)
source
CircuitSim.get_frequencyMethod
get_frequency(dataset::QucsatorDataset) -> Vector{Float64}

Get the frequency vector for S-parameter, AC, or other frequency-domain analyses. Looks for 'frequency', 'acfrequency', or 'hbfrequency' (for HB analysis, returns unique frequencies).

Returns

  • Vector of frequency values in Hz

Throws

  • ErrorException if no frequency vector found
source
CircuitSim.get_imag_vectorMethod
get_imag_vector(dataset::QucsatorDataset, name::String) -> Vector{Float64}

Extract imaginary parts of a named vector from the dataset.

source
CircuitSim.get_node_voltageMethod
get_node_voltage(dataset::QucsatorDataset, node_name::String) -> Vector{ComplexF64}

Get voltage at a named node.

Arguments

  • dataset::QucsatorDataset: The simulation results
  • node_name::String: Node name (e.g., "net1", "vout")

Returns

  • Vector of complex voltage values

Example

v_out = get_node_voltage(result, "net5")
source
CircuitSim.get_node_voltageMethod
get_node_voltage(result, node_name::String)

Get voltage at a specific node from simulation results.

Arguments

  • result: DCResult, ACResult, or TransientResult
  • node_name::String: Node name (e.g., "net1", "net2")

Returns

  • For DC: Float64 voltage
  • For AC: Vector{ComplexF64} voltage vs frequency
  • For Transient: Vector{Float64} voltage vs time

Example

dc = simulate_qucsator(circ, DCAnalysis())
v_out = get_node_voltage(dc, "_net1")
source
CircuitSim.get_pin_currentMethod
get_pin_current(result, component, pin::Symbol)

Get current flowing INTO a specific pin of a component from the external circuit.

Current direction convention:

  • Positive current = current flowing INTO the pin (from external circuit)
  • Negative current = current flowing OUT of the pin (to external circuit)

For a voltage source delivering power:

  • Current OUT of nplus (to circuit) → getpincurrent returns NEGATIVE
  • Current INTO nminus (from circuit) → getpincurrent returns POSITIVE

This follows standard node current convention where currents entering a node are positive.

Arguments

  • result: DCResult, ACResult, or TransientResult
  • component: Component instance (must be a voltage or current source)
  • pin::Symbol: Pin name (e.g., :nplus, :nminus, :n1, :n2)

Returns

  • For DC: Float64 current (in amperes)
  • For AC: Vector{ComplexF64} current vs frequency
  • For Transient: Vector{Float64} current vs time

Example

V = DCVoltageSource("V1", 10.0)
R = Resistor("R", 100.0)
# ... build circuit: V.nplus -> R -> GND, V.nminus -> GND ...
dc = simulate_qucsator(circ, DCAnalysis())

# For a source delivering 100mA:
i_nplus = get_pin_current(dc, V, :nplus)   # -100mA (current OUT of source)
i_nminus = get_pin_current(dc, V, :nminus) # +100mA (current INTO source)

# Kirchhoff's current law: i_nplus + i_nminus = 0

Note

Only voltage and current sources report currents in qucsator. For other components, current can be calculated using Ohm's law with voltage and component parameters.

source
CircuitSim.get_pin_voltageMethod
get_pin_voltage(result, component, pin::Symbol)

Get voltage at a specific pin of a component.

Arguments

  • result: DCResult, ACResult, or TransientResult
  • component: Component instance (e.g., R1, C1)
  • pin::Symbol: Pin name (e.g., :n1, :n2, :nplus, :nminus)

Returns

  • For DC: Float64 voltage
  • For AC: Vector{ComplexF64} voltage
  • For Transient: Vector{Float64} voltage vs time

Example

R1 = Resistor("R1", 100.0)
# ... build and simulate circuit ...
dc = simulate_qucsator(circ, DCAnalysis())
v_r1_input = get_pin_voltage(dc, R1, :n1)
v_r1_output = get_pin_voltage(dc, R1, :n2)
v_across_r1 = v_r1_input - v_r1_output
source
CircuitSim.get_probe_currentMethod
get_probe_current(result, probe)

Get current measured by a CurrentProbe.

Arguments

  • result: DCResult, ACResult, or TransientResult
  • probe: CurrentProbe instance or probe name as String

Returns

  • For DC: Float64 current
  • For AC: Vector{ComplexF64} current vs frequency
  • For Transient: Vector{Float64} current vs time

Example

IP = CurrentProbe("IP1")
# ... build circuit with probe ...
dc = simulate_qucsator(circ, DCAnalysis())
i_measured = get_probe_current(dc, IP)
source
CircuitSim.get_probe_voltageMethod
get_probe_voltage(result, probe)

Get voltage measured by a VoltageProbe.

Arguments

  • result: DCResult, ACResult, or TransientResult
  • probe: VoltageProbe instance or probe name as String

Returns

  • For DC: Float64 voltage
  • For AC: Vector{ComplexF64} voltage vs frequency
  • For Transient: Vector{Float64} voltage vs time

Example

VP = VoltageProbe("VP1")
# ... build circuit with probe ...
dc = simulate_qucsator(circ, DCAnalysis())
v_measured = get_probe_voltage(dc, VP)
source
CircuitSim.get_real_vectorMethod
get_real_vector(dataset::QucsatorDataset, name::String) -> Vector{Float64}

Extract real parts of a named vector from the dataset.

source
CircuitSim.get_s_matrix_sizeMethod
get_s_matrix_size(dataset::QucsatorDataset) -> Int

Determine the size of the S-parameter matrix (number of ports).

Returns

  • Number of ports in the S-parameter matrix

Example

n_ports = get_s_matrix_size(result)  # Returns 2 for a 2-port network
source
CircuitSim.get_sparameterMethod
get_sparameter(dataset::QucsatorDataset, i::Int, j::Int) -> Vector{ComplexF64}

Get S-parameter S[i,j] from dataset.

Arguments

  • dataset::QucsatorDataset: The simulation results
  • i::Int: Output port number (1-indexed)
  • j::Int: Input port number (1-indexed)

Returns

  • Vector of complex S-parameter values

Example

s21 = get_sparameter(result, 2, 1)  # Forward transmission
s11 = get_sparameter(result, 1, 1)  # Input reflection
source
CircuitSim.get_timeMethod
get_time(dataset::QucsatorDataset) -> Vector{Float64}

Get the time vector for transient analyses.

Returns

  • Vector of time values in seconds

Throws

  • ErrorException if no time vector found
source
CircuitSim.get_voltage_acrossMethod
get_voltage_across(result, component, pin_pos::Symbol, pin_neg::Symbol)

Get voltage difference across a component (Vpos - Vneg).

Arguments

  • result: DCResult, ACResult, or TransientResult
  • component: Component instance
  • pin_pos::Symbol: Positive pin name
  • pin_neg::Symbol: Negative pin name

Returns

  • For DC: Float64 voltage difference
  • For AC: Vector{ComplexF64} voltage
  • For Transient: Vector{Float64} voltage difference vs time

Example

R1 = Resistor("R1", 100.0)
# ... build and simulate circuit ...
dc = simulate_qucsator(circ, DCAnalysis())
v_across_r1 = get_voltage_across(dc, R1, :n1, :n2)
source
CircuitSim.load_csvMethod
load_csv(filepath::String) -> FileData

Load CSV file with two columns: time, value. First row may be header with column names.

source
CircuitSim.load_file_dataMethod
load_file_data(filepath::String; format::Symbol=:auto) -> FileData

Load time-series data from CSV or Qucs Dataset file.

Arguments

  • filepath: Path to data file
  • format: Format hint (:auto, :csv, :qucs_dataset)

Returns

  • FileData struct with times, samples, and metadata

Supported Formats

CSV Format

Two columns: time, value (comma or semicolon separated) Optional header row with column names

Example:

time,voltage
0.0,0.0
1e-9,1.0
2e-9,0.5

Qucs Dataset Format

Native qucsator format with indep/dep blocks

Example:

<Qucs Dataset 1.0.0>
<indep time 4>
  0.0
  1e-9
  2e-9
  3e-9
</indep>
<dep V1 4>
  0.0
  1.0
  0.5
  0.0
</dep>
source
CircuitSim.load_qucs_datasetMethod
load_qucs_dataset(filepath::String) -> FileData

Load Qucs Dataset format file.

Format:

<Qucs Dataset VERSION>
<indep TIME_NAME N>
  time1
  time2
  ...
</indep>
<dep VAR_NAME N>
  value1
  value2
  ...
</dep>
source
CircuitSim.parse_qucs_datasetMethod
parse_qucs_dataset(output::AbstractString) -> QucsatorDataset

Parse the Qucs dataset format output from qucsator_rf. Returns a QucsatorDataset containing all parsed vectors and status information.

source
CircuitSim.parse_qucs_valueMethod
parse_qucs_value(s::AbstractString) -> ComplexF64

Parse a single value from Qucs dataset format. Handles real values like +1.234e+00 and complex values like +1.234e+00+j5.678e-01

source
CircuitSim.prepare_external_files!Method
prepare_external_files!(comp::AbstractCircuitComponent, netlist_dir::String)

Prepare external files (S-parameters, data files, etc.) for a component before simulation. Default implementation does nothing. Components that need external files should implement this method.

source
CircuitSim.prepare_external_files!Method
prepare_external_files!(comp::FileCurrentSource, netlist_dir::String)

Create data file for FileCurrentSource in the netlist directory when using vector mode. Called by the backend before running qucsator.

source
CircuitSim.prepare_external_files!Method
prepare_external_files!(comp::FileVoltageSource, netlist_dir::String)

Create data file for FileVoltageSource in the netlist directory when using vector mode. Called by the backend before running qucsator.

source
CircuitSim.prepare_external_files!Method
prepare_external_files!(comp::SPfile, netlist_dir::String)

Copy S-parameter file to the netlist directory. Called by the backend before running qucsator.

source
CircuitSim.run_ngspiceMethod
run_ngspice(c::Circuit, analysis::AbstractAnalysis; output_file::String="")

Run ngspice simulation with the given circuit and analysis.

Arguments

  • c::Circuit: The circuit to simulate
  • analysis::AbstractAnalysis: Analysis type (DCAnalysis, ACAnalysis, etc.)
  • output_file::String="": Optional output file path. If empty, uses a temporary file.

Returns

  • (success::Bool, output::String, netlist::String)

Example

success, output, netlist = run_ngspice(c, DCAnalysis())
source
CircuitSim.run_ngspiceMethod
run_ngspice(c::Circuit, analyses::Vector{<:AbstractAnalysis}; output_file::String="")

Run ngspice simulation with multiple analysis types.

source
CircuitSim.run_qucsatorMethod
run_qucsator(c::Circuit, analysis::AbstractAnalysis; output_file::String="", suppress_warnings::Bool=false)

Run qucsator simulation with the given circuit and analysis.

Arguments

  • c::Circuit: The circuit to simulate
  • analysis::AbstractAnalysis: Analysis type (DCAnalysis, ACAnalysis, etc.)
  • output_file::String="": Optional output file path. If empty, uses a temporary file.
  • suppress_warnings::Bool=false: If true, suppress qucsator warnings by redirecting stderr

Returns

  • (success::Bool, output::String, netlist::String)

Example

success, output, netlist = run_qucsator(c, DCAnalysis())
success, output, netlist = run_qucsator(c, ACAnalysis(1.0, 1e6, 101), suppress_warnings=true)
source
CircuitSim.run_qucsatorMethod
run_qucsator(c::Circuit, analyses::Vector{<:AbstractAnalysis}; output_file::String="", suppress_warnings::Bool=false)

Run qucsator simulation with multiple analysis types.

source
CircuitSim.s2zFunction
s2z(S::Matrix, z0=50.0) -> Matrix

Convert S-parameter matrix to Z-parameter matrix for a two-port network.

Arguments

  • S: 2x2 S-parameter matrix
  • z0: Reference impedance (default: 50.0 Ω)

Returns

  • 2x2 Z-parameter matrix

Note

This conversion uses the standard formula Z = z0(I+S)(I-S)⁻¹. For certain ideal passive networks (e.g., perfect series elements at DC), the matrix (I-S) becomes singular, making Z-parameters undefined. This is a fundamental limitation of the parameter representation, not a numerical issue.

Examples

julia> using CircuitSim

julia> z_load = 75.0 + 0.0im;  # 75 Ω resistive load

julia> z0 = 50.0;

julia> gamma = (z_load - z0) / (z_load + z0);  # Reflection coefficient

julia> S = [gamma 0.0; 0.0 0.0];  # One-port (shunt load)

julia> Z = s2z(S, z0);

julia> abs(Z[1,1] - z_load) < 1e-10  # Verify Z11 matches load impedance
true
source
CircuitSim.s2z_seriesFunction
s2z_series(S::Matrix, z0=50.0) -> ComplexF64

Extract series impedance from S-parameter matrix for a symmetric two-port network.

This function uses the S→ABCD conversion approach, which is more robust for series elements than the direct Z-parameter conversion. For a series element, the impedance is the B parameter of the ABCD matrix.

Arguments

  • S: 2x2 S-parameter matrix
  • z0: Reference impedance (default: 50.0 Ω)

Returns

  • Series impedance (complex number)

Note

For a perfect open circuit (S21 = 0), this function returns Inf+0im, representing infinite impedance. This avoids singularity issues that occur with direct Z-parameter conversion for open circuits.

Examples

julia> using CircuitSim

julia> z0 = 50.0;

julia> z_series = 0.0 - 100.0im;  # 100 Ω capacitive reactance

julia> A, B, C, D = 1.0+0.0im, z_series, 0.0+0.0im, 1.0+0.0im;  # ABCD for series element

julia> denom = A + B/z0 + C*z0 + D;

julia> s11 = (A + B/z0 - C*z0 - D) / denom;

julia> s21 = 2.0 / denom;

julia> S = [s11 s21; s21 s11];  # Symmetric

julia> z_extracted = s2z_series(S, z0);

julia> abs(z_extracted - z_series) < 1e-10  # Verify extracted impedance matches original
true
source
CircuitSim.simulate_qucsatorMethod
simulate_qucsator(c::Circuit, analysis::ACAnalysis; suppress_warnings::Bool=false) -> ACResult

Run qucsator AC simulation and return typed AC results.

Example

ac_result = simulate_qucsator(circ, ACAnalysis(1e6, 1e9, 101))
freqs = ac_result.frequencies_Hz
v_out = ac_result.voltages["_net1"]
source
CircuitSim.simulate_qucsatorMethod
simulate_qucsator(c::Circuit, analysis::AbstractAnalysis; suppress_warnings::Bool=false) -> QucsatorDataset

Fallback for other analysis types - returns raw QucsatorDataset.

Example

dataset = simulate_qucsator(circ, HarmonicBalanceAnalysis(1e9))
dataset = simulate_qucsator(circ, NoiseAnalysis(1e6, 1e9, 101, "out", "V1"))
source
CircuitSim.simulate_qucsatorMethod
simulate_qucsator(c::Circuit, analysis::DCAnalysis; suppress_warnings::Bool=false) -> DCResultrnings::Bool=false) -> DCResult

Run qucsator DC simulation and return typed DC results.

Example

dc_result = simulate_qucsator(circ, DCAnalysis())
v_node = dc_result.voltages["_net1"]
i_source = dc_result.currents["V1"]
source
CircuitSim.simulate_qucsatorMethod
simulate_qucsator(c::Circuit, analysis::SParameterAnalysis; suppress_warnings::Bool=false) -> SParameterResult

Run qucsator S-parameter simulation and return typed S-parameter results.

Example

sp_result = simulate_qucsator(circ, SParameterAnalysis(1e9, 10e9, 101))
freqs = sp_result.frequencies_Hz
s21 = sp_result.s_matrix[(2,1)]
source
CircuitSim.simulate_qucsatorMethod
simulate_qucsator(c::Circuit, analysis::TransientAnalysis; suppress_warnings::Bool=false) -> TransientResult

Run qucsator transient simulation and return typed transient results.

Example

tran_result = simulate_qucsator(circ, TransientAnalysis(1e-3, points=1001))
times = tran_result.time_s
v_out = tran_result.voltages["_net1"]
source
CircuitSim.simulate_qucsatorMethod
simulate_qucsator(c::Circuit, analyses::Vector{<:AbstractAnalysis}; suppress_warnings::Bool=false) -> MultiAnalysisResult

Run qucsator simulation with multiple analysis types and return typed results.

Returns a MultiAnalysisResult containing typed results for each analysis that was run.

Example

# Run DC + S-parameter analysis together (DC provides operating point for nonlinear components)
results = simulate_qucsator(circ, [DCAnalysis(), SParameterAnalysis(1e9, 10e9, 101)])

# Access DC results
v_node = results.dc.voltages["_net1"]
i_source = results.dc.currents["V1"]

# Access S-parameter results
freqs = results.sparameter.frequencies_Hz
s21 = results.sparameter.s_matrix[(2,1)]

# Raw dataset still available if needed
dataset = results.dataset
source
CircuitSim.to_qucs_analysisFunction
to_qucs_analysis(analysis::AbstractAnalysis) -> String

Convert an analysis struct to a Qucs netlist analysis command string. Must be implemented for each concrete analysis type.

source
CircuitSim.to_qucs_netlistFunction
to_qucs_netlist(comp::AbstractCircuitComponent) -> String

Generate a Qucs netlist line for a component. Must be implemented for each component type in the component's file.

source
CircuitSim.to_spice_analysisFunction
to_spice_analysis(analysis::AbstractAnalysis) -> String

Convert an analysis struct to a SPICE netlist analysis command string. Must be implemented for each concrete analysis type.

source
CircuitSim.to_spice_netlistFunction
to_spice_netlist(comp::AbstractCircuitComponent) -> String

Generate a SPICE netlist line for a component. Must be implemented for each component type in the component's file.

source
CircuitSim.write_csvMethod
write_csv(filepath::String, times::AbstractVector, samples::AbstractVector; 
          time_name="time", var_name="data")

Write data to CSV format file (two columns with header).

source
CircuitSim.write_qucs_datasetMethod
write_qucs_dataset(filepath::String, times::AbstractVector, samples::AbstractVector;
                   time_name="time", var_name="data")

Write data to Qucs Dataset format file.

source