Finding area under multiple curves with different y references
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello all,
I need to find the sum of the area under each peak (see 5 minute skin conductance sample attached). The y axis must correspond to the lowest point of each peak to the peak itself. Therefore, the y axis changes for each peak. I have attached an image of the areas I would like help with.
I have tried for several days with no prevail, using past forums as guides, using functions such as trapz, cumtrapz, findpeaks, etc.
Any help would be greatly appreciated!
Jacob
0 Kommentare
Antworten (1)
Robin Kirsch
am 29 Mai 2020
Bearbeitet: Robin Kirsch
am 29 Mai 2020
you could try to get the peaks with the findpeaks method from Matlab, and then you for-loop backwards over the data array from the x value as the index and compare the data, as long as it is decreasing. I have made you an example for the first peak.
I attached you an example. Does this make sense? I get as a result 24.6050 for the first low to the first peak.
Of course you must for loop over all peaks and extend the thing! The example is only for the first peak.
My example gets you from that first detected peak to the bottom.
and this is the variable z, so the extracted data from the first peak in the figure above to the bottom. Then simply get the area underneath the data with the trapz method.
If you want to ignore this little peaks and only head for the bigger ones, I think you can add a parameter to the findpeaks method.
data = [3.42
3.42
3.41
3.4
3.4
3.4
3.4
3.4
3.4
3.39
3.39
3.39
3.39
3.39
3.37
3.37
3.37
3.37
3.37
3.37
3.37
3.37
3.36
3.35
3.35
3.35
3.34
3.36
3.37
3.38
3.43
3.54
3.61
3.7
3.79
3.77
3.84
3.9
3.99
4.03
4.07
4.11
4.05
4
3.95
3.9
3.86
3.85
3.84
3.89
3.92
3.9
3.86
3.83
3.83
3.83
3.83
3.83
3.83
3.83
3.84
3.85
3.85
3.91
3.96
3.97
3.96
3.95
3.96
4.01
4.03
4
3.99
3.99
3.97
3.97
3.97
3.97
3.99
3.97
3.97
3.99
4
4
3.99
3.97
3.97
4
3.99
3.97
3.97
3.97
3.97
3.97
3.95
3.95
3.95
3.94
3.92
3.92
3.91
3.9
3.89
3.87
3.86
3.86
3.86
3.89
3.9
3.87
3.85
3.85
3.84
3.83
3.8
3.8
3.84
3.85
3.85
3.85
3.83
3.83
3.8
3.81
3.83
3.8
3.78
3.78
3.78
3.78
3.79
3.8
3.79
3.77
3.76
3.75
3.76
3.85
3.85
3.83
3.8
3.78
3.78
3.9
3.96
3.94
3.89
4.04
4.04
4.03
4.01
4
4.14
4.18
4.16
4.14
4.11
4.11
4.08
4.05
4.04
4.05
4.05
4.07
4.14
4.14
4.14
4.11
4.08
4.08
4.08
4.08
4.08
4.08
4.21
4.29
4.26
4.22
4.21
4.19
4.16
4.16
4.16
4.15
4.14
4.14
4.14
4.14
4.12
4.11
4.11
4.11
4.11
4.11
4.11
4.11
4.11
4.11
4.21
4.32
4.31
4.28
4.25
4.19
4.19
4.16
4.19
4.21
4.19
4.19
4.16
4.16
4.28
4.32
4.31
4.39
4.4
4.34
4.28
4.25
4.25
4.29
4.31
4.28
4.25
4.25
4.22
4.22
4.19
4.19
4.21
4.19
4.22
4.29
4.28
4.25
4.25
4.23
4.26
4.25
4.22
4.22
4.21
4.19
4.19
4.19
4.19
4.21
4.19
4.19
4.19
4.19
4.18
4.26
4.32
4.4
4.4
4.37
4.37
4.37
4.31
4.28
4.28
4.25
4.25
4.25
4.25
4.22
4.22
4.21
4.19
4.19
4.25
4.28
4.37
4.45
4.43
4.4
4.37
4.34
4.39
4.4
4.37
4.34
4.31
4.28
4.34
4.4
4.4
4.37
4.34
4.31
4.31
4.31
4.31
4.32
4.28
4.29
4.32
4.31
4.28
4.28
4.28
4.25
4.25
4.25
4.25
4.23
4.22
4.22
4.22]
[x,y] = findpeaks(data);
%%take first peak
j = 1;
for i=y(1):-1:2
if data(i-1) < data(i)
z(j) = data(i);
j = j+1;
else
break;
end
end
z = flip(z);
area = trapz(z);
2 Kommentare
Robin Kirsch
am 29 Mai 2020
I just noticed you have to add the data point of the bottom, cause that will be left out, for example in the else method before the break.
like:
if ...
else
z(j) = data(i);
break;
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!