LEVELDURATION

Purpose:

Returns an XY series of the locations where a series crosses a level and remains above the level for a specified duration.

Syntax:

LEVELDURATION(series, level, duration, edgeout, tol)

(r, f) = LEVELDURATION(series, level, duration, edgeout, tol)

series

-

A series or array, the input series.

level

-

Optional. A real, the rising and falling crossing threshold. Defaults to 0.0.

duration

-

Optional. A real, the time duration required between crossings. Defaults to 1.0.

edgeout

-

Optional. An integer, the output value alignment. The output value will be placed to the left or right of the actual crossing point as specified below:

0

:

Left if input edge rising, right if falling (default).

1

:

Right on rising, left on falling.

2

:

Right on rising, left on falling.

3

:

Left whether rising or falling.

4

:

Linearly interpolate the X crossing values if necessary.

tol

-

Optional. A real, the level crossing tolerance. Defaults to EPS.

Returns:

An XY series where the X values are the rising edges of where the series remains above level for duration. The Y values are the same as level.

 

(r, f) = LEVELDURATION(series, level, duration, edgeout, tol) returns two XY series, the rising (starting) edges and the falling (ending) edges.

Example:

W1: gsin(10000, 1/1000, 0.3)

W2: levelduration(w1)

W3: W1;overp(w2);setplotstyle(1,2);setsym(8, 2)

 

W1 contains the source series.

 

W2 returns a 3 point XY series of the rising edges where W1 crosses 0.0 and remains above 0.0 for 1 second.

 

W3 displays the original series with the rising edges overplotted as up arrows.

Example:

W1: gsin(10000, 1/1000, 0.3)

W2: levelduration(w1, 0.0, 1.0)

W3: W1;overp(w2);setplotstyle(1,2);setsym(8, 2)

 

Same as above except the level and duration parameters are explicit.

Example:

W1: gsin(10000, 1/1000, 0.3)

W2: (r, f) = levelduration(w1,0.5,1.0);r;overplot(f);setsym(8, 1);setsym(9,2)

W3: W1;overp(r);overp(f);setplotstyle(1,2);setsym(8,2);setplotstyle(1,3);setsym(9,3)

 

W1 contains the source series.

 

W2 returns two 3 point XY series where r contains the rising (beginning) edges and f contains the falling (ending) edges where W1 crosses 0.5 and remains above 0.5 for 1 second.

 

W3 displays the original series with the rising edges overplotted as up arrows and the falling edges are overplotted as down arrows.

Example:

W1: gsweep(10000, 1/10000, 1, 10.3)

W2: (r, f) = levelduration(w1,0.5,0.04);r;overplot(f);setsym(8, 1);setsym(9,2)

W3: W1;overp(r);overp(f);setplotstyle(1,2);setsym(8,2);setplotstyle(1,3);setsym(9,3)

 

leveldur1.png

 

W1 contains a swept sine wave from 1 Hz to 10.3 Hz.

 

W2 returns two 4 point XY series where r contains the rising (beginning) edges and f contains the falling (ending) edges where W1 crosses 0.5 and remains above 0.5 for 0.04 seconds.

 

W3 displays the original series with the rising edges overplotted as up arrows and the falling edges are overplotted as down arrows. The plot shows 4 intervals meet the condition of crossing 0.5 for at least 0.04 seconds.

 

Note the resulting rising edges are to the left of the actual crossing point and the falling edges are to the right of the crossing point.

Example:

W1: gsweep(10000, 1/10000, 1, 10.3)

W2: (r, f) = levelduration(w1,0.5,0.04,4);r;overplot(f);setsym(8, 1);setsym(9,2)

W3: W1;overp(r);overp(f);setplotstyle(1,2);setsym(8,2);setplotstyle(1,3);setsym(9,3)

 

Same as above, except the rising and crossing edges are linearly interpolated to the actual crossing location.

Example:

W1: gsweep(10000, 1/10000, 1.0, 10.3)

W2: (r, f) = levelduration(w1,0.5,0.04,4);r;overplot(f);setsym(8, 1);setsym(9,2)

W3: W1;overp(r);overp(f);setplotstyle(1,2);setsym(8,2);setplotstyle(1,3);setsym(9,3)

W4: integ(gnorm(1000, 1/1000))

W5: xy(xvals(r), xylookup(W4, xvals(r)));points;setsym(8)

W6: xy(xvals(f), xylookup(W4, xvals(f)));points;setsym(9)

w7: W4;overp(w5);overp(w6)

 

Same as above, except the rising and crossing edges are used to mark the same locations of an associated series in W4.

 

W7 shows the rising and falling edges overplotted on the series in W4, showing the four intervals of W1 that cross 0.5 for at least 0.04 seconds. Note the source series in W1 and the associated series in W4 have different sample rates.

Remarks:

LEVELDURATION returns an XY series where the input crosses level and remains above level for duration. The Y values of the returned XY series are set to level.

 

The edgeout parameter determines the precise location of the level crossing. By default, if the input series crosses level between samples, the rising edge is the sample to the left of the crossing and the falling edge is the sample to the right of the crossing. Set edgeout to 4 to linearly interpolate the crossing locations. See LEVELCROSS for more details.

 

The tol parameter is used to handle cases where the series reaches level exactly but does not cross it. The default value for tol is EPS("double").

See Also:

EPS

LEVELCROSS

XYLOOKUP