def calc_tcv(signal, threshold=2.0):
    """
    Calculate the count of threshold crossings for positive and negative threshold.

    :param signal: input signal
    :param threshold: threshold used for counting
    :return: number of times the threshold was crossed
    """
    tcv = 0
    prev = 0.0
    tm = -threshold
    for x in signal:
        if (x < threshold and prev > threshold) or (
            x > threshold and prev <= threshold
        ):
            prev = x
            tcv += 1
        elif (x < tm and prev > tm) or (x > tm and prev <= tm):
            prev = x
            tcv += 1
    return float(tcv)