## How do I find Peaks in Plotted data?

### Serena Solanki (view profile)

on 6 Nov 2017
Latest activity Commented on by Star Strider

### Star Strider (view profile)

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'
B=ColumnB
A=ColumnA
%%Logarithmic Decrement Method
Time=ColumnA
Displacement=ColumnB
plot(Time,Displacement,'g'),grid on
findpeaks(Time,Displacement)

### Star Strider (view profile)

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.

Show 1 older comment
Star Strider

### Star Strider (view profile)

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

### Serena Solanki (view profile)

on 7 Nov 2017
This has worked perfectly! Thank you very much !
Star Strider

### Star Strider (view profile)

on 7 Nov 2017
As always, my pleasure!