Measuring local "flatness" I have a function which looks like so:



I would like to know if there is a measure for a "weak type run length". 
How can I know that a function is approximately constant in some specific neighborhood?
How can I differentiate this function from random noise?
You can run the signal through a low pass filter to get rid of the high frequency content. After that, if you know the expected length of the flatness of the signal, you can perform matched filtering with a template of that length. If the cross-correlation result exceeds some threshold, consider the signal detected.