Using trapz to calculate the area under part of the whole pulse where y is not zero

조회 수: 12 (최근 30일)
Hey,
I am trying to calculate the area under the pulse between the two specified minima shown in the picture from the whole pulse. I am wondering is it correct to use trapz here although one of the two specified points doesn't have y=0?
Thanks in advance!

채택된 답변

Robert Daly
Robert Daly 2023년 5월 4일
이동: Mathieu NOE 2023년 5월 4일
I would run traps on the peak data set between the two end points.
Then I would run traps using a line between the two endpoints to represent the baseline then subtract that from the first result.
peak.x = [1:10]
peak = struct with fields:
x: [1 2 3 4 5 6 7 8 9 10]
peak.y = [2,3,6,20,25,26,20,5,2,1]
peak = struct with fields:
x: [1 2 3 4 5 6 7 8 9 10] y: [2 3 6 20 25 26 20 5 2 1]
figure
plot(peak.x,peak.y)
baseline = interp1(peak.x([1,end]),peak.y([1,end]),peak.x) %interpolate a striaght line between the first and last data points in the peak
baseline = 1×10
2.0000 1.8889 1.7778 1.6667 1.5556 1.4444 1.3333 1.2222 1.1111 1.0000
hold on
plot(peak.x,baseline)
PeakArea = trapz(peak.x,peak.y) - trapz(peak.x,baseline)
PeakArea = 95
  댓글 수: 3
Robert Daly
Robert Daly 2023년 5월 5일
편집: Robert Daly 2023년 5월 5일
trapz(peak.x,peak.y)
will calculate the area under the curve between 0 and the curve.
It doesn't matter if the data doesn't start at zero it will still work (maybe this is what you were asking?). The results will be the area in yellow below.
trapz(peak.x,peak.y) - trapz(peak.x,baseline)
What my example will give you is the area in yellow below. This is commonly what gets done in chemistry for things like integrating peaks in chromatography (this is what I thought you were asking). It ignores the area in below the baseline.
Chen Klein
Chen Klein 2024년 1월 18일
Hey, if my signal has also negative values, will it only calculate the area from the positive values to 0 (on Y-Axes) ? or it will calculate the whole area under the pulse as you showed here ?

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

추가 답변 (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