x: input data, specified as a numeric vector or matrix. In case of a vector it represents a single signal; in case of a matrix each column is a signal.
lvl: threshold levels against which x is compared, specified as a vector. If this is a scalar, the thresholds are symmetric around 0, i.e. c(-lvl, lvl).
st: trigger state, specified as a vector of length ncol(x. The trigger state is returned in the output list and may be passed again to a subsequent call to schtrig. Default: NULL.
Returns
a list containing the following variables:
v: vector or matrix of 0's and 1's, according to whether x is above or below lvl, or the value of x if indeterminate
rng: ranges in which the output is high, so the indexes rng[1,i]:rng[2,i] point to the i-th segment of 1s in v. See clustersegment for a detailed explanation.
st: trigger state, returned as a vector with a length of the number of columns in x.
Details
The trigger works compares each column in x to the levels in lvl, when the value is higher than max(lvl), the output v is high (i.e. 1); when the value is below min(lvl) the output is low (i.e. 0); and when the value is between the two levels the output retains its value.
Examples
t <- seq(0,1, length.out =100)x <- sin(2* pi *2* t)+ sin(2* pi *5* t)%*% matrix(c(0.8,0.3),1,2)lvl <- c(0.8,0.25)trig <- schtrig (x, lvl)op <- par(mfrow = c(2,1))plot(t, x[,1], type ="l", xlab ="", ylab ="")abline(h = lvl, col ="blue")lines(t, trig$v[,1], col ="red", lwd =2)plot(t, x[,2], type ="l", xlab ="", ylab ="")abline(h = lvl, col ="blue")lines(t, trig$v[,2], col ="red", lwd =2)par(op)