Skip to content

Instantly share code, notes, and snippets.

@jondoesntgit
Created September 25, 2018 22:34
Show Gist options
  • Save jondoesntgit/6afbb1bf8d3ccbaa97d5a2fa2a2c9693 to your computer and use it in GitHub Desktop.
Save jondoesntgit/6afbb1bf8d3ccbaa97d5a2fa2a2c9693 to your computer and use it in GitHub Desktop.
LTSpice to Python
# Some regular expression for parsing LTSpice gain files
import re
regex = r"^([\.0-9e+-]+)\t\(([\.0-9e+-]+)dB,([-0-9\.e+-]+)°\)"
path = # Insert your path here
with open(path) as file:
matches = re.finditer(regex, file.read(), re.MULTILINE)
freq, gain, phase = zip(*[(float(m.group(1)), float(m.group(2)), float(m.group(3))) for m in matches])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment