How to find the area from a Positive and negative signal plot

13 views (last 30 days)
Facing problem to find the positive and negative signal area.
  1. want to find the how many signals has in the positive and negative area seperately. Suppose, for first negative area showing in the plot it might be 46525 discrete signals. but its difficult to find manually everytime. Is there any way ? I can find the the positive and negative discret values only. But want to find positive and negative area seperately. Marked the 7 areas in the attched figure.
  2. attached the signal file in xlsx format and a figure of the plot,as the mat file storage is high. Tried with the below mentioned code, but can't proceed more.
clear all;
clc;
A= readmatrix('Data.xlsx');
t=1:length(A);
time=t';
power=A(1:end,:);
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
zeroaxes = zci(power);
gt0 = power>0;
posareaonly = cumtrapz(time(gt0), power(gt0));
negareaonly = cumtrapz(time(~gt0), power(~gt0));

Accepted Answer

KSSV
KSSV on 12 Dec 2021
A = readmatrix('Data.xlsx');
t = (1:length(A))' ;
% Positive Area
Ap = A ;
Ap(A<=0) = 0 ;
trapz(t,Ap)
  3 Comments
Arif Hoq
Arif Hoq on 12 Dec 2021
Found the Positive and negative area. Now is there any syntax to find the signal values in every area ? Let's imagine first area(Negative) has 65000 signal values with respect to time. how to find that values?
Arif Hoq
Arif Hoq on 12 Dec 2021
used this Code:
clear all;
clc;
A = readmatrix('Data.xlsx');
t = (1:length(A))' ;
% Positive Area
Ap = A ;
Ap(A<=0) = 0 ;
B=trapz(t,Ap);
% Negative Area
An=A;
An(A>=0) = 0 ;
C=trapz(t,An);
subplot(2,1,1);
plot(Ap);
subplot(2,1,2);
plot(An);

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 12 Dec 2021
To count number of positive and negative regions:
[labeledRegionsPos, numPositive] = bwlabel(power > 0);
[labeledRegionsNeg, numNegative] = bwlabel(power < 0);
Requires bwlabel() which is in the Image Processing Toolbox.
  5 Comments
Image Analyst
Image Analyst on 14 Dec 2021
trapz integrates the area under the curve. It does not count the areas like you asked for: "want to find the how many signals"
Arif Hoq
Arif Hoq on 14 Dec 2021
i might be wrong on my question. my question was close to integration i guess. I apologize for this inconvenience. I have solved this issue anyway by using trapz.
if i get the area of positive and neagtive, it shows the way to find the signal number as well as data value.thank you very much.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!