Finding peak with two nulls around in a 1d plot

조회 수: 1 (최근 30일)
Vinay Killamsetty
Vinay Killamsetty 2021년 5월 31일
답변: Sai Pavan 2024년 2월 16일
How can we find the presence of a peak (global maxima) with two nulls (or crossing lower threshold) on each side of the peak in a 1d plot.
And is there a way to find the width of the peak at a particular threshold level
  댓글 수: 2
Image Analyst
Image Analyst 2021년 5월 31일
You forgot to attach your data or even a screenshot. Which means you blew right past the posting guidelines. Here is another chance to read them and make it easy for us to help you:

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

답변 (1개)

Sai Pavan
Sai Pavan 2024년 2월 16일
Hello Vinay,
I see that you want to find the presence of a peak with two nulls on each side of the peak in a 1d plot and find the width of the peak at a particular threshold level.
Please refer to the below workflow to find the presence of a peak with two nulls (or crossing a lower threshold) on each side of the peak in a 1D plot, and to find the width of the peak at a particular threshold level:
  • Identify the peaks using the 'findpeaks' function.
  • For each detected peak, find the points where the signal crosses the lower threshold level on both sides of the peak.
  • Measure the width of the peak at the threshold level by calculating the distance between the two crossing points.
Please refer to the below code that illustrates the above mentioned workflow:
% Sample data
x = linspace(0, 10, 1000);
y = exp(-(x-5).^2) + 0.1*randn(size(x)); % Gaussian peak with some noise
plot(x, y);
hold on
threshold = 0.1; % Set to consider as null. Adjust the threshold variable to the level at which you want to measure the peak widths.
[peakValues, peakLocs] = findpeaks(y, x, 'MinPeakHeight', threshold); % Find the peaks
plot(peakLocs, peakValues, 'r*', 'MarkerSize', 10);
% For each peak, find the width at the threshold level
for i = 1:length(peakLocs)
peakX = peakLocs(i);
peakY = peakValues(i);
% Find where the signal crosses the threshold on the left side of the peak
leftSide = y(1:find(x==peakX));
leftCross = find(leftSide < threshold, 1, 'last');
if isempty(leftCross)
leftCross = 1; % If it never crosses, use the start of the data
end
% Find where the signal crosses the threshold on the right side of the peak
rightSide = y(find(x==peakX):end);
rightCross = find(rightSide < threshold, 1, 'first');
if isempty(rightCross)
rightCross = length(rightSide); % If it never crosses, use the end of the data
else
rightCross = rightCross + find(x==peakX) - 1; % Adjust index
end
% Calculate the width at the threshold
peakWidth = x(rightCross) - x(leftCross);
% Plot the width
plot(x([leftCross rightCross]), [threshold threshold], 'k-', 'LineWidth', 2);
% Display the width
disp(['Peak ' num2str(i) ' width at threshold ' num2str(threshold) ': ' num2str(peakWidth)]);
end
hold off
Please refer to the below documentation to learn more about 'findpeaks' function: https://www.mathworks.com/help/signal/ref/findpeaks.html
Hope it helps!

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by