I want to find the area of the graph
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
대수 김
am 18 Mai 2022
Kommentiert: Star Strider
am 19 Mai 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,:));
0 Kommentare
Akzeptierte Antwort
Star Strider
am 19 Mai 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 Kommentare
Star Strider
am 19 Mai 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!