I only changed slightly the function, so that it is possible to identify the directionnality of the change in the output (from under to above the threshold and from above to under the threshold)