Borrar filtros
Borrar filtros

Making two peaks into one

15 visualizaciones (últimos 30 días)
Joel el 6 de Abr. de 2023
Comentada: Mathieu NOE el 11 de Abr. de 2023
How can I make two peaking values into the highest.
I have these vectors (one double and one duration) showing the duration of the peaks (when the curve crosses the red threshold).
However some peaks have two peak values, making the double vector one element bigger than the duration vector. I want the vectors to be of the same length so only the highest peaking value of each peak show. So in this case row 9 of the max_val should be removed.
EFFEKT= 8760x1 double %One value for every hour of the year
Abonnemang=24200; %threshold value
t=8760x1 datetime %Every hour of the year
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang); % find the peak and its x axis location
[t0_pos1,s0_pos1,t0_neg1,s0_neg1]= crossing_V7(EFFEKT,t,Abonnemang,'linear'); % positive (pos) and negative (neg) slope crossing points
peak_width = t0_neg1- t0_pos1;
peak_width =peak_width

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 6 de Abr. de 2023
hello again
have a look at the help of findpeaks;
use this argument of findpeaks to keep only the tallest peak :
MinPeakDistance Minimum peak separation
0 (default) | positive real scalar
Minimum peak separation, specified as a positive real scalar. When you specify a value for 'MinPeakDistance', the algorithm chooses the tallest peak in the signal and ignores all peaks within 'MinPeakDistance' of it. The function then repeats the procedure for the tallest remaining peak and iterates until it runs out of peaks to consider.
  • If you specify a location vector, x, then 'MinPeakDistance' must be expressed in terms of x. If x is a datetime array, then specify 'MinPeakDistance' as a duration scalar or as a numeric scalar expressed in days.
  • If you specify a sample rate, Fs, then 'MinPeakDistance' must be expressed in units of time.
  • If you specify neither x nor Fs, then 'MinPeakDistance' must be expressed in units of samples.
Use this argument to have findpeaks ignore small peaks that occur in the neighborhood of a larger peak.
  3 comentarios
Joel el 10 de Abr. de 2023
Hello again
Thank you so much. I tried this and got max_val to a 9x1 double which matches to the peak_width. However
I had to try differnt values (30), what does it mean exactly? I got larger vectors with a small values and fewer for a bigger value:
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang); % find the peak and its x axis location
[max_val,locs] = findpeaks(EFFEKT,t,'MinPeakDistance',30);
Mathieu NOE
Mathieu NOE el 11 de Abr. de 2023
look at the doc
you can combine multiple options (arguments) in one single call to findpeaks
if you use 'MinPeakDistance' with value = 30, that means you want no peaks that are closer than 30 samples (on the x axis) , so if you have 2 (and more) close by peaks, you can use that argument to keep only one (with the highest peak value)
NB you should combine the arguments :
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang,'MinPeakDistance',30);

Iniciar sesión para comentar.

Más respuestas (0)




Community Treasure Hunt

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

Start Hunting!

Translated by