SYNOPSIS

The program LeCroy2raw.frt is able to:

Additionally, it is possible to:

The primary purpose of the program is to read a LeCroy file and to write it out as an LTSPICE file. The command sequence in this case is:

	FORTH> S" C2I_90Watt_binary.trc" READ-SCOPE  ok
	FORTH> S" myname.raw" WRITE-SCOPE2raw  ok

The result of the read operation can be plotted with PLOT-SCOPE and will look like Fig. 1.

LeCroy data
Figure 1. Sample LeCroy data file read in.

INSTALLATION

To use READ-STEPS or READ-EXPORT, Matlab must be installed on the target machine.

To setup Forth, run the install.cmd on the CD (answer "yes" to all questions).

In case the above script fails:

  1. copy all files to c:\dfwforth
  2. set environment variables
    	IFORTH = c:\dfwforth
    	IFORTHBIN = c:\dfwforth\ifwinnt\bin\iforth.img
    
  3. create a shortcut to c:\dfwforth\ifwinnt\bin\iwserver.exe .
  4. copy 8514fix.fon and 8514oem.fon from the c:\dfwforth\ifwinnt\bin to the c:\windows\fonts directory
  5. Make the location of Matlab known to Forth by editing the file c:\dfwforth\include\mlabeng.frt . Look for the text
    : MATLAB? ( -- c-addr u ) S" C:\Program Files\MATLAB\R2007b\bin\win32\" ; PRIVATE
    (around line 52) and change the path to where Matlab is located on your machine. Older or newer Matlab executables will work too.

BUGS

On Dell computers, sometimes the monitor plots are drawn incorrectly (Lines are drawn so they completely fill the area to the X-axis). This is a hardware problem with the graphics accelerators in these machines that can be corrected by gradually decreasing the hardware acceleration fader (right-click on desktop -> Properties -> Settings -> Advanced -> Troubleshoot). Sometimes it suffices to turn off "write combining."

PLEASE NOTE

Strings are prefixed with S" and a space, and followed by a quote (").

Floating-point numbers are entered using exponential notation: 1e-3 and not 0.001 .

Integer numbers should only contain [+|-]{ 0 1 2 3 4 5 6 7 9 }*

The commandline can be edited, try the arrow keys, Home, End, Ins, Del, ESC. Typing a few characters followed by TAB tries to match strings in the history buffer. Typing a few characters and Ctrl-PgDn tries to match a filename. Leave the program by typing BYE when you want to permanently remember the history.

The commands CD and DIR work for navigation.

Copy and paste with the mouse (left button).

Functionkey F2 prints some help (try F1).

BACKGROUND INFORMATION

The current version of this program is independent of Matlab, no Matlab programs need to be installed. However, it is still possible to:
  1. make intermediary plots,
  2. filter a specific signal or signals,
  3. scale, offset, and crop individual channels.

Filtering and plotting of the signals for monitoring purposes is done in Forth. The plotting commands in Forth are a bit awkward, figures don't look particularly nice, and printing or clipboarding is cumbersome. Because the window contents are not automatically refreshed, you should make sure that the Forth Graphics Terminal window is open and not obscured by other windows. Better looking output is possible by using the LTSPICE waveform viewer once a .raw file has been created. Alternatively it is possible to install the free Gnuplot program and set an option in the LeCroy2raw.frt file to use this viewer.

LTSPICE

Data is read from disk with the command
	   FORTH> S" LC_ini.raw" READ-RAW
	
