Find peaks not working on my data set

16 visualizaciones (últimos 30 días)
Ashlyn McCann
Ashlyn McCann el 9 de Mzo. de 2021
Comentada: Steve Eddins el 9 de Mzo. de 2021
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!

Respuesta aceptada

Steve Eddins
Steve Eddins el 9 de Mzo. de 2021
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 comentarios
Ashlyn McCann
Ashlyn McCann el 9 de Mzo. de 2021
Yes! thats what it was! thank you
Steve Eddins
Steve Eddins el 9 de Mzo. de 2021
Great! If this answer worked for you, can you go ahead and accept it?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by