How do I find Peaks in Plotted data?
Show older comments
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>>
Answers (1)
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
Serena Solanki
on 7 Nov 2017
Star Strider
on 7 Nov 2017
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.
Serena Solanki
on 7 Nov 2017
Star Strider
on 7 Nov 2017
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!