How to count the specific sampling pairs given several samples of a function?

17 Views Asked by At

enter image description here

As illustrated in the figure, we have a function (the solid line) and sample it with a user-defined sampling rate (the blue circles). In addition, we uniformly divide the y-axis into several sub-areas (i.e., $A$ to $F$ in the figure). We define a sample and its adjacent sample as the crossing-sample pair if they belong to the different sub-areas. Examples are illustrated by red squares.

My concern is how to account the crossing-sample pairs given a function and a specific sub-area division.