MATLAB Answers

Peak value on plot graph

9 views (last 30 days)
Reff
Reff on 15 Jan 2020
Commented: Star Strider on 16 Jan 2020
y=a1(:,1);
chan1= y-mean(a1);
fs=128;
d=1/fs;
t=[0:length(chan1)-1]*d;
fs=fft(chan1,128);
pp=fs.*conj(fs)/128;
ff=(2:9)/128/d;
figure(4);
plot(ff,pp(2:9));
title('Power Spectrum');
xlabel('Frequency(Hz)');
ylabel('Power Spectrum Density(µv)');
grid on;
Peak.jpg
How to find peak value on y-axis without using Data Cursor tools. Thanks in advance.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 15 Jan 2020
If you have R2017b or later, you can use the islocalmax function.
If you have the Signal Processing Toolbox, you can use the findpeaks function.

  4 Comments

Show 1 older comment
Star Strider
Star Strider on 15 Jan 2020
If you are using:
[pks,locs] = findpeaks(pp(2:9))
you will need to add 1 to the ‘locs’ that findpeaks returns to get the actual indices.
Example —
x = 1:9;
pp = [50 100 1800 300 2500 1500 3000 3500 5800];
[pks,locs] = findpeaks(pp(2:9));
figure
plot(x, pp)
hold on
plot((locs+1), pks, 'r*')
hold off
Note that my code uses ‘(locs+1)’ in the plot call to refer to them correctly.
Reff
Reff on 16 Jan 2020
Hi Strider,
It works well. Really aprreciate it. Thanks.
Star Strider
Star Strider on 16 Jan 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)

Sign in to answer this question.