Circuit Examples
Ready-to-use SPICE circuits to help you learn and get started quickly. Copy any example and customize it for your needs.
Filters
BeginnerngspiceLTspice
Low Pass RC Filter
A simple first-order RC low pass filter with 1kHz cutoff frequency.
* Low Pass RC Filter * Cutoff frequency: 1kHz * Compatible with ngspice and LTspice Vin in 0 SINE(0 1 10k) R1 in out 1.59k C1 out 0 100n .tran 1u 5m .save V(in) V(out) .end
BeginnerngspiceLTspice
High Pass RC Filter
A first-order RC high pass filter that blocks DC and low frequencies.
* High Pass RC Filter * Cutoff frequency: 1kHz * Compatible with ngspice and LTspice Vin in 0 SINE(0 1 100) C1 in out 100n R1 out 0 1.59k .tran 10u 50m .save V(in) V(out) .end
IntermediatengspiceLTspice
Second-Order Low Pass Filter
A Sallen-Key active low pass filter with sharper rolloff.
* Sallen-Key Low Pass Filter * Second-order active filter * Compatible with ngspice and LTspice Vin in 0 SINE(0 1 1k) * Filter components R1 in n1 10k R2 n1 inv 10k C1 n1 out 10n C2 inv 0 10n * Unity gain buffer (ideal op-amp) * Output follows non-inverting input (out) Eopamp out 0 out inv 100k .tran 1u 10m .save V(in) V(out) .end
Basic
BeginnerngspiceLTspice
Voltage Divider
A basic resistive voltage divider that reduces voltage by a fixed ratio.
* Voltage Divider * Vout = Vin * R2/(R1+R2) = 6V * Compatible with ngspice and LTspice V1 in 0 DC 12 R1 in out 10k R2 out 0 10k .op .end
BeginnerngspiceLTspice
LED with Current Limiting Resistor
Basic LED circuit with a resistor to limit current to safe levels.
* LED with Current Limiting Resistor * LED forward voltage ~2V, target current ~20mA * Compatible with ngspice and LTspice V1 vcc 0 DC 5 R1 vcc led 150 D1 led 0 LED .model LED D(Is=1e-20 N=1.5 Rs=0.5) .op .end
BeginnerngspiceLTspice
RC Integrator
Converts a square wave input into a triangular wave output.
* RC Integrator Circuit * Integrates input signal over time * Compatible with ngspice and LTspice * Square wave input Vin in 0 PULSE(0 5 0 1n 1n 0.5m 1m) R1 in out 10k C1 out 0 100n .tran 1u 5m .save V(in) V(out) .end
Amplifiers
IntermediatengspiceLTspice
Inverting Op-Amp
An inverting amplifier using an ideal op-amp with gain of -10.
* Inverting Op-Amp Amplifier * Gain = -Rf/Rin = -10 * Compatible with ngspice and LTspice * Input signal (0.5V amplitude, 1kHz) Vsig in 0 SINE(0 0.5 1k) * Inverting amplifier circuit R1 in inv 10k R2 inv out 100k * Ideal op-amp using voltage-controlled source * E<name> <n+> <n-> <nc+> <nc-> <gain> Eopamp out 0 0 inv 100k .tran 1u 5m .save V(in) V(out) .end
IntermediatengspiceLTspice
Non-Inverting Op-Amp
A non-inverting amplifier with gain of 11 (1 + Rf/R1).
* Non-Inverting Op-Amp Amplifier * Gain = 1 + Rf/R1 = 11 * Compatible with ngspice and LTspice * Input signal (0.5V amplitude, 1kHz) Vsig in 0 SINE(0 0.5 1k) * Non-inverting amplifier circuit R1 inv 0 10k R2 inv out 100k * Ideal op-amp using voltage-controlled source Eopamp out 0 in inv 100k .tran 1u 5m .save V(in) V(out) .end
Power
IntermediatengspiceLTspice
Full-Wave Bridge Rectifier
AC to DC conversion using four diodes in a bridge configuration.
* Full-Wave Bridge Rectifier * Converts AC to pulsating DC * Compatible with ngspice and LTspice * AC source (12V peak, 60Hz) Vac in 0 SINE(0 12 60) * Bridge rectifier D1 in outp D1N4148 D2 0 outp D1N4148 D3 outn in D1N4148 D4 outn 0 D1N4148 * Load and filter capacitor Rload outp outn 1k Cfilter outp outn 100u .model D1N4148 D(Is=2.52e-9 Rs=0.568 N=1.752) .tran 10u 100m .save V(in) V(outp,outn) .end
IntermediatengspiceLTspice
Voltage Regulator (Zener)
Simple voltage regulation using a Zener diode.
* Zener Diode Voltage Regulator * Regulates varying input to stable 5.1V output * Compatible with ngspice and LTspice V1 in 0 DC 12 Rs in out 470 Dz 0 out ZENER Rload out 0 1k * 5.1V Zener diode model .model ZENER D(Is=1e-14 BV=5.1 IBV=1m) .dc V1 6 15 0.1 .save V(in) V(out) .end
Python Signals
IntermediatengspiceLTspice
Python Signals: Custom PWL
Use Python to generate a custom PWL waveform for simulation.
* Circuit using Python-generated PWL signal
* The ${CUSTOM_PWL} variable is exported from Python
Vin in 0 PWL(${CUSTOM_PWL})
R1 in out 1k
C1 out 0 100n
.tran 1u ${SIM_TIME}
.save V(in) V(out)
.end
* -------- Python Signals Code --------
* import numpy as np
*
* # Generate a damped sine wave as PWL
* t = np.linspace(0, 10e-3, 200)
* freq = 500 # 500 Hz
* tau = 5e-3 # decay time constant
* v = np.exp(-t/tau) * np.sin(2*np.pi*freq*t)
*
* # Convert to PWL string: "t1 v1 t2 v2 ..."
* pwl = " ".join(f"{ti:.9e} {vi:.9e}" for ti, vi in zip(t, v))
* export("CUSTOM_PWL", pwl)
* export("SIM_TIME", 10e-3)IntermediatengspiceLTspice
Python Signals: Noise Source
Generate a random noise signal using Python for transient simulation.
* Circuit with Python-generated noise source
* Uses random.gauss() for Gaussian noise
Vnoise noise 0 PWL(${NOISE_PWL})
R1 noise out 10k
C1 out 0 10n
.tran 1u 10m
.save V(noise) V(out)
.end
* -------- Python Signals Code --------
* import random
* import numpy as np
*
* random.seed(42) # Reproducible results
* t = np.linspace(0, 10e-3, 500)
*
* # 10mV RMS Gaussian noise
* noise_rms = 10e-3
* v = [random.gauss(0, noise_rms) for _ in t]
*
* pwl = " ".join(f"{ti:.9e} {vi:.9e}" for ti, vi in zip(t, v))
* export("NOISE_PWL", pwl)