MATLAB Answers

0

How do I find Peaks in Plotted data?

Asked by Serena Solanki on 6 Nov 2017
Latest activity Commented on by Star Strider
on 7 Nov 2017
I have plotted some data for a simply damped object which has been displaced and is allowed to oscillate freely. The data plotted shows a sinusoidal behaviour.
I would like to find the peaks and have tried all of the recommended codes on Mathworks.
I have used [pks,locs]=findpeaks[Time, Displacement] I have also tried this in various different ways but have had no joy.
Hope you can help !
filename='Test_Results_19.xls'
ColumnA= xlsread(filename,'A2:A2088')
ColumnB= xlsread(filename,'B2:B2088')
B=ColumnB
A=ColumnA
%%Logarithmic Decrement Method
Time=ColumnA
Displacement=ColumnB
plot(Time,Displacement,'g'),grid on
findpeaks(Time,Displacement)
<</matlabcentral/answers/uploaded_files/93569/peaks.JPG>>

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 6 Nov 2017

Using findpeaks is the correct approach. You need to reverse the arguments to get the result you want.
Try this:
[PkAmp, PkTime] = findpeaks(Displacement,Time);
The peak amplitudes are in the ‘PkAmp’ vector, and the corresponding times in the ‘PkTime’ vector.

  4 Comments

Show 1 older comment
My pleasure.
The order of the statements are important.
Try this:
Time=ColumnA
Displacement=ColumnB
[PKAmp,PKTime]=findpeaks(Displacement,Time);
figure(1)
plot(Time,Displacement,'g')
hold on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
hold off
grid on
That should plot red upward-pointing triangles at every peak.
NOTE Since I don’t have your data, this is UNTESTED CODE. It should work.
This has worked perfectly! Thank you very much !
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.