Detecting and changing the polarity of signals
조회 수: 14 (최근 30일)
이전 댓글 표시
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
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
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
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!