I want to find the area of the graph
4 views (last 30 days)
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?
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)
plot(x(k), yf(k), '+r', 'MarkerSize',10)
plot(x, yf, 'LineWidth',1.25)
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 .