WHY?¶
LT-SPICE is one of the very commonly used SPICE tools for educational purposes. It was developed by the developers of Linear Technology Corp and Analog Devices. User is allowed to draw schematics and simulate the circuit under various conditions. Even though the software seem to give a very good access to and freedom to perform tasks, we cannot perform calculations, manipulate and obtain substantial inferences with just visualizing the data. </br></br> Luckily, This generated data can be brought into Python and worked with! </br>
HOW?¶
LtsPy is a parser that read the Data from .raw file from LTSpice Simulator. We cannot install this library from the pip, It needs to be downloaded and saved in the directory or added to the path. Link to download is here . Once you have it, you just need to load the file and you get everything as a data-frame. Values for every step/variation in every node is available to you in the form of list. </br>
Lets just see it through an example
CASE - CHARGING AND DISCHARGING OF CAPACITOR¶
Given is a circuit to show charging and discharging of a capacitor. It is to be noted that the Voltage source V1 provides a HIGH signal for 1ms, followed by a LOW signal for another same time, thus making it connect to Vcc for sometime then opening the circuit and letting the capacitor discharge.</br>
Once we run this, there is a .raw file generated and saved in the same directory as the schematic. let the path and name of the file be '/path/to/file/capacitor.raw'. Now we get to the Python part of it. I am doing this in Jupyter Notebook, but you can code it in any way.
import ltspy3
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-darkgrid')
data = ltspy3.SimData('/home/raghuttam/Documents/LTspiceXVII/basic-electronic-circuits/Capacitor.raw')
Checking the Available parameters to that can be worked with.
data.variables
[b'time', b'V(vo)', b'V(n001)', b'I(C1)', b'I(R1)', b'I(V1)']
t = data.values[0]
v_capacitor = data.values[1]
Visualizing the data!
plt.plot(t,v_capacitor)
plt.vlines([0.0005],0,5,linestyle = "dashed",colors='red')
plt.title("Capacitor charging and Discharging")
plt.xlabel("Transient time ->")
plt.ylabel("Capacitor Voltage ->")
plt.savefig("Cap.png")
plt.show()
This is just an example, but this method can be used to compute various data to draw inferences! Hope this would be of some help!