I want to find the area of the graph
조회 수: 1 (최근 30일)
이전 댓글 표시
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,:));
댓글 수: 0
채택된 답변
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
Star Strider
2022년 5월 19일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!