how to use property "ProminenceWindow" for command islocalmin

8 ビュー (過去 30 日間)
swati khese
swati khese 2024 年 9 月 25 日
編集済み: swati khese 2024 年 10 月 2 日
Can someone please explain how to use property "ProminenceWindow" for command islocalmin. I want to understand what difference this ProminenceWindow property can make.
My assumption is i can filter out peak/valley according to the width of the peak/valley(do not confuse width with 'halfprom' or 'halfheight' in WidthReference property of findpeak. I want to find full prominence width i.e X indices of start of peak and end of peak. using this width can be easily found by subtacting)
i can filter out peak/valley according to the height if i use MinPeakProminence property
Please check below example that i tried for understanding this property.
Example code:
% Generate sample data
x = linspace(0, 3*pi, 1000); % Extended range for gradual changes
y = sin(0.5*pi*x) + 0.01*randn(size(x)); % Half sine wave with very minimal noise
% Define different ProminenceWindow values
prominenceWindows = [5, 20, 50]; % Adjust these values to see the effect
% Create a figure with subplots
figure;
for k = 1:length(prominenceWindows)
% Detect local minima with the current ProminenceWindow
minIdx = islocalmin(y, 'ProminenceWindow', prominenceWindows(k));
% Count the number of local minima detected
numMinima = sum(minIdx);
% Create a subplot for the current ProminenceWindow
subplot(length(prominenceWindows), 1, k);
plot(x, y, '-b', 'DisplayName', 'Data');
hold on;
plot(x(minIdx), y(minIdx), 'ro', 'MarkerFaceColor', 'r', 'DisplayName', 'Local Minima');
hold off;
legend show;
title(['ProminenceWindow = ', num2str(prominenceWindows(k)), ', Count = ', num2str(numMinima)]);
xlabel('x');
ylabel('y');
end
% Adjust subplot layout for better visualization
sgtitle('Local Minima Detection with Different ProminenceWindow Values');

回答 (1 件)

Suraj Kumar
Suraj Kumar 2024 年 10 月 1 日
Hi Swati,
The ProminenceWindowis a property in the islocalmin function which is used to define the range over which the prominence of each local minimum is calculated. Prominence measures how much a minimum stands out compared to its surroundings.
To visualize the effect of ‘ProminenceWindow parameter, we need to set the ‘MinProminence parameter as well as it specifies a threshold for the prominence of local minima. Only minima with a prominence equal to or greater than this value are considered.
Now without this, the count of minima remains constant regardless of the 'ProminenceWindow' setting since all local minima are considered, irrespective of their prominence values.
You can refer to the attached code snippet and the output for a better understanding:
x = 1:100;
A = peaks(100);
A = A(50,:);
figure;
% First subplot
subplot(2, 1, 1);
TF1 = islocalmin(A, 'MinProminence', 1, 'ProminenceWindow', [5, 5]);
plot(x, A, x(TF1), A(TF1), 'r*');
title('Plot 1');
axis tight;
% Second subplot
subplot(2, 1, 2);
TF2 = islocalmin(A, 'MinProminence', 2, 'ProminenceWindow', [15, 15]);
plot(x, A, x(TF2), A(TF2), 'r*');
title('Plot 2');
axis tight;
Output:
To know more about the ProminenceWindowparameter in the islocalmin function in MATLAB, you can refer to the following documentation:
Hope this works for you!

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by