I want to find the area of the graph

4 views (last 30 days)
대수 김
대수 김 on 18 May 2022
Commented: Star Strider on 19 May 2022
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,:));

Accepted Answer

Star Strider
Star Strider on 19 May 2022
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 Comments
Star Strider
Star Strider on 19 May 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by