Comparing LTspice and Oscilloscope Waveforms

Sometimes you want to see how closely your SPICE simulation matches the real circuit as seen by your scope.  Here is a utility which imports an LTspice waveform and the data from your scope, overlays them, and allows you to slide one back and forth to line them up.  It’s called CompareWaveforms, and here’s what it looks like:

CompareWaveformsScreen

You select the files to compare, press Compare, and use the long slider along the bottom to line up the waveforms.  You can save the plot as a .png file to include in a report.

The formats of the input files are straightforward.  The LTspice file is the direct output of File / Export from the LTspice waveform window.  The scope file is a .csv (Comma-Separated Values text file) with two header lines at the beginning (because that’s what my scope puts out).  Each subsequent line is of the form time-in-seconds, volts.  These are easily changed in the Python source if you wish.  The scope data file may have a time offset due to trigger delay or trace positioning, so that is subtracted from the scope time measurements to match the LTspice time which starts at zero.

Note on waveform comparison: you may want to include the loading of your scope probe in your simulation.  My probes are 12 pF in parallel with 2.2 Mohm, which can alter the simulator waveforms.  Also, make your total simulation time equal to the sweep time of your scope (typically the time/div times 10), and make the start of the waveform roughly the same.  CompareWaveforms allows you to adjust time +/-10% of the total sweep.

You can get a Windows installation package for CompareWaveforms (42 MB) from here.  No Python is required — it is self-contained.  If you want the Python 3.4 source (6.6 kB) and some sample waveform files you can get that here.  Good luck and have fun!