Filtering peaks to find number of pulses

Greetings,
As shown in the image below, I am trying to filter these "false" peaks(get rid of the close ones, which have the same "height" as the previous one) and thus find the number of pulses. Looking over the Help section and this forum I couldn't find any questions exactly like this one.
I've used this command to plot this graphic: findpeaks(data,'MinPeakProminence',3);
Thanks in advance.

Risposte (3)

It looks like you are using FINDPEAKS to find the flat parts of pulses. This might not be the right approach, but in a pinch, you can simply add a very small number to the input to prevent equal-height peaks that all appear within the same range.
Something like:
findpeaks(data(:) + 0.001*(1:numel(data))','MinPeakProminence',3)
If you want the first peak of each range (rather than the last) you can do something like this:
findpeaks(data(:) - 0.001*(1:numel(data))','MinPeakProminence',3)
Since you have the Signal Processing Toolbox, have a look at pulsewidth() or midcross(). That might be more in line of what you wish to do.
Image Analyst
Image Analyst il 19 Mag 2015
Modificato: Image Analyst il 19 Mag 2015
Which of the two peaks do you want? Or do you want the average location? Can't you adjust the findpeaks() options to get rid of those? If not, find out when the peak locations are within some specified distance of each other and take either the first, second, or average index location instead of both of them. Attach your data if you want more help.

5 Commenti

I want to it to take one peak when it is taking two.
findpeaks(data,'MinPeakProminence',3);
I'm just using that line of code for now, as I had put back then. Again, I didn't find any solution in MATLAB's Help function or in the search mechanism here, so I have no idea on how to adjust this function.
Problem is, they have the same Y value so the 'MinPeakProminence' do not detect the second ones.
If all you're interested in is the number of pulses, you should threshold the data which i think is a parameter within findpeaks and/or set the minpeak distance.
Joseph made a good point. And if you have the Image Processing Toolbox, and it all your data are in the same -8 to +8 range, you can simply do:
[~, numberOfPeaks] = bwlabel(data > 2);
You don't even need findpeaks() at all!
Joseph Cheng
Joseph Cheng il 19 Mag 2015
Modificato: Joseph Cheng il 19 Mag 2015
Additionally, i would recommend using a threshold and then using something like diff to discover the rising and falling edge positions to count the number of pulses. This would also help determine which points are noise spikes like the 1 point wide pulses. are they real pulses, part of either neighboring pulses but a drop in signal made it look like a pulse, or not even a pulse but a noise spike while the signal was low?
2 was the threshold. If some of the pulses might be isolated noise spikes, then you could use regionprops() to detect and eliminate any pulses that did not span the minimum required number of indexes, like for example the thin pulse where x is about 90.

Accedi per commentare.

Armindo
Armindo il 21 Feb 2019
Modificato: Armindo il 21 Feb 2019
rising and falling edge can be found like this:
%Get the rising edge, is given by default matlab function findpeaks like this:
% rising edge
[pks,RisingEdgeIndx] = findpeaks(data)
%falling edge
% first Invert the signal like this
dataRev = data(end:-1:1);
[pks,locs] = findpeaks(dataRev)
% get the right indexes
FallingEdgeIndx = length(data) - locs +1;
FallingEdgeIndx = FallingEdgeIndx(end:-1:1);

Modificato:

il 21 Feb 2019

Community Treasure Hunt

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

Start Hunting!

Translated by