The data from the read *.raw file is put in the columns of the matrix s:data{{ . The 0th column is reserved for the simulation time. The other columns are for the simulated signals, and their index and name can be found by typing .RAW-HEADER:
	
	   FORTH> .raw-header
	   Title: * C:\Program Files\LTC\LTSPICEIV\mylib\LC_ini.asc
	   Date: Sun Nov 04 23:00:32 2007
	   Plotname: Transient Analysis
	   Flags: real forward
	   No. Variables: 7
	   no. Points: 7491
	   Offset: 1.031072e-6
	   Command: Linear Technology Corporation LTspice
	   Variables:
		 0      time    time
		 1      V(n001) voltage
		 2      V(cap)  voltage
		 3      I(C1)   device_current
		 4      I(L1)   device_current
		 5      I(I1)   device_current
		 6      I(V1)   device_current ok
	

As you can see, the file LC_ini.raw contains 6 signals in addition to time. Column 2 of s:data{{ contains the V(cap) signal. We don't explain here how to print and manipulate s:data{{ , but it is possible (print rows 0 to 5 of column 2):

	   FORTH> s:data{{ 0 5  2 2 }}print[]
	    -5.102113e-002
	    -5.591273e-002
	    -6.079427e-002
	    -6.566575e-002
	    -7.052717e-002
	    -7.537852e-002 ok
	

This data can be viewed when you give the ( n -- ) PLOT-RAW or ( n -- ) ( F: r -- ) FPLOT-RAW commands. E.g. plotting the second column, V(cap), is done with:

	   FORTH> 2 PLOT-RAW 
	
or with
	   FORTH> S" V(cap)" NAME->TRACE PLOT-RAW 
	
The result of the plot command is shown in Fig. 2.

raw data
Figure 2. Sample LTSPICE data file read in.

Finally, it is possible to write out the data as a new LTSPICE raw file, with the Forth command S" myname.raw" WRITE-raw2raw . Did you use FPLOT-RAW, filtered data is written out. Did you use PLOT-RAW (or no plot command), the original raw data is written to the new .raw file. Note that using FPLOT-RAW (0.0e < r < 1.0e) permanently modifies s:data{{. Therefore, issuing FPLOT-RAW twice may have unexpected results (but is useful for arbitrary heavy filtering of a trace).

It bears noticing that, as the LTSPICE samples are in general not equidistant in time, FPLOT-RAW is not trivial. The used algorithm first resamples, then filters, then interpolates back to the original timesteps. It is more efficient to filter oscilloscope data before writing it to a raw file.

LeCroy

The data from a .trc file is put in the array data{ . Because the oscilloscope uses a fixed time-base, the time itself is not stored in a .trc file. However, for convenience, Forth synthesizes a time axis in the array time{ . All the information that is used to do this can be viewed with the .TRC-HEADER command:
	   FORTH> LECROY:BIN:SCOPE TO SCOPE  ok
	   FORTH> S" C2I_90Watt_binary.trc" READ-SCOPE  ok
	   FORTH> .TRC-HEADER
	     COMM_TYPE        : 1 bytes
	     l:points         : 2500002 samples
	     VERTICAL_GAIN    : 44.19456 mV
	     VERTICAL_OFFSET  : 0  V
	     HORIZ_INTERVAL   : 19.999999 us
	     HORIZ_OFFSET     : -4.25365 us ok
	

The first command (... TO SCOPE) sets up the READ-SCOPE command to expect a LeCroy binary format. Other formats are LECROY:SCOPE (ASCII text for LeCroy type WS434), YOKOGAWA:SCOPE (ASCII text for Yokogawa ';' delimited text files), and YOKOGAWA:1:SCOPE, YOKOGAWA:2:SCOPE, YOKOGAWA:3:SCOPE (channels 1, 2, or 3 for the Yokogawa DL1600). Normally only the YOKOGAWA:1:SCOPE, YOKOGAWA:2:SCOPE and YOKOGAWA:3:SCOPE commands are needed as the program decides the file types for the other possibilities automatically.

The output shows that the oscilloscope's samples have a resolution of 8 bits ( COMM_TYPE ), and are spaced 20 microseconds apart ( HORIZ_INTERVAL ). Type data{ 0 5 }print[] to show the first 6 samples:

	   FORTH> data{ 0 5 }print[]
	      0.000000e+000 -4.419456e-002  4.419456e-002  0.000000e+000 -4.419456e-002  4.419456e-002 ok
	   FORTH> time{ 0 5 }print[]
	      0.000000e+000  2.000000e-005  4.000000e-005  6.000000e-005  8.000000e-005  1.000000e-004 ok
	

The scope trace can be plotted with PLOT-SCOPE and filtered with 0.01e PLOT-FSCOPE . To write the (un)filtered data as an LTSPICE file, use the command S" test.raw" WRITE-SCOPE2raw. To show the result of the noise filter, compare Fig. 3 and Fig. 4 after the commands

	FORTH> S" C2_Vmult.trc" READ-SCOPE  ok
	FORTH> PLOT-SCOPE  ok
	FORTH> 0.01e FPLOT-SCOPE  ok
	

noisy LeCroy data
Figure 3. Noisy LeCroy data.

Denoised LeCroy data
Figure 4. Denoised LeCroy data.
Using Gnuplot, the result of the plot command looks like Fig. 5.

Denoised LeCroy data
Figure 5. Denoised LeCroy data, shown by Gnuplot.

Multi-file handing

Arbitrary combinations of (un)filtered text and/or binary trace files can be merged into a single raw file for use by LTSPICE or the program itself (MWRITE-SCOPE2raw). In such cases it is frequently needed to cut a specific time segment from a file, scale the amplitude of the signal, or add an offset to all values. With LeCroy2raw this can be done with a sequence of commands. The first step is to read all the required single traces (in *.trc, *.txt or *.csv files) and combine them in a single LTSPICE compatible .raw file:
	   FORTH> LECROY:SCOPE TO SCOPE  ok
	   FORTH> S" V(fswhint).120" S" I(L6_1).120" S" I(L6_2).120" S" I(L6_3).120" 4 
	          S" vi_120.raw"   -4.07e-3 4.263333e-3   0.1e  MWRITE[]-FSCOPE2raw  ok
	

The command MWRITE[]-FSCOPE2raw is used here to read four different files and combine them to vi_120.raw. Only the parts of the files between -4.07 ms and 4.263333 ms are used, and each segment is filtered by a digital Butterworth filter with parameter 0.1e. When filtering is not needed but only a small segment is needed, specify the MWRITE[]-SCOPE2raw command. When unfiltered complete files are needed, specify MWRITE-SCOPE2raw. Note that the original files were ASCII from a LeCroy oscilloscope, so we specified that with LECROY:SCOPE TO SCOPE before issuing the MWRITE.. command. (Here the explicit SCOPE command is needed because the file extension of the original files was changed.) The SCOPE setting stays valid until we change it again.

The second step is scaling and offsetting of the signals. This is done by first reading the raw file back into memory, than applying scale and offset to individual traces:

	   FORTH> S" vi_120.raw" READ-RAW  ok
	   FORTH>   1   0.0091e    N-LOWPASS  ok
	   FORTH>   10  PI         SCALE-RAW   10 1.2e OFFSET-RAW  ok
	   FORTH>   21  1.414e     SCALE-RAW  ok
	   FORTH>   39  13.4e 1/F  SCALE-RAW  ok
	   FORTH> S" vi_120.raw" WRITE-raw2raw 	ok
	

Here vi_120.raw is first read with the READ-RAW command (no SCOPE setting, this is always in LTSPICE binary uncompressed format). Then, channel 10 is multiplied by PI, channel 21 by 1.414e, and channel 39 by 1/13.4e. For some reason we also apply a second low-pass filtering to channel 1, by a factor of 0.0091e. Finally, channel 10 is offset by 1.2e, and the result is written back to vi_120.raw again.

Experts

It is possible to access the filter routines used by the program to define higher or lower order Butterworth characteristics (modify the word LOWPASS) or change the averaging behavior. By default, the filtering method is AVERAGING, where the parameter 0.01e means "average over 100 samples."