Page 1 of 1

appling calculations to a signal recorded with the tracer

Posted: Fri 4. May 2012, 08:51
by engineer
Hello,

I am wondering how or if it is possible to calculate, for example the derivative of an signal, which was recorded via the Peak-CAN Tracer and was imported to a plot file?
Could you kindly provide some sample code.

Thanks in advance

Re: appling calculations to a signal recorded with the trace

Posted: Fri 4. May 2012, 15:12
by M.Maidhof
Hi,

this will be more or less a mathematical problem, do you have the mathematical skills to build the derivative of a signal based on trace files? For me, this will be some days study and work :geek: . Perhaps there are some more mathematical genius out there, which could solve that problem.

regards

Michael

Re: appling calculations to a signal recorded with the trace

Posted: Fri 4. May 2012, 18:04
by engineer
Hallo,

It is not the mathematical skills that are difficult to me in this matter, it is more how can I handle data from the tracer which are present as a recorded .trc file and do the math to it? Could i do this operation by a Macro?

Thanks in Advance.

Re: appling calculations to a signal recorded with the trace

Posted: Tue 8. May 2012, 14:45
by K.Wolf
Hi,

yes you can do that with a Macro. Suppose you have a recorded signal with the name 'Speed' that you would like to use for further calculations. If you have already imported the trace into a Plotter, the code would look like this:

Code: Select all

Sub PlotToSpeed()
    Dim doc, plotter, channel, i, speed
    ' Open the plotter file
    Set doc = Documents.Open("MyPlot.plt")
    ' Obtain a reference to the Plotter object
    Set plotter = doc.ActiveWindow.Object
    ' Suppose the desired signal is assigned to channel 1
    Set channel = plotter.Channels(1)
    ' Iterate through all data points and access the speed values
    For i = 0 To channel.DataCount-1
        speed = channel.DataY(i)
        PrintToOutputWindow speed  ' Or any other processing
    Next
End Sub
You can also extract the speed values directly from the tracer:

Code: Select all

Sub TraceToSpeed()
    Dim doc, trc, sym, SpeedVar, msgs, msg, speed
    ' Open the trace file
    Set doc = Documents.Open("MyTrace.trc")
    ' Obtain a reference to the Tracer object 
    Set trc = doc.ActiveWindow.Object.Tracer
    ' Get the Symbol object that contains the speed CAN variable
    ' to filter the Tracer contents
    Set sym = SymbolsManager("MySymbols").Item("MySymbol")
    ' Now filter the Tracer contents using the Symbol object
    Set msgs = trc.Messages.FindSymbol(sym)
    ' Get the Variable object that contains the neccessary information to
    ' extract the speed values from the CAN message data bytes 
    Set SpeedVar = Signals("Speed").Source
    ' Iterate through all found messages and extract the speed values
    For Each msg in msgs
        speed = SpeedVar.MessageToValue(msg)
        PrintToOutputWindow speed    ' Or any other processing
    Next
End Sub