# 2.2.10 levelcrossing

## Brief Information

Find X values at a given Y value

## Command Line Usage

 1. levelcrossing iy:=col(2) level:=2; 

2. levelcrossing iy:=col(2) level:=500 direction:=<new> xindex:=<new> type:=left pts:=2; 

## Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Input iy

Input

XYRange

<active>
Specify the input dataset.
Crossing Level level

Input

double

0
Specify the Y value for the level. Then the X-Function will detect the crossings for this level.
ncrossing

Output

int

<new>
Specify the output for the number of the crossing points. This variable is not shown in the dialog box, but you can get the value of this variable by running levelcrossing.ncrossing=; in the Command Window after executing this X-Function.
X Values of Crossing oy

Output

vector

<new>
Specify the output for the X values of the crossing points, and designated as X column.
Directions direction

Output

vector

<new>
Specify the output for the directions of the crossing behaviors, 1 for upward, -1 for downward, and 0 for differentiation is zero, and designated as Y column.
X Indices xindex

Output

vector

<new>
Specify the output for the X indices of the crossing points, designated as Label column.
Y Crossing Values yval

Output

vector

<new>
Specify the output for the Y values, which will all be the same as input level crossing value, designated as Y column.
Nearest Type type

Input

int

0
Specify how to output the X index of the crossing point when the crossing point is interpolated but not the point of the original data.

Option list:

• any:Any
The index of the point, which is closest to the crossing point, will be output.
• left:Left
The index of the point, which is to the "left" side of the crossing point, will be output.
• right:Right
The index of the point, which is to the "right" side of the crossing point, will be output.
Duration Points pts

Input

int

1
This variable is used to control the output of a pair of level crossing points. The distance (indices) of the pair of points should not be less the specified duration, or both crossing points will be discarded. Only positive integer is acceptable. Duration should not be larger than Deadtime.
Deadtime Points deadtime

Input

int

1
This variable determines how a level crossing point is treated as valid and output.
• The first found level crossing point will be treated as "valid".
• If other crossing points are found in the deadtime distance (indices) following the first point, they will be considered as "invalid" and thus ignored.
• If the next found crossing point is out of the deadtime distance (indices),
• if the point falls in the duration (indices) following the first point, both this point and the first will be considered as "invalid" and thus ignored.
• if the point locates out of the duration (indices) following the first point, this point will be considered as "valid" and output.

... and so forth

Only positive integer is acceptable.

## Description

This X-Function finds the locations (X values) where the input curve crosses a specified level. For example, if you set the level to be 0, the zero crossing points (where the curve passes 0) will be output. Such zero crossing points could be meaningful for some special curves. Outputs are selectable, including X values, X indices, crossing directions, and Y crossing values. Also, duration can be specified to get rid of some noise.

Note that linear interpolation could be used to get the locations.

## Examples

### Example1

In the following example, we will find the locations where the curve crosses 500.

1. Use the Import Wizard to import the data <Origin Installation Directory>\Samples\graphing\waterfall.dat into an empty worksheet.
2. Highlight col(B) and open the levelcrossing dialog by entering levelcrossing -d; in the Command Window.
3. Enter 500 after Crossing Level. Other settings as following image shows.
4. Click the OK button, four new columns will be added to the worksheet, and the X coordinates corresponding to the 500 level, crossing directions, the X indices and Y crossing values will be output there.
5. Run levelcrossing.ncrossing=; in the Command Window, the number of intersection points will be shown as:
  LEVELCROSSING.NCROSSING=8


### Example 2

This example is to show you how the duration and deadtime effect the result you get.

1. Create a new workbook. Import data <Origin Installation Directory>\Samples\Curve Fitting\Multiple Peaks.dat by Data: Import From Files: Single ASCII.
2. Highlight col(C) and open the levelcrossing dialog by entering levelcrossing -d; in the Command Window.
3. Enter 100 for Crossing Level, 5 for Duration Points. Leave other settings as default.
4. In the source worksheet, click the green lock and select Change Parameters. This time, enter 10 for Duration Points and 20 for Deadtime Points.

Keywords:crossing, threshold