How do I find Peaks in Plotted data?

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>>

Risposte (1)

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 Commenti

Thank you for your suggestion. I have tried running the code you have given, it worked however, it does not identify the actual peaks or produce any other information apart from the graph.
Have I missed something?
%%Logarithmic Decrement Method
Time=ColumnA
Displacement=ColumnB
plot(Time,Displacement,'g'),grid on
[PKAmp,PKTime]=findpeaks(Displacement,Time);
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!

Accedi per commentare.

Richiesto:

il 6 Nov 2017

Commentato:

il 7 Nov 2017

Community Treasure Hunt

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

Start Hunting!

Translated by