LeCroy2raw.frt is able to:
LeCroy binary data files (8 and 16 bit types, automatically),
LeCroy and Yokogawa ASCII data files (*.txt and *.csv),
LTSPICE raw uncompressed binary file,
LTSPICE raw uncompressed binary file.
Additionally, it is possible to:
LTSPICE uncompressed binary raw data files,
LTSPICE data out as another LTSPICE raw uncompressed binary file,
LTSPICE text files containing the result of .STEP command executions.
In this case each probe can be exported to a separate Matlab matrix with columns = steps.
The data in these matrices is equidistantly resampled (The LTSPICE original is not uniform).
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 file read in. |
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:
c:\dfwforth
IFORTH = c:\dfwforth IFORTHBIN = c:\dfwforth\ifwinnt\bin\iforth.img
c:\dfwforth\ifwinnt\bin\iwserver.exe .
8514fix.fon and 8514oem.fon from the c:\dfwforth\ifwinnt\bin to the c:\windows\fonts directory
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.
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).
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.
FORTH> S" LC_ini.raw" READ-RAWThe 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-RAWor with
FORTH> S" V(cap)" NAME->TRACE PLOT-RAWThe result of the plot command is shown in Fig. 2.
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 (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.
.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
LeCroy data. |
LeCroy data. |
Gnuplot, the result of the plot command looks like Fig. 5.
LeCroy data, shown by Gnuplot. |
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.
LOWPASS) or change the averaging behavior.
By default, the filtering method is AVERAGING, where the parameter 0.01e means "average
over 100 samples."