islocalmax('flat selection') selecting 0 value points

조회 수: 1 (최근 30일)
Simeon
Simeon 2024년 7월 25일
편집: Star Strider 2024년 7월 25일
I am trying to select these 'flat' peaks from a set of data and as I need the range of index values I am using islocalmax(data,'FlatSelection','all') and for most of my data it does a good job as shown in the picture above but others end up looking like this.
Was wondering if there is a way to fix this? I have tried altering things like minprominence and such.

답변 (1개)

Star Strider
Star Strider 2024년 7월 25일
In the lower plot image, if you are referring to the collection of orange asterisks before the start of the variable section (for want of a better way to describe it), the ‘spurious’ data could represent noise. In addition to 'MinProminence', setting 'ProminenceWindow' could be an option. Another option would be various approaches to filtering to elinminate the high-frequency noise, if that is the problem. (Start that approach by calculating the one-sided Fourier transform to see if there is band-limited high-frequency noise that could be filtered. Then design a frequency-selective lowpass filter using that information.)
It would help to have the data to experiment with. Without it, I can only speculate as to what the problem is, assuming that I even understand your question correctly.
  댓글 수: 2
Simeon
Simeon 2024년 7월 25일
Ok thanks
Star Strider
Star Strider 2024년 7월 25일
편집: Star Strider 2024년 7월 25일
My pleasure!
EDIT — (25 Jul 2024 at 17:28)
Thinking about it further, filtering may not produce the desired results, because it could affect the areas you want to detect. The solution to that problem could be to use thresholding, and only apply islocalmax to the areas above and below a specific threshold. This approach calculates the threshold using a logical vector, and then logically excludes it from the islocalmax result.
The code —
x = linspace(0, 50, 250);
y = [x(x<=10)*0 sign(sin(x(x>10 & x<40))*2*pi*10) x(x>=40)*0] + randn(size(x))*0.005;
figure
plot(x, y)
title('Original Data')
Lv1 = islocalmax(y, 'FlatSelection','all');
figure
plot(x, y)
hold on
plot(x(Lv1), y(Lv1),'.r')
hold off
title('Original Data With identified Regions')
Lvt = (y<0.05) & (y>-0.05); % Set Threshold & Return Appropriate Logical Vector
nnz(Lvt) % Check Threshold
ans = 100
Lv1= islocalmax(y, 'FlatSelection','all');
Lvlm = Lv1 & ~Lvt; % Logically Combine Vectors To Get Result Logical Vector
figure
plot(x, y, 'DisplayName','Original Data')
hold on
plot(x(Lvlm), y(Lvlm),'.r', 'DisplayName','Desired Result')
plot(x(Lvt), y(Lvt), '.g', 'DisplayName','Excluded Region')
hold off
legend('Location','N')
ylim([min(ylim) max(ylim)*1.25])
title('Original Data With Selectied Regions Showing Excuded Region')
Lvt = (y<0.05) & (y>-0.05); % Set Threshold & Return Appropriate Logical Vector
nnz(Lvt) % Check Threshold
ans = 100
Lv1= islocalmax(y, 'FlatSelection','all');
Lvlm = Lv1 & ~Lvt; % Logically Combine Vectors To Get Result Logical Vector
figure
plot(x, y, 'DisplayName','Original Data')
hold on
plot(x(Lvlm), y(Lvlm),'.r', 'DisplayName','Desired Result')
% plot(x(Lvt), y(Lvt), '.g', 'DisplayName','Excluded Region')
hold off
legend('Location','N')
ylim([min(ylim) max(ylim)*1.25])
title(["Original Data With Selectied Regions" "Omitting Specific Plot Of Excuded Region"])
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by