Removing peaks less than threshold

14 views (last 30 days)
Trevor Evans
Trevor Evans on 11 Apr 2024
Commented: Voss on 13 Apr 2024
Hi,
I have a time series which has fairly large cyclical peaks (~1sec) that I used the findpeaks function to identify. However, there are sometimes lesser spurious peaks which I am trying to eliminate. I've tried to set a threshold for minimum peak distance of 0.7sec using the diff function to get rid of the smaller peaks, but this has sometimes resulted in also removing the larger peaks that I would like to keep. I know I need to use the y-values from the peaks to keep the larger values but am unsure how to incorporate that into the algorithm. For example, given this data of peaks:
[LMaxValues2,LMaxInd2] = findpeaks(data.Y,'MinPeakProminence',0.1,'Annotate','extents'); %find data peaks
LMaxTimes2 = data.time(LMaxInd2); %turn peak indices into timestamps
badpts = diff(LMaxTimes2)<0.7; %threshold 0.7s to eliminate minor spurious peaks
LMaxTimes2(badpts)=[]; %Eliminate times of fake peaks from array
LMaxValues2(badpts)=[]; %Eliminate values of fake peaks from array
LMaxTimes2 = [292.498 293.517 294.543 295.117 295.556 296.548];
LMaxValues2 = [0.0097 -0.027 0.0412 -0.4127 0.0111 -0.011];
I want it to keep points 1,2,3,4,6, outputting:
LMaxTimes2 = [292.498 293.517 294.543 295.556 296.548]
LMaxValues2 = [0.0097 -0.027 0.0412 0.0111 -0.011];
But I'm getting:
LMaxTimes2 = [292.498 293.517 294.543 296.548]
Since the diff(LMaxTimes2) for points 3-4 and 4-5 both cross the <0.7 threshold.
Hope this was clear, thank you!
  2 Comments
Image Analyst
Image Analyst on 11 Apr 2024
Do you just want to find the shorter peaks on the left shoulder of the big peak and delete everything in the x and y arrays between the valleys on each side of the shoulder peak? Or did you want to change the values, like interpolate a smooth function between the valleys?
Trevor Evans
Trevor Evans on 13 Apr 2024
I only wanted to extract the x-values of the big peaks, but the idea of smoothing the data between peaks is interesting! I ended up doing a variation of what Voss suggested in his answer. Thanks anyway!

Sign in to comment.

Accepted Answer

Voss
Voss on 11 Apr 2024
Try using MinPeakHeight and/or MinPeakDistance in findpeaks, instead of MinPeakProminence. You'll likely be able to entirely avoid removing elements afterward based on diff.
  2 Comments
Trevor Evans
Trevor Evans on 13 Apr 2024
I tweaked the MinPeakDistance value and ended up with the desired results without using diff like you said. Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!