Detecting maximum and minimum of signal

140 views (last 30 days)
Hey guys,
I'd like to write some code which finds the mean stress and stress amplitude for each block of a signal whose amplitude changes from one constant value to another (pictured below).
In order to do this, I need the maximum and minimum values for each block of the signal. The only problem is that my program should be able to read any signal with multiple blocks of constant amplitude so the method needs to be general and not just for the example below.
Any help would be greatly appreciated :)

Accepted Answer

Wayne King
Wayne King on 9 Jan 2013
Edited: Wayne King on 9 Jan 2013
One thing you can do is to use the Hilbert transform to form the analytic signal corresponding to your signal, then use the modulus (absolute value) of the analytic signal to detect changes in the mean.
For a purely sinuisodal signal obviously the modulus of the analytic signal is a constant. Given numerical precision concerns and the fact that the measurement will contain random noise, the modulus in a given block will not be a constant, but from your example above, it will be close.
For example:
n = 0:399;
x = zeros(400,1);
x(1:159) = cos(pi/4*n(1:159));
x(200:end) = 1/5*cos(pi/2*n(200:end));
Now, use hilbert() to obtain the analytic signal
y = hilbert(x);
Notice how the modulus of the analytic signal captures changes in the mean.
If you do something like:
changepoints = abs(diff(abs(y)));
You can see where the mean levels are changing. You will have to ignore the very beginning and end of the interval.
Of course there are a number of change point detection algorithms out there better than the technique I've given (detecting a change based on the first difference of the absolute value of the analytic signal), so feel free to use another technique, but hopefully that gets you started.

More Answers (2)

Image Analyst
Image Analyst on 9 Jan 2013
Edited: Image Analyst on 9 Jan 2013
How about:
minValue = min(theBlock(:));
maxValue = max(theBlock(:));
You only asked about finding the min and max value. You didn't ask about locating the blocks themselves, so presumably you already have a way of doing that. If not, I posted a method for that about a month or two ago involving conv() and thresholding I think.
You said your " program should be able to read any signal". I'm not sure what this means, but perhaps you need to get the Data Acquisition Toolbox if you need to read from an instrument, or perhaps fread(), dlmread(), importdata() or something like that if you need to read it from a file. If you have some other definition of read, let's hear it.

Community Treasure Hunt

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

Start Hunting!