If I have a rectangular function with irregular positive parts, is there a clever way of finding the center of each positive "plateau"?

The application is, that I threshold a continuous function and want to find the center locations of each segment that is greater than the threshold.

  • $\begingroup$ can you show us a plot/drawing of your function? I'm not 100% sure I understand what you're referring to. $\endgroup$ – Marcus Müller Nov 18 '16 at 16:38
  • 1
    $\begingroup$ i think there are some folks coming from disciplines other than electrical engineering that define a "rectangular function" as what we might call a "piecewise-constant function". otherwise the question makes no sense to me since there is only one "plateau" (not plural) of a rectangular function. $\endgroup$ – robert bristow-johnson Nov 18 '16 at 18:22
  • $\begingroup$ yep, and that's why I'd love to have a sketch or something to be on the same page as P.R. Otherwise, I'll have to vote for this as unclear, to be honest, because it's unclear to me. $\endgroup$ – Marcus Müller Nov 18 '16 at 21:40

Assume $x(t)$ is your original continuous function. The rectangular function $\pi(t)$ is generated by thresholding, something similar to


where $\gamma$ is the threshold. Consider one of the rectangular segments of $\pi(t)$ which is between $t=t_a$ and $t=t_b$, where there is an upward edge at $t_a$ and a downward edge at $t_b$. The center point is at $$t_m=t_a+\frac{1}{2}(t_b-t_a)$$ So the problem reduces to finding the upward and downward edges of each rectangular segment. This can be done by looking at the first derivative (or if the functions are discrete, the first difference) of $\pi(t)$. The derivative has positive and negative impulses that correspond to upward and downward edges. In vector notation:


$$\mathbf{t}_b=\{t:\pi'(t)<0\}$$ $$\mathbf{t}_m=\mathbf{t}_a+\frac{1}{2}(\mathbf{t}_b-\mathbf{t}_a)$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.