Examples

The following examples use a few channels and functions that are:

  • speed: The speed of the car in km/h
  • lapctr: The current lapnumber
  • HOLD: The last value calculated by this math-channel
  • dt: Time passed since the last calculated sample of this math-channel
  • sigma: Sums up the expression inside for the whole file up to the current sample

Example with sigma and dt - Integration over time

There is no function for integrating a channel over time. No matter, integration over time is simply the sum of a channel multiplied with the delta-time:

In this example, the speed is integrated over the file. The result is the distance driven (assuming the unit of speed is km/h, we have to divide by 3.6 to receive the distance in meters)

sigma(speed*dt) / 3.6

Example with delta and dt - Derivation of a channel

To derivate a channel by time, you have to divide the change of the channel by the change of time:

delta(channel)/dt

Example with HOLD - Filtering measurement errors

Assuming the speed of a car is between 0 and 400 km/h. If we want to clean the speed-channel from all measurement errors (values outside the valid speed-range) we have to find the error values.

If (speed <0 OR speed >400;0;speed)

Now every wrong value is set to 0. Instead of using this static value, you may want to keep the latest reasonable value. This can be accomplished by inserting the HOLD-function: HOLD returns the previous result of the math channel.

If(speed < 0 OR speed > 400; HOLD; speed)

Examples with sigma, lapsigma, dt, and delta - Calculating “highspeed”-duration for each lap

In this example, you are shown how to use these functions to generate a math channel that calculates the duration driven with more than 200 km/h for each lap. First thing to do is to sum up the time; the car is faster than 200 km/h.

sigma(if(speed > 200; dt; 0))

The if-function returns the time since the last sample when speed is greater 200 and 0 if not. Sigma sums up the results of the if-function to get the time past driving faster than 200 km/h.

Note:

  • This current function sums up the time for the whole file.

If you want the time being calculated for each lap individual, you have to reset the sum at the each laptrigger.

Unfortunately the sigma-function works on the whole file by default, so you need to reset the function after each lap. For that matter, the sigma-function has an optional reset condition.

Sigma(if(speed > 200; dt; 0); delta(lapctr) <> 0)

The new part in this function does exactly that. If the lap number changed (delta(lapctr) <> 0) sigma resets the sum back to zero and starts again.

Note:

  • Instead of delta (lapctr) you can also use {laptrig} <> 0.
    Whatever your choice is, take care of the calculation period of your math channel. Especially {laptrig} is a single peak at the lap trigger and can be easily missed, if the calculation period is set to “Slowest channel”. Therefore using the lap counter is better, but again: If the period is “slowest channel” and your speed is measured faster, you have to select “fastest channel”!
    For more information, see also “Computing Tab”.

There is a faster way to get the same results as well. Use LapSigma for resetting the sum at the beginning of a new lap.

LapSigma(if(speed > 200; dt; 0))

Example with DetectEvent - Brake Pressure

A Simple math function:

DetectEvent({pbrake_fl} > 10)

This generates an output with a non-zero value while the condition is true, in this case, the front brake pressure is greater than 10 bar. For one braking event, this looks like:

  1. Rising Edge: The output is equal to a value of '1' for exactly one sample.
  2. Event True: The output is equal to a value of '2' while the event is true (between the rising and falling edge)
  3. Falling Edge: The output is equal to a value of '-1' for exactly one sample.

Detect Event Supports Multiple Overloads

  • Two additional arguments “BeginDelay” and “EndDelay” were added to DetectEvent. With these arguments DetectEvent delays state changes by the given amount of time.
  • The two arguments are optional and don’t change the signature of the “old” DetectEvent:

DetectEvent(Inactive|Rising|Active|Falling; <BeginCondition>; <BeginDuration>; <BeginDelay>; <EndCondition>; <EndDuration>; <EndDelay>)

  • The kind of the arguments are actually controlled by the given number of arguments. Hereby the first keyword argument (Inactive/Rising|Active|Falling) is always optional and is NOT counted as an argument!

DetectEvent with 6 Arguments

DetectEvent(

Inactive|Rising|Active|Falling;

<BeginCondition>; <BeginDuration>; <BeginDelay>;

<EndCondition>; <EndDuration>; <EndDelay>

)

DetectEvent with 5 Arguments

