I have a signal which consists of oscillations riding on square waves as shown in the image below. I wish to detect the time at which oscillatory events occur (as shown by the red star).

enter image description here

Each square wave is a different height and the oscillatory sequences riding on each sqaure wave are not identical. Here I have zoomed in on a small chunk of one oscillation.

enter image description here

A second order low-pass butterworth filter with cutoff at 500 Hz can be used to clean the data if this is a useful preprocessing step.

enter image description here

How can non-stereotyped oscillations be detected in a signal like this? Thanks!

  • $\begingroup$ What characteristics of the oscillation are known with confidence? $\endgroup$ Commented Mar 9, 2020 at 19:26
  • 1
    $\begingroup$ If the signal you want to keep and the oscillations are in different frequency bands, then you can do filtering just as you did. You'd choose the passband to be the band where the signal you want to keep is and the stopband is all other frequencies. It might turn out to be something like a passband filter $\endgroup$
    – Engineer
    Commented Mar 9, 2020 at 19:42

1 Answer 1


As far as I can tell from the graph, the variance of the signal goes up substantially under "oscillation" conditions. So, monitor the variance over a rolling window. High variance indicates oscillation. To choose the window width, consider:

  • if the window is too short, the computed variance will be too noisy
  • if the window is too long, the monitor will be slow to respond

Also note that, given the information you've provided, there is no way to tell the difference between the step function signal itself and the beginning of an oscillation condition. You should therefore impose some auxiliary condition on the signal to avoid false positive detection. For a square wave signal, I'd suggest detecting extremely large time derivative. If the derivative exceeds some critical value, you probably have a square wave step, not an oscillation. So the criterion is:

oscillation if variance exceeds $V_{min}$ and max derivative is smaller than $D_{max}$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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