Search code examples
matlabarea

Calculate area from Signal under basline


The Matlab code I have plots the following curve:

X1= 1:600;
plot (X1,tmp)

basline = 0;% level
area(tmp,basline,'FaceColor','g');

enter image description here

how can I calculate the area in the red circle?


Solution

  • You need to find the 2nd and 3rd zero cross (z2 and z3). then do a sum over the tmp. Something like this:

    X1= 1:600;
    tmp = sin(0.03*X1);
    plot (X1,tmp)
    range = 209:314;
    basline = 0;% level
    area(tmp,basline,'FaceColor','g');
    figure;area(tmp(range),basline,'FaceColor','g');
    
    sum(tmp(range))
    

    enter image description here

    enter image description here