DetectEvent(

Inactive|Rising|Active|Falling;

<BeginCondition>; <BeginDuration>; <BeginDelay>;

; <EndDuration>; <EndDelay>

)

DetectEvent with 4 Arguments

DetectEvent(

Inactive|Rising|Active|Falling;

<BeginCondition>; <BeginDuration>; ;

<EndCondition>; <EndDuration>;

)

DetectEvent with 3 Arguments

DetectEvent(

Inactive|Rising|Active|Falling;

<BeginCondition>; <BeginDuration>; ;

; <EndDuration>;

)

DetectEvent with 2 Arguments

DetectEvent(

Inactive|Rising|Active|Falling;

<BeginCondition>; <BeginDuration>;

)

DetectEvent with 1 Arguments

DetectEvent(

Inactive|Rising|Active|Falling;

<BeginCondition>;

)

Variables in Math Functions

Math functions support var & local variables

  • var declared variables keep their values between the calculation of one sample to the next. They are initialized once when evaluation the value of the first sample and can be used to “transfer” intermediate results to the next calculation cycle.
  • local declared variables are always initialized when calculating a sample. They can be used to calculate intermediate values – e.g. if an intermediate result is required multiple times in the same expression.

Example #1

Calculate the average wheel speed over a file

var wheelSpeedSum

var wheelSpeedCount

Local wheelSpeedAve := (vwheel_fl + vwheel_fr) / 2

wheelSpeedSum := wheelSpeedSum + wheelSpeedAve

wheelSpeedCount := wheelSpeedCount + 1

wheelSpeedSum / WheelSpeedCount

Example #2

You can even use script blocks within any other function argument. Simple put your expressions within “begin” and “end”

var wheelSpeedSum

var wheelSpeedCount

If (nmot >= 5000;

begin

Local wheelSpeedAve := (vwheel_fl + vwheel_fr) / 2

wheelSpeedSum := wheelSpeedSum + wheelSpeedAve

wheelSpeedCount := wheelSpeedCount + 1

end; 0)

wheelSpeedSum / WheelSpeedCount

Math Functions Support 'NoValue'

  • In math channels you can use “NoValue” to supress any output in WinDarab (e.g. the oscilloscope signal is interrupted).
  • A math function “IsValue” was added to checka input value for “NoValue”.
  • Also all analysis windows (should) work correctly, if they meet a “NoValue”.
  • Note: All comparisions with NoValue will returns false (NoValue is internally a NaN double value)
  • Here’s a sample math function:

if (nmot > 6000; nmot; NoValue)

This channel will show only a signal, if nmot is larger than 6000 – anywhere else there’s nothing!

ValueAtDist

ValueAtDist(<channel>; <dist> [; <LapIndex>])

  • If <LapIndex> is omitted, <dist> is the absolute distance value within the file.

ValueAtDist(<channel>; <xdist>-10)

returns the value 10m before the current position.

  • If <LapIndex> is given, the <dist> argument is a lap distance value.

ValueAtDist(<channel>; 100; LapIndex)

returns the value at position 100m of the current lap.

ValueAtDist(<channel>; lapdist; LapIndex-1)

returns the value at the lap position but in the previous lap

ValueAtTime

ValueAtTime(<channel>; <time> [; <LapIndex>])

  • If <LapIndex> is omitted, <time> is the absolute time value within the file.

ValueAtTime(<channel>; <xtime>-10)

returns the value 10sec before the current position.

  • If <LapIndex> is given, the <time> argument is a lap time value.

ValueAtDist(<channel>; 10; LapIndex)

returns the value at position 10sec of the current lap.

ValueAtDist(<channel>; laptime; LapIndex-1)

returns the value at the same laptime position but in the previous lap

Conditions

Conditions are a smaller size datatype that is meant to represent a boolean value. To access the dialog, from the ribbon: Tools → Mathematics → Conditions

Conditions are stored on disk in the Settings.Ini file. This is located at %WinDarab Install%/Config/Settings.ini.

Alternative to Conditions

  • We recommend not using Conditions, as this functionality is nearing end of life and will be removed in a later version.

Throughout WinDarab, any dialog box where a 'Condition' is specified, you can instead select a Math function where and value not equal to 0 is true.

  • Alternatively, you can enter a condition manually in any of these dialogs