is there a way to only pull out flat peaks of a certain length using the findpeaks function?

3 views (last 30 days)
I have a color sensor that is giving data and I am trying to eliminate peaks that are not flat plateaus of a certain length, for example peaks of 3 seconds in length. Is there anyway to pull these specific peaks.

Answers (2)

Greg Dionne
Greg Dionne on 27 Feb 2017
When you say "flat" do you mean ruler flat? (i.e. all the same identical value?) If so, you can try something like this:
n = 2000;
x = sin(2*pi*10*(1:n)/n) + 0.5*sin(2*pi*5*(1:2000)/n) - linspace(0,3,2000);
x( x > 0) = 0;
plot(x);
[~,ifwd] = findpeaks(x);
[~,irev] = findpeaks(x(n:-1:1));
irev = n + 1 - irev(end:-1:1);
subplot(2,1,1);
plot(1:n,x,'-', ...
ifwd,x(ifwd),'>', ...
irev,x(irev),'<');
n = 2000;
legend('signal','leftside','rightside');
% keep references to corners less than three samples away
iok = find(abs(irev - ifwd) < 3);
ifwdok = ifwd(iok);
irevok = irev(iok);
subplot(2,1,2)
plot(1:n,x,'-', ...
ifwdok,x(ifwdok),'>', ...
irevok,x(irevok),'<');

Image Analyst
Image Analyst on 28 Feb 2017
Tell us more about the color sensor data. Does it produce a color image, or a 1-D signal? If 1-D, how many color signals are there?
To find flat parts, you can use imregionalmax() if you have the Image Processing Toolbox. Then you can get the length or area of the peaks or flat spots using regionprops(). You can then throw out ones that are more than one element big.

Tags

Community Treasure Hunt

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

Start Hunting!