Find peaks not working on my data set

조회 수: 14 (최근 30일)
Ashlyn McCann
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
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
Ashlyn McCann
Ashlyn McCann 2021년 3월 9일
Yes! thats what it was! thank you
Steve Eddins
Steve Eddins 2021년 3월 9일
Great! If this answer worked for you, can you go ahead and accept it?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by