# Detect when signal starts oscillating

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). 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. 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. How can non-stereotyped oscillations be detected in a signal like this? Thanks!

• What characteristics of the oscillation are known with confidence? – Cristobol Polychronopolis Mar 9 '20 at 19:26
• 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 – Engineer Mar 9 '20 at 19:42

## 1 Answer

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}$$.