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.
Specifically find the first substantial peak in a graph.
5 ビュー (過去 30 日間)
表示 古いコメント

回答 (2 件)
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
figure;
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');
else
legend('Signal', 'Threshold');
end
xlabel('Index');
ylabel('Signal Value');
title('Signal with First Substantial Peak');
hold off;
0 件のコメント
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)
figure
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
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".
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!