Detecting and changing the polarity of signals

조회 수: 14 (최근 30일)
Khan Engr
Khan Engr 2018년 9월 27일
댓글: Khan Engr 2018년 10월 17일
Hi every one;
I have hundred of data files (signals) of equal length. I am interested in the highest peak (maximum) and location in each signal but want to have them with positive polarity. Now the problem is that, randomly, some signals have highest peak as positive polarity and some have negative. I want all of the signals with the positive polarity. Manually, I can just plot and if find negative, I multiple with -1, then find maximum and its location but my question is that can I do some thing that, it sees if highest value appears as negative, it converts the signal to positive. I will appreciate your help.
  댓글 수: 7
Khan Engr
Khan Engr 2018년 9월 27일
Thanks,i will see it now and as you mentioned about plot, I am attaching a file having three such data files, you may please have a look in the and also a PDF that what I am looking for.
Adam Danz
Adam Danz 2018년 9월 27일
편집: Adam Danz 2018년 9월 27일
I looked at the plot in the pdf file. If you have an estimate of the baseline (~-0.75 in these data) I'd go with my first option proposed in my answer. Subtract that from the signal so the new baseline is 0. Then you can just take max(abs()) + baseline.

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

채택된 답변

Adam Danz
Adam Danz 2018년 9월 27일
(Continuing from comments under the question) I think the best solution would be subtract the baseline value and then take the absolute value of your signal. Then you just need to find the max. I don't have your data but it would look something like this:
[maxVal, maxIdx] = max(abs(signal-baseline));
An alternative is to find the max and min, determine which has the greater magnitude, and then multiply the value by the sign of that number. If the sign is positive, the value will remain positive. If the sign is negative, multiplying two negatives will turn it positive. That would look something like this:
Assuming you have the peak value ( peakVal ) and its location ( peakIdx ),
peakVal * sign(data(peakIdx))
  댓글 수: 3
Adam Danz
Adam Danz 2018년 10월 16일
The method below finds which element of the vector data1 has the largest magnitude (positive or negative) by using the absolute value and the n multiplies it by the sign of that number so negative peaks remain negative.
data1 = [-3 3 -2 -20 4 -1 -2 1 -2 -1];
[peak, peakIdx] = max(abs(data1));
peak = peak * sign(data1(peakIdx));
peak =
-20
Khan Engr
Khan Engr 2018년 10월 17일
OK Great... I have used it like;
data1 = [-3 3 -2 20 4 -1 -2 1 -2 -1];
[peak, peakIdx] = max(abs(data1));
peak = peak * sign(data1(peakIdx));
>> if peak<0;
data2=-data1;
else
data2=data1;
end
Its working well for the purpose.
The problem is solved, thanks a lot Adam.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by