Finding local minimums/maximums for a set of data

Hi, I have a set of data which oscillates between minimums and maximum values. The min and max values change slightly over time. I want to see the trend of changing of min and max values over time. In order to do that, it seems that I need to extract the local min and local maximums.
Is there any function to extract the local minimums and maximums of the following graph?
Thanks.

4 comentarios

Martin Elenkov
Martin Elenkov el 10 de Mzo. de 2016
Is this Electrical Impedance Tomography(EIT) data? I have the same problem, where I have to determine the time interval where an dynamic Computed Tomography scan is made during the EIT. I thought I can determine the peak distances and then meet some kind of a decision to determine this time interval.
Here is my signal
Start your own question and explain more about what's in the red circles that you want. Otherwise just threshold and call diff() and look for +1 values.
binarySignal = signal > 2.56;
leadingEdges = find(diff(binarySignal) >= 1);
You can get the distance between leading edges by doing diff(leadingEdges).
Steev Mathew
Steev Mathew el 4 de Mzo. de 2021
Thanks! This helped me a lot. I was looking for a way to filter out noise from my data.
Anupama V
Anupama V el 6 de Nov. de 2022
How to find the valley of a ppg signal?(secondary peak of a signal)

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 22 de Jul. de 2012
Editada: Star Strider el 22 de Jul. de 2012
Another option is ‘findpeaks’ in the Signal Processing Toolbox. It will give you the maximum (and indirectly the minimum) values and their index locations. If ‘Data’ is the vector that produced the plot, to find the maxima and minima:
[Maxima,MaxIdx] = findpeaks(Data);
DataInv = 1.01*max(Data) - Data;
[Minima,MinIdx] = findpeaks(DataInv);
The true minima will then be:
Minima = Data(MinIdx);
The index values also allow you to determine the times the maxima and minima occurred.

9 comentarios

For the same signal how to get the position values of those peaks we got? please help me with finding the position of the code as well as in plotting the peaks we got.
Image Analyst
Image Analyst el 8 de Mzo. de 2017
"MaxIdx" is the index number of the peaks ("the position values of those peaks". I'd have called it "indexesOfPeaks" to be more explicit.
I don't know what you mean by "position of the code". How does source code have a position?
I'm having same values in both Maxima and Minima matrices ? can you explain the code once?
Instead of DataInv = 1.01*max(Data) - Data, would this be sufficient:
[Minima, MinIdx] = findpeaks(-Data)
I believe you'd also have to do
Minima = -Minima;
so we get the original sign of the valleys.
nuclear physics
nuclear physics el 28 de Oct. de 2017
Editada: Image Analyst el 28 de Oct. de 2017
Why does not work findpeak for me? i found this code and saved in my current folder as m.file. i got this error:Too many output arguments . i run this:
[~, maxes] = findpeaks(proffj);
Image Analyst
Image Analyst el 28 de Oct. de 2017
That code works fine. I ran it with no errors if I gave it a double 1-D array for proffj. Attach ALL your code and data so we can run it and discover any problem..
Hi, I know that this is an old question, but why is the signal inverted using : DataInv = 1.01*max(Data) - Data; Cheers,
Star Strider
Star Strider el 27 de Feb. de 2018
For some reason, it was important that the inverted waveform be greater than zero. (That was years ago, so I don’t remember the details.)
That’s likely not necessary for every signal. If you want the minima, just negate the original signal and use the indices findpeaks returns in the second output to get the values of the original signal.
I you have R2017b, the islocalmin function is also an option to get the minima without inverting the signal.

Iniciar sesión para comentar.

Más respuestas (5)

Steven Lord
Steven Lord el 4 de Mzo. de 2021

2 votos

For more recent releases take a look at the islocalmin, islocalmax, and (perhaps) detrend functions.
Si14
Si14 el 26 de Jul. de 2012
Thank you guys for your responses. I am using the following and it works nice:
[Maxima,MaxIdx] = findpeaks(Data);
DataInv = 1.01*max(Data) - Data;
[Minima,MinIdx] = findpeaks(DataInv);
Minima = Data(MinIdx);

2 comentarios

Star Strider
Star Strider el 26 de Jul. de 2012
Thank you for accepting my answer!
Umesh Gautam
Umesh Gautam el 11 de Mayo de 2023
It is working great.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 22 de Jul. de 2012
Editada: Image Analyst el 22 de Jul. de 2012

0 votos

If you have the Image Processing Toolbox, you can use imregionmax() and imregionalmin(). Do you have that toolbox? If you do that would be the simplest because it's just simply one line of code to find either the maxs or the mins.
You can also do it by seeing where the morphological max or min (performed by imdilate() and imerode() respectively) equals the original array. But again, that requires the Image Processing Toolbox.
Randy82
Randy82 el 13 de Ag. de 2014

0 votos

I have one question: Why do i have to multiply max(Data) with a factor 1.01?
Prithisha K
Prithisha K el 8 de Sept. de 2021

0 votos

Set the prominence window value to 25. Then increase the min.prominence value untill there are exactly 9 minima found.

Preguntada:

el 21 de Jul. de 2012

Comentada:

el 11 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by