How to find number of times graph goes back to zero

Hello everyone, I am new to MATLAB and I am currently plotting a normalised gyroscope data as in the picture below, and I am trying to count the number of the graph trying to go back to zero (on the word, number of the graph descending after reaching each peak)
For example, if I calculate it manually fromthe graph, it's around 9 times it tries to go back to zero. But I am trying to do analysis on big data so I really ned way of finding it by MATLAB.
Help me, thanks

 Accepted Answer

To find the troughs, invert the ‘y’ values and use findpeaks:
Example:
x = linspace(0,250,250); % Create Data
y = 0.25*sin(0.25*pi*x) .* exp(-(x-125).^2./1000) + exp(-(x-125).^2./1000);
[pks,plocs] = findpeaks(y); % Find peaks
[trs,tlocs] = findpeaks(0.1+max(y) - y); % Find troughs
figure(1)
plot(x, y)
hold on
plot(x(plocs), y(plocs), '^r', 'MarkerFaceColor','r') % Plot peaks
plot(x(tlocs), y(tlocs), 'vg', 'MarkerFaceColor','g') % Plot troughs
hold off
grid
produces:

6 Comments

thanks for your suggestion. but the when it find the through, it still detect the line at the begining of the graph, and I don't need that. What is your fast suggestion for this?
The findpeaks function has ‘name’-‘value’ pair options. Here, 'threshold' is your friend.
With your data (assuming your y variable is ‘y’:
trhd = 1; % Set threshold
[pks,plocs] = findpeaks(y, 'threshold', trhd); % Find peaks
[trs,tlocs] = findpeaks(0.1+max(y) - y, 'threshold', trhd); % Find troughs
I don’t have your data, so just looking at your plot, I would start with a threshold (my ‘trhd’ variable) of 1 and increase or decrease it until you get the result you want.
thanks. anyway, your attached picture looks so high in resolution and mine looks pixelated. how did you do that?
My pleasure!
Did the thresholding work as you want it to? If not, findpeaks has other options we can consider. If you want to post your data here I can experiment with findpeaks on it.
I always use the ‘.png’ format (portable network graphics). You used .jpg, which at least used to use a discrete cosine transform that produces ‘ringing’ at abrupt transitions. (If Image Analyst happens upon this, I will welcome his explanation and clarification.)
thank you, that solution is very helpful. yes, i do have another problem with it but i posted on anther question http://www.mathworks.co.uk/matlabcentral/answers/134657-how-to-detect-point-before-it-went-on-plateau
My pleasure!
I saw your other post and suggested a solution.

Sign in to comment.

More Answers (0)

Asked:

on 15 Jun 2014

Commented:

on 16 Jun 2014

Community Treasure Hunt

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

Start Hunting!