Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect steps in a Piecewise constant signal

I have a piecewise constant signal shown below. I want to detect the location of step transition (Marked in red).

My current approach:

  • Smooth signal using moving average filter (http://www.mathworks.com/help/signal/examples/signal-smoothing.html)
  • Perform Discrete Wavelet transform to get discontinuities
  • Locate the discontinuities to get the location of step transition

I am currently implementing the last step of detecting the discontinuities. However, I cannot get the precise location and end with many false detection.

My question:

  1. Is this the correct approach?
  2. If yes, can someone shed some info/ algorithm to use for the last step?
  3. Please suggest an alternate/ better approach.

Thanks

Original, Smoothed, DWT-detailed Coeff at level 1 plots

like image 554
VP. Avatar asked Oct 31 '13 19:10

VP.


2 Answers

Convolve your signal with a 1st derivative of a Gaussian to find the step positions, similar to a Canny edge detection in 1-D. You can do that in a multi-scale approach, starting from a "large" sigma (say ~10 pixels) detect local maxima, then to a smaller sigma (~2 pixels) to converge on the right pixels where the steps are.

You can see an implementation of this approach here.

like image 127
bla Avatar answered Sep 21 '22 14:09

bla


If your function is really piecewise constant, why not use just abs of diff compared to a threshold?

th = 0.1;
x_steps = x(abs(diff(y)) > th)

where x a vector with your x-axis values, y is your y-axis data, and th is a threshold.

Example:

>> x = [2 3 4 5 6 7 8 9];
>> y = [1 1 1 2 2 2 3 3];
>> th = 0.1;
>> x_steps = x(abs(diff(y)) > th)  

x_steps =

     4     7
like image 27
Luis Mendo Avatar answered Sep 19 '22 14:09

Luis Mendo