How to find the maximal and minimal derivatives of noisy signals?

6 views (last 30 days)

Hello!

I'm currently using MATLAB for simple signal processing. I need to find the maximal and minimal derivatives (or slopes) of noisy signals. Actually I need the value of the derivative and the index at where it occurs so that I can draw a line representing the slope at that index. The picture below illustrates what I'm trying to do. The problem is that the signals are pretty noisy which will result in a very large derivative that doesn't represent the actual behavior of the signal. With some luck I managed to find the correct derivatives by constructing an averaged version of the original signal and calculating the average derivative over 10 samples at every index of the averaged signal. I'm sure there is a better way to accomplish this. Any help would be greatly appreciated.

Accepted Answer

Jan
Jan on 23 Feb 2011
At first you have to decide which parts of the signal are noise. A physically motivated choice should be preferred. With this information you can create a low-pass filter such that the high-frequency signal is smoothed. With FILTFILT this filter can be applied without phaseshifting. Finnaly GRADIENT creates the derivative and MIN and MAX finds the extrema and the corresponding index.
x = rand(10000, 1);
[B, A] = butter(3, 0.2, 'low')
xFiltered = filtfilt(B, A, x);
xGradient = gradient(xFiltered);
[maxValue, maxIndex] = max(xGradient);
[minValue, minIndex] = min(xGradient);
  1 Comment
heikkus
heikkus on 1 Mar 2011
Thank you for a quick reply! I'm now using butter() for creating and filtfilt() for applying the filter. The only fallback is that I have to create a different filter for every signal as the spectrum varies among these signals, but I guess this is as good as it gets.

Sign in to comment.

More Answers (2)

Vieniava
Vieniava on 23 Feb 2011

Differentiator filter should satisfy your needs.

You can use it in your mfile - Differentiator filter specification object .

You could also interactively design a filter using fdatool ( doc here) - response type should be choosed as Differentiator .


heikkus
heikkus on 23 Feb 2011
Thank you for a quick reply!
There seems to be a phase shift when using filters. I designed a differentiator filter and applied it to the original signal. I can now find the maximal derivative and index by using max() on the filtered signal but how would I find the corresponding actual derivative value and index of the original signal?
  2 Comments
Jan
Jan on 23 Feb 2011
Simply use the 2nd output of MAX, which is the wanted index.
Vieniava
Vieniava on 23 Feb 2011
corresponding values could be found using order of a filter. Use odd order filter - r. Than the "response delay" could be expressed as (r+1)/2 samples (see step response of designed filter on fdatool - this clarifies a lot )

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!