Specifically find the first substantial peak in a graph.

5 ビュー (過去 30 日間)
Anthony 2023 年 6 月 5 日
コメント済み: Image Analyst 2023 年 6 月 6 日
  1 件のコメント
Anthony 2023 年 6 月 5 日
I want to find the value of the first occuring peak in this graph. How can I write a code that can specifcally do that for this graph or any graph I input into the code.


回答 (2 件)

Diwakar Diwakar
Diwakar Diwakar 2023 年 6 月 5 日
Try this example. may be this code will help you.
% Example usage
signal = [0, 0, 0, 1, 2, 3, 2, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 2, 1, 0, 0, 0];
threshold = 0.5;
% Find the first peak in the signal above the threshold
localMaxima = islocalmax(signal);
peakIndex = find(localMaxima & signal > threshold, 1);
% Plot the signal
plot(signal, 'b-', 'LineWidth', 2);
hold on;
% Plot the threshold line
plot([1, numel(signal)], [threshold, threshold], 'r--', 'LineWidth', 1);
% Plot the first peak, if found
if ~isempty(peakIndex)
plot(peakIndex, signal(peakIndex), 'go', 'MarkerSize', 10, 'MarkerFaceColor', 'g');
legend('Signal', 'Threshold', 'First Peak');
legend('Signal', 'Threshold');
ylabel('Signal Value');
title('Signal with First Substantial Peak');
hold off;

Star Strider
Star Strider 2023 年 6 月 5 日
Perhaps something like this —
x = linspace(1.3, 3.3)*1E+4;
yfcn = @(x) x.*exp(-0.00025*x);
y = yfcn(x-x(1))/6 + [zeros(1,13) randn(1,87)*10];
[pks,locs] = findpeaks(y, 'NPeaks',1)
pks = 252.8592
locs = 18
plot(x, y)
hold on
plot(x(locs), pks, 'rs')
hold off
legend('Data','First Peak','Location','best')
That should be robust to all your data sets.
  3 件のコメント
Image Analyst
Image Analyst 2023 年 6 月 6 日
@Anthony what is your definition of the first peak, out of all those peaks in the image. Is it the very first one, like islocalmax would return in the first element it returns? Or is it the peak of the noisy signal, as it you had denoised the signal? Or is it the overall max of the entire signal, like the red square in Star's last plot? Do you even want to denoise your signal, or do you want to use the original, noisy signal?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
and please indicate which (x,y) point on the curve you want to find as the "first peak".



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