I want to find the area of the graph

조회 수: 1 (최근 30일)
대수 김
대수 김 2022년 5월 18일
댓글: Star Strider 2022년 5월 19일
I'd like to get the area of the part drawn in red using threshold.
I thought I'd use a specific value or slope to get a range and then get an area.
And may I know how to remove the noise from the signal?
% plot(xy(1,:),xy(2,:));

채택된 답변

Star Strider
Star Strider 2022년 5월 19일
Try this —
LD = load('x,y.mat');
x = LD.xy(1,:);
y = LD.xy(2,:);
yf = sgolayfilt(y, 3, 1001); % Filter Signal
k = islocalmin(yf, 'MinProminence',0.0001); % Find Local Minima
idx = find(k); % Numeric Index
idxrng = idx(1):idx(2); % Index Range
xp = x(idxrng); % X-Vector
yp = y(idxrng); % Y-Vector
posarea = trapz(xp(yp>0),yp(yp>0)); % Area Above y=0
negarea = trapz(xp(yp<=0),yp(yp<=0)); % Area below y=0
totarea = posarea - negarea % Total Area
uncorrarea = trapz(xp,yp); % Uncorrectred Area (For Comparison)
figure
plot(x, y)
hold on
plot(x(k), yf(k), '+r', 'MarkerSize',10)
plot(x, yf, 'LineWidth',1.25)
hold off
grid
legend('Original Data','Local Minima','Filtered Data', 'Location','best')
text(0.5, 0.0125, sprintf('Area = %.4f',totarea)
The trapz function integrates with respect to zero, so anything below zero is subtracted from the area above zero. This code calculates the peak area without (‘uncorrarea’) and with (‘totarea’) the baseline correction.
The area of the peak with the uncorrected baseline is and the peak area with the corrected baseline is .
.
  댓글 수: 2
대수 김
대수 김 2022년 5월 19일
Thank you very much.
I will apply various things based on the code and function you wrote me.
I hope you have a good day.
Star Strider
Star Strider 2022년 5월 19일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by