user19785597
user19785597

Reputation:

Area under curve in MatLab

can anyone tell me how to determine the AUC of the signal shown in the screenshot in Matlab? I would like to determine the AUC above the blue line (demarcation) over the 120 sec. period. Can anyone tell me how to do this in Matlab? Many thanks in advance!

Screenshot here

Upvotes: 0

Views: 271

Answers (1)

RobertoT
RobertoT

Reputation: 1683

There are a few functions in Matlab to integrate or approximate an integral of a function. Depending on the size of your vector - therefore depending on the sampling rate of that signal - some functions can save you time.

  1. Remove the area under the blue line. So, I assume the y-axis value for the horizontal blue line is positive (x>0). Just subtract the blue line from your original signal and set all negative values to 0.

If y is your signal, x is the cutoff for the blue line (a single number) and it is positive:

y2 = y-x; % subtract blue line
y2(y2<0) = 0; % set negative values to 0
  1. Integrate the resulting y2 curve. You can approximate the integral of the signal with the Trapezoidal numerical integration method from matlab -- trapz function:

But you need to know the sampling rate of the original signal to select the length for the specific 120 seconds.

freq = ?; % Sampling rate in Hz
% For 120 seconds:
sampling _length = 120 * freq;
% select the points for the first 120 seconds and approximate the integral
Q = trapz(y2([1:sampling _length])) 

If you want to deepen in this topic: https://es.mathworks.com/help/matlab/math/integration-of-numeric-data.html

Upvotes: 1

Related Questions