Merging Traces

From Elsys Wiki - Help and Recources for TranAX and TraNET DAQ
Jump to: navigation, search

With the function MergeTraces you can merge multiple waveforms into one waveform. This can be useful if you want to separate specific events from your measured curve. You are also able to pick single events from a Multiblock measurement and put specific blocks into a new waveform.

Merge events from Continuous Measurement into another trace

If you have a continuous measurement which is fairly long and just have several events which are interesting then you can merge those events into a new trace (tpc5). The function MergeTraces will help you with this task.

; Works with TranAX 4.0.0.1828 or newer

; Don't close files. Improves performance.
SetEnvironment(1, False)

; Don't save files. Improves performance.
SetEnvironment(5, True)

; File which has to be analyzed
filepathToAnalyze = "X:\TBE\T1_1428_USS002_16kHz_anschleifen.tpc5"

; File destination
filepathForMergedTraces = "mergedTrace.tpc5"

listOfTraces = List()
nrOfTraces = NTracesInFile(filepathToAnalyze)

; Keep all traces from the file in a list
for chanIdx = 0 to nrOfTraces-1 step 1.0 
    trace = File(filepathToAnalyze, chanIdx)
	listOfTraces() = trace
next

; Evaluate start and end time of trace number 2
trace2 = listOfTraces(2)
tstart = TBegin(trace2)
tstop = TEnd(trace2)

; We use a constant time window for slicing the events
sliceLength[s] = 170e-6

; Loop all events (positive slope) in trace2
for each timeVal in EnEvents(trace2, 0, tstart, tstop, 1, 0.25) 
    for chanIdx = 0 to nrOfTraces-1 step 1.0 
        trace = listOfTraces(chanIdx)
        slicedTrace = Slice(trace, timeVal, timeVal + sliceLength)
        channelName = GetChName(trace)
        
        ; Merge the slice into the file.
        MergeTraces(filepathForMergedTraces, channelName, chanIdx, slicedTrace)
    next
next

; Close the file
CloseFile(filepathForMergedTraces)

Graphical result in TranAX YT Waveform

tumb