Find peaks not working on my data set
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashlyn McCann
le 9 Mar 2021
Commenté : Steve Eddins
le 9 Mar 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!
0 commentaires
Réponse acceptée
Steve Eddins
le 9 Mar 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spectral Estimation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!