# Find peaks not working on my data set

20 ビュー (過去 30 日間)
Ashlyn McCann 2021 年 3 月 9 日
コメント済み: Steve Eddins 2021 年 3 月 9 日
I am trying to find the first 5 peaks in the PSD plot of an acoustic signal. While I do not have any bugs in my code, it is not finding actual peaks and looks more like arbitrary locations. I will paste my code below:
M = movmean((PSD), 50);
[maxpks, maxloc]=findpeaks(PSD(1:2000),'MinPeakDistance',195,'MinPeakHeight',-50,'NPeaks',5);
figure(1)
plot(fp,PSD)
hold on
%O=2*f %%convert to octaves so the slope is in dB/octave
plot((maxloc), maxpks, 'r*')
hold off
sortpks=sort(maxpks);
[j,h]=size(sortpks);
J= [sortpks(j),sortpks(j-1),sortpks(j-2), sortpks(j-3), sortpks(j-4)]; %first five peak
ML = maxloc(j-4:j); %first five peak location
ML=(ML)'; %%convert to octaves so the slope is in dB/octave
figure(2)
plot(ML,J,'r*')
Fit = polyfit(ML,J,1); %linear regression
yfit = Fit(1)*ML+Fit(2); %equation of line
hold on
plot(ML,yfit,'g-')
slope=Fit(1)%spectral tilt The picture above is a zoomed in version of figure 1 and it is just not detecting the peaks I need. Thank you in advanced for any help!

サインインしてコメントする。

### 採用された回答

Steve Eddins 2021 年 3 月 9 日
I suspect the issue is with the x-coordinates that you are using to plot the peaks. You are plotting the peaks against the indices returned by findpeaks, but you are plotting PSD against x-coordinates in the variable fp. So, intead of this:
plot((maxloc), maxpks, 'r*')
Try this:
plot(fp(maxloc), maxpks, 'r*')
##### 2 件のコメント表示非表示 1 件の古いコメント
Steve Eddins 2021 年 3 月 9 日
Great! If this answer worked for you, can you go ahead and accept it?

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!