findpeaks in a spectrum
46 views (last 30 days)
Show older comments
Sören Gevaert
on 30 Apr 2020
Commented: Star Strider
on 1 May 2020
Hello
Currently i am using the command 'findpeaks' to find local maximums in a plot as follows.
fs = 30000;
Ts = 1/fs;
t=0:Ts:10-Ts;
t=t';
perm = 4*pi*10^-7;
%calculate spectrum with command Pspectrum expressed in db
xTable = timetable(seconds(t),stroom);
[pxx,f] = pspectrum(xTable, 'Reassign',true, 'leakage',0.85);
%find local maximum with findpeaks
[amplitudewaarde,frequentieamplitude] = findpeaks(pow2db(pxx),f);
K = [amplitudewaarde,frequentieamplitude];
figure;
subplot(2,1,1)
plot(f,pow2db(pxx));
xlabel('Frequency (Hz)')
ylabel('Power Spectrum (dB)')
subplot(2,1,2)
plot(frequentieamplitude,amplitudewaarde);
xlabel('Frequency (Hz)')
ylabel('pieken(db)')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288896/image.png)
The plot above is the spectrum and the plot below is the plot with find peaks. But this is not exactly what i want. My main goal is to only get the values coherent with the red arrows. In the figure above i placed a data tip from a value that i dont want to have. unfortunate i still obtain those values as you can see in this matrix:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288897/image.png)
All those values i dont want to retrieve. THe only values i want are the values corresponding with the peaks(red arrows). Does anyone have a sugestion on how to handle this problem?
Thanks in advance
0 Comments
Accepted Answer
Star Strider
on 30 Apr 2020
The actual findpeaks output plot is not shown, and we do not have your data, so it is not possible to determine what findpeaks is actually returning. The findpeaks function has a number of name-value pair arguments that can be quite useful in getting the resullt you want. In this instance, I would use 'MinPeakProminence', although it might be possible to use 'MinPeakHeight' if you first detrended the baseline with the detrend function. (This will not affect your data, however it willl make life easier for findpeaks.)
You can get prominence values from findpeaks by requesting them using the current syntax:
[amplitudewaarde,frequentieamplitude,width,prominence] = findpeaks(pow2db(pxx),f);
then use the returned ‘prominence’ values for the peaks you want as a guide for setting the 'MinPeakProminence' value.
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!