findpeaks in a spectrum

50 visualizaciones (últimos 30 días)
Sören Gevaert
Sören Gevaert el 30 de Abr. de 2020
Comentada: Star Strider el 1 de Mayo de 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)')
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:
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

Respuesta aceptada

Star Strider
Star Strider el 30 de Abr. de 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 comentarios
Sören Gevaert
Sören Gevaert el 1 de Mayo de 2020
Thank you star strider! the prominence is working very well! thanks for the help :)
Star Strider
Star Strider el 1 de Mayo de 2020
As always, my pleasure!

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