Sure, here is the PySpice code for an LC tank circ...
# adiabatonauts
a
Sure, here is the PySpice code for an LC tank circuit: Python
Copy code
import math
import numpy as np
import matplotlib.pyplot as plt
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()
from PySpice.Plot.BodeDiagram import bode_diagram
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

# Define circuit parameters
inductance = 10@u_mH
capacitance = 1@u_uF

# Create circuit
circuit = Circuit('LC Tank Circuit')

# Add voltage source
circuit.SinusoidalVoltageSource('input', 'in', circuit.gnd, amplitude=1@u_V)

# Add inductor
circuit.L(1, 'in', 1, inductance)

# Add capacitor
circuit.C(1, 1, circuit.gnd, capacitance)

# Perform AC analysis
simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = <http://simulator.ac|simulator.ac>(start_frequency=100@u_Hz, stop_frequency=10@u_kHz, number_of_points=100, variation='dec')

# Calculate resonant frequency and quality factor
resonant_frequency = 1 / (2 * math.pi * math.sqrt(inductance * capacitance))
quality_factor = 1 / circuit.L['1'].resistance * math.sqrt(inductance / capacitance)

# Plot bode diagram
figure, axes = plt.subplots(2, figsize=(20, 10))
plt.title("Bode Diagram of LC Tank Circuit")
bode_diagram(analysis, axes=axes)

# Print resonant frequency and quality factor
print("Resonant frequency = {:.1f} Hz".format(resonant_frequency))
print("Factor of quality = {:.1f}".format(quality_factor))
This code will create an LC tank circuit in PySpice, perform an AC analysis, and plot the bode diagram. The resonant frequency and quality factor of the circuit will also be printed to the console. Sources 1. https://pyspice.fabrice-salvaire.fr/releases/v1.4/examples/filter/rlc-filter